refactor: remove bookmarks (#90)

This commit is contained in:
Richard Ramos 2021-10-20 12:11:55 -04:00 committed by GitHub
parent 0759388710
commit b6a5b7e4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 93 deletions

View File

@ -1,16 +1,11 @@
from ./types import Backend, StatusGoBackend, MockBackend
export Backend, StatusGoBackend, MockBackend
from base/bookmarks as bookmarks_methods import storeBookmark, updateBookmark, getBookmarks, deleteBookmark
export storeBookmark, updateBookmark, getBookmarks, deleteBookmark
from base/keycard as keycard_methods import keycardStart, keycardStop, keycardSelect, keycardPair,
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey
export keycardStart, keycardStop, keycardSelect, keycardPair,
keycardOpenSecureChannel, keycardVerifyPin, keycardExportKey
import statusgo/bookmarks as statusgo_bookmarks
import mock/bookmarks as mock_bookmarks
import statusgo/keycard as statusgo_keycard
import mock/keycard as mock_keycard

View File

@ -1,14 +0,0 @@
import ../../types/[bookmark]
import ../types
method storeBookmark*(self: Backend, bookmark: Bookmark): Bookmark =
raise newException(ValueError, "No implementation available")
method updateBookmark*(self: Backend, originalUrl: string, bookmark: Bookmark) =
raise newException(ValueError, "No implementation available")
method getBookmarks*(self: Backend): seq[Bookmark] =
raise newException(ValueError, "No implementation available")
method deleteBookmark*(self: Backend, url: string) =
raise newException(ValueError, "No implementation available")

View File

@ -1,37 +0,0 @@
import json, chronicles
import ../../types/[bookmark]
import ../types
import ./core
method storeBookmark*(self: StatusGoBackend, bookmark: Bookmark): Bookmark =
let payload = %* [{"url": bookmark.url, "name": bookmark.name}]
try:
let resp = callPrivateRPC("browsers_storeBookmark", payload).parseJson["result"]
bookmark.imageUrl = resp["imageUrl"].getStr
return bookmark
except Exception as e:
error "Error updating bookmark", msg = e.msg
discard
method updateBookmark*(self: StatusGoBackend, originalUrl: string, bookmark: Bookmark) =
let payload = %* [originalUrl, {"url": bookmark.url, "name": bookmark.name}]
try:
discard callPrivateRPC("browsers_updateBookmark", payload)
except Exception as e:
error "Error updating bookmark", msg = e.msg
discard
method getBookmarks*(self: StatusGoBackend): seq[Bookmark] =
let payload = %* []
try:
let responseResult = callPrivateRPC("browsers_getBookmarks", payload).parseJson["result"]
if responseResult.kind != JNull:
for bookmark in responseResult:
result.add(Bookmark(url: bookmark{"url"}.getStr, name: bookmark{"name"}.getStr, imageUrl: bookmark{"imageUrl"}.getStr))
except:
discard
method deleteBookmark*(self: StatusGoBackend, url: string) =
let payload = %* [url]
discard callPrivateRPC("browsers_deleteBookmark", payload)

View File

@ -1,28 +0,0 @@
# import statusgo_backend/browser as status_browser
import ../eventemitter
import ../../types/[bookmark]
import ../backends/backend
type
BrowserModel* = ref object
events*: EventEmitter
backend*: Backend
proc newBrowserModel*(events: EventEmitter, backend: Backend): BrowserModel =
result = BrowserModel()
result.events = events
result.backend = backend
proc storeBookmark*(self: BrowserModel, bookmark: Bookmark): Bookmark =
return self.backend.storeBookmark(bookmark)
proc updateBookmark*(self: BrowserModel, originalUrl: string, bookmark: Bookmark) =
self.backend.updateBookmark(originalUrl, bookmark)
proc getBookmarks*(self: BrowserModel): seq[Bookmark] =
result = self.backend.getBookmarks()
proc deleteBookmark*(self: BrowserModel, url: string) =
self.backend.deleteBookmark(url)

View File

@ -1,7 +1,7 @@
import statusgo_backend/accounts as statusgo_backend_accounts
import statusgo_backend/core as statusgo_backend_core
import statusgo_backend/settings as statusgo_backend_settings
import chat, accounts, wallet, wallet2, node, network, messages, contacts, profile, stickers, permissions, fleet, settings, mailservers, browser, tokens, provider
import chat, accounts, wallet, wallet2, node, network, messages, contacts, profile, stickers, permissions, fleet, settings, mailservers, tokens, provider
import notifications/os_notifications
import ../eventemitter
import bitops, stew/byteutils, chronicles
@ -29,7 +29,6 @@ type Status* = ref object
permissions*: PermissionsModel
settings*: SettingsModel
mailservers*: MailserversModel
browser*: BrowserModel
tokens*: TokensModel
provider*: ProviderModel
osnotifications*: OsNotifications
@ -54,7 +53,6 @@ proc newStatusInstance*(fleetConfig: string, backendName: string = "statusgo"):
result.permissions = permissions.newPermissionsModel(result.events)
result.settings = settings.newSettingsModel(result.events)
result.mailservers = mailservers.newMailserversModel(result.events)
result.browser = browser.newBrowserModel(result.events, result.backend)
result.tokens = tokens.newTokensModel(result.events)
result.provider = provider.newProviderModel(result.events, result.permissions, result.wallet)
result.osnotifications = newOsNotifications(result.events)

View File

@ -0,0 +1,21 @@
import json, strmisc
import core, utils
import response_type
export response_type
proc getBookmarks*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = callPrivateRPC("browsers_getBookmarks", payload)
proc storeBookmark*(url, name: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [{"url": url, "name": name}]
result = callPrivateRPC("browsers_storeBookmark", payload)
proc deleteBookmark*(url: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [url]
result = callPrivateRPC("browsers_deleteBookmark", payload)
proc updateBookmark*(originalUrl, newUrl, name: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [originalUrl, {"url": newUrl, "name": name}]
result = callPrivateRPC("browsers_updateBookmark", payload)

View File

@ -1,5 +0,0 @@
type Bookmark* = ref object
name*: string
url*: string
imageUrl*: string

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit c3ced098390f3d4e8d4850d9c0bf6e7dbd627c20
Subproject commit bade0a24fff87c8cfbc6ba0e9322c9cccf1a656a