status-lib/status/statusgo_backend/browser.nim

36 lines
1.2 KiB
Nim
Raw Normal View History

2021-09-28 19:21:50 +00:00
import json, chronicles
import core
import ../types/[bookmark]
2021-09-08 18:05:39 +00:00
2021-09-28 19:21:50 +00:00
proc storeBookmark*(bookmark: Bookmark): Bookmark =
let payload = %* [{"url": bookmark.url, "name": bookmark.name}]
2021-09-08 18:05:39 +00:00
try:
let resp = callPrivateRPC("browsers_storeBookmark", payload).parseJson["result"]
2021-09-28 19:21:50 +00:00
bookmark.imageUrl = resp["imageUrl"].getStr
return bookmark
2021-09-08 18:05:39 +00:00
except Exception as e:
error "Error updating bookmark", msg = e.msg
discard
2021-09-28 19:21:50 +00:00
proc updateBookmark*(originalUrl: string, bookmark: Bookmark) =
let payload = %* [originalUrl, {"url": bookmark.url, "name": bookmark.name}]
2021-09-08 18:05:39 +00:00
try:
discard callPrivateRPC("browsers_updateBookmark", payload)
except Exception as e:
error "Error updating bookmark", msg = e.msg
discard
2021-09-28 19:21:50 +00:00
proc getBookmarks*(): seq[Bookmark] =
2021-09-08 18:05:39 +00:00
let payload = %* []
2021-09-28 19:21:50 +00:00
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
2021-09-08 18:05:39 +00:00
proc deleteBookmark*(url: string) =
let payload = %* [url]
discard callPrivateRPC("browsers_deleteBookmark", payload)