integrate status-go browsers api

This commit is contained in:
yenda 2019-07-12 14:43:34 +02:00
parent 7e061e9cd1
commit 0c839860a2
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
7 changed files with 44 additions and 35 deletions

View File

@ -23,11 +23,6 @@
[taoensso.timbre :as log]
[status-im.signing.core :as signing]))
(fx/defn initialize-browsers
[{:keys [db all-stored-browsers]}]
(let [browsers (into {} (map #(vector (:browser-id %) %) all-stored-browsers))]
{:db (assoc db :browser/browsers browsers)}))
(fx/defn initialize-dapp-permissions
[{:keys [db all-dapp-permissions]}]
(let [dapp-permissions (into {} (map #(vector (:dapp %) %) all-dapp-permissions))]
@ -44,8 +39,9 @@
(defn get-current-browser [db]
(get-in db [:browser/browsers (get-in db [:browser/options :browser-id])]))
(defn get-current-url [{:keys [history history-index]}]
(when (and history-index history)
(defn get-current-url [{:keys [history history-index]
:or {history-index 0}}]
(when history
(nth history history-index)))
(defn secure? [{:keys [error? dapp?]} {:keys [url]}]
@ -57,7 +53,7 @@
(fx/defn remove-browser
[{:keys [db]} browser-id]
{:db (update-in db [:browser/browsers] dissoc browser-id)
:data-store/tx [(browser-store/remove-browser-tx browser-id)]})
:data-store/delete-browser browser-id})
(defn update-dapp-name [{:keys [name] :as browser}]
(assoc browser :dapp? false :name (or name (i18n/label :t/browser))))
@ -117,7 +113,7 @@
{:db (update-in db
[:browser/browsers browser-id]
merge updated-browser)
:data-store/tx [(browser-store/save-browser-tx updated-browser)]}))
:data-store/save-browser updated-browser}))
(defn can-go-back? [{:keys [history-index]}]
(pos? history-index))

View File

@ -1,26 +1,36 @@
(ns status-im.data-store.browser
(:require [re-frame.core :as re-frame]
[status-im.data-store.realm.core :as core]))
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx]))
(re-frame/reg-cofx
:data-store/all-browsers
(fn [cofx _]
(assoc cofx :all-stored-browsers (-> @core/account-realm
(core/get-all :browser)
(core/sorted :timestamp :desc)
(core/all-clj :browser)))))
(fx/defn initialize-browsers
{:events [::initialize]}
[{:keys [db]} all-stored-browsers]
(let [browsers (reduce (fn [acc {:keys [browser-id] :as browser}]
(assoc acc browser-id browser))
{}
all-stored-browsers)]
{:db (assoc db :browser/browsers browsers)}))
(defn save-browser-tx
"Returns tx function for saving browser"
[{:keys [browser-id] :as browser}]
(fn [realm]
(core/create realm :browser browser true)))
(re-frame/reg-fx
:data-store/get-browsers
(fn []
(json-rpc/call
{:method "browsers_getBrowsers"
:on-success #(re-frame/dispatch [::initialize %])})))
(defn remove-browser-tx
"Returns tx function for removing browser"
[browser-id]
(fn [realm]
(let [browser (.objectForPrimaryKey realm
"browser"
browser-id)]
(core/delete realm browser))))
(re-frame/reg-fx
:data-store/save-browser
(fn [browser]
(json-rpc/call
{:method "browsers_addBrowser"
:params [(select-keys browser [:browser-id :timestamp :name :dapp? :history :history-index])]
:on-success #()})))
(re-frame/reg-fx
:data-store/delete-browser
(fn [browser-id]
(json-rpc/call
{:method "browsers_deleteBrowser"
:params [browser-id]
:on-success #()})))

View File

@ -36,7 +36,10 @@
"status_chats" {}
"status_startOneOnOneChat" {}
"status_removeChat" {}
"wallet_getTransfers" {}})
"wallet_getTransfers" {}
"browsers_getBrowsers" {}
"browsers_addBrowser" {}
"browsers_deleteBrowser" {}})
(defn call
[{:keys [method params on-success on-error]}]

View File

@ -143,7 +143,6 @@
[(re-frame/inject-cofx :web3/get-web3)
(re-frame/inject-cofx :data-store/get-all-contacts)
(re-frame/inject-cofx :data-store/get-all-installations)
(re-frame/inject-cofx :data-store/all-browsers)
(re-frame/inject-cofx :data-store/all-dapp-permissions)
(re-frame/inject-cofx :data-store/all-chats)
(re-frame/inject-cofx :data-store/all-chat-requests-ranges)]

View File

@ -239,7 +239,6 @@
(contact/load-contacts)
#(when (dev-mode? %)
(models.dev-server/start))
(browser/initialize-browsers)
(browser/initialize-dapp-permissions)
(extensions.module/initialize)
(stickers/init-stickers-packs)

View File

@ -172,6 +172,7 @@
:card-read-in-progress?
:pin
:multiaccount))
:data-store/get-browsers nil
:web3/set-default-account [web3 address]
:web3/fetch-node-version [web3
#(re-frame/dispatch

View File

@ -116,11 +116,12 @@
:RendezvousNodes rendezvous-nodes})
:always
(assoc :WhisperConfig {:Enabled true
(assoc :WalletConfig {:Enabled true}
:BrowsersConfig {:Enabled true}
:WhisperConfig {:Enabled true
:LightClient true
:MinimumPoW 0.001
:EnableNTPSync true}
:WalletConfig {:Enabled true}
:ShhextConfig {:BackupDisabledDataDir (utils.platform/no-backup-directory)
:InstallationID installation-id
:MaxMessageDeliveryAttempts config/max-message-delivery-attempts