integrate status-go browsers api
This commit is contained in:
parent
7e061e9cd1
commit
0c839860a2
|
@ -23,11 +23,6 @@
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[status-im.signing.core :as signing]))
|
[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
|
(fx/defn initialize-dapp-permissions
|
||||||
[{:keys [db all-dapp-permissions]}]
|
[{:keys [db all-dapp-permissions]}]
|
||||||
(let [dapp-permissions (into {} (map #(vector (:dapp %) %) all-dapp-permissions))]
|
(let [dapp-permissions (into {} (map #(vector (:dapp %) %) all-dapp-permissions))]
|
||||||
|
@ -44,8 +39,9 @@
|
||||||
(defn get-current-browser [db]
|
(defn get-current-browser [db]
|
||||||
(get-in db [:browser/browsers (get-in db [:browser/options :browser-id])]))
|
(get-in db [:browser/browsers (get-in db [:browser/options :browser-id])]))
|
||||||
|
|
||||||
(defn get-current-url [{:keys [history history-index]}]
|
(defn get-current-url [{:keys [history history-index]
|
||||||
(when (and history-index history)
|
:or {history-index 0}}]
|
||||||
|
(when history
|
||||||
(nth history history-index)))
|
(nth history history-index)))
|
||||||
|
|
||||||
(defn secure? [{:keys [error? dapp?]} {:keys [url]}]
|
(defn secure? [{:keys [error? dapp?]} {:keys [url]}]
|
||||||
|
@ -57,7 +53,7 @@
|
||||||
(fx/defn remove-browser
|
(fx/defn remove-browser
|
||||||
[{:keys [db]} browser-id]
|
[{:keys [db]} browser-id]
|
||||||
{:db (update-in db [:browser/browsers] dissoc 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}]
|
(defn update-dapp-name [{:keys [name] :as browser}]
|
||||||
(assoc browser :dapp? false :name (or name (i18n/label :t/browser))))
|
(assoc browser :dapp? false :name (or name (i18n/label :t/browser))))
|
||||||
|
@ -117,7 +113,7 @@
|
||||||
{:db (update-in db
|
{:db (update-in db
|
||||||
[:browser/browsers browser-id]
|
[:browser/browsers browser-id]
|
||||||
merge updated-browser)
|
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]}]
|
(defn can-go-back? [{:keys [history-index]}]
|
||||||
(pos? history-index))
|
(pos? history-index))
|
||||||
|
|
|
@ -1,26 +1,36 @@
|
||||||
(ns status-im.data-store.browser
|
(ns status-im.data-store.browser
|
||||||
(:require [re-frame.core :as re-frame]
|
(: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
|
(fx/defn initialize-browsers
|
||||||
:data-store/all-browsers
|
{:events [::initialize]}
|
||||||
(fn [cofx _]
|
[{:keys [db]} all-stored-browsers]
|
||||||
(assoc cofx :all-stored-browsers (-> @core/account-realm
|
(let [browsers (reduce (fn [acc {:keys [browser-id] :as browser}]
|
||||||
(core/get-all :browser)
|
(assoc acc browser-id browser))
|
||||||
(core/sorted :timestamp :desc)
|
{}
|
||||||
(core/all-clj :browser)))))
|
all-stored-browsers)]
|
||||||
|
{:db (assoc db :browser/browsers browsers)}))
|
||||||
|
|
||||||
(defn save-browser-tx
|
(re-frame/reg-fx
|
||||||
"Returns tx function for saving browser"
|
:data-store/get-browsers
|
||||||
[{:keys [browser-id] :as browser}]
|
(fn []
|
||||||
(fn [realm]
|
(json-rpc/call
|
||||||
(core/create realm :browser browser true)))
|
{:method "browsers_getBrowsers"
|
||||||
|
:on-success #(re-frame/dispatch [::initialize %])})))
|
||||||
|
|
||||||
(defn remove-browser-tx
|
(re-frame/reg-fx
|
||||||
"Returns tx function for removing browser"
|
:data-store/save-browser
|
||||||
[browser-id]
|
(fn [browser]
|
||||||
(fn [realm]
|
(json-rpc/call
|
||||||
(let [browser (.objectForPrimaryKey realm
|
{:method "browsers_addBrowser"
|
||||||
"browser"
|
:params [(select-keys browser [:browser-id :timestamp :name :dapp? :history :history-index])]
|
||||||
browser-id)]
|
:on-success #()})))
|
||||||
(core/delete realm browser))))
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:data-store/delete-browser
|
||||||
|
(fn [browser-id]
|
||||||
|
(json-rpc/call
|
||||||
|
{:method "browsers_deleteBrowser"
|
||||||
|
:params [browser-id]
|
||||||
|
:on-success #()})))
|
||||||
|
|
|
@ -36,7 +36,10 @@
|
||||||
"status_chats" {}
|
"status_chats" {}
|
||||||
"status_startOneOnOneChat" {}
|
"status_startOneOnOneChat" {}
|
||||||
"status_removeChat" {}
|
"status_removeChat" {}
|
||||||
"wallet_getTransfers" {}})
|
"wallet_getTransfers" {}
|
||||||
|
"browsers_getBrowsers" {}
|
||||||
|
"browsers_addBrowser" {}
|
||||||
|
"browsers_deleteBrowser" {}})
|
||||||
|
|
||||||
(defn call
|
(defn call
|
||||||
[{:keys [method params on-success on-error]}]
|
[{:keys [method params on-success on-error]}]
|
||||||
|
|
|
@ -143,7 +143,6 @@
|
||||||
[(re-frame/inject-cofx :web3/get-web3)
|
[(re-frame/inject-cofx :web3/get-web3)
|
||||||
(re-frame/inject-cofx :data-store/get-all-contacts)
|
(re-frame/inject-cofx :data-store/get-all-contacts)
|
||||||
(re-frame/inject-cofx :data-store/get-all-installations)
|
(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-dapp-permissions)
|
||||||
(re-frame/inject-cofx :data-store/all-chats)
|
(re-frame/inject-cofx :data-store/all-chats)
|
||||||
(re-frame/inject-cofx :data-store/all-chat-requests-ranges)]
|
(re-frame/inject-cofx :data-store/all-chat-requests-ranges)]
|
||||||
|
|
|
@ -239,7 +239,6 @@
|
||||||
(contact/load-contacts)
|
(contact/load-contacts)
|
||||||
#(when (dev-mode? %)
|
#(when (dev-mode? %)
|
||||||
(models.dev-server/start))
|
(models.dev-server/start))
|
||||||
(browser/initialize-browsers)
|
|
||||||
(browser/initialize-dapp-permissions)
|
(browser/initialize-dapp-permissions)
|
||||||
(extensions.module/initialize)
|
(extensions.module/initialize)
|
||||||
(stickers/init-stickers-packs)
|
(stickers/init-stickers-packs)
|
||||||
|
|
|
@ -172,6 +172,7 @@
|
||||||
:card-read-in-progress?
|
:card-read-in-progress?
|
||||||
:pin
|
:pin
|
||||||
:multiaccount))
|
:multiaccount))
|
||||||
|
:data-store/get-browsers nil
|
||||||
:web3/set-default-account [web3 address]
|
:web3/set-default-account [web3 address]
|
||||||
:web3/fetch-node-version [web3
|
:web3/fetch-node-version [web3
|
||||||
#(re-frame/dispatch
|
#(re-frame/dispatch
|
||||||
|
|
|
@ -116,11 +116,12 @@
|
||||||
:RendezvousNodes rendezvous-nodes})
|
:RendezvousNodes rendezvous-nodes})
|
||||||
|
|
||||||
:always
|
:always
|
||||||
(assoc :WhisperConfig {:Enabled true
|
(assoc :WalletConfig {:Enabled true}
|
||||||
|
:BrowsersConfig {:Enabled true}
|
||||||
|
:WhisperConfig {:Enabled true
|
||||||
:LightClient true
|
:LightClient true
|
||||||
:MinimumPoW 0.001
|
:MinimumPoW 0.001
|
||||||
:EnableNTPSync true}
|
:EnableNTPSync true}
|
||||||
:WalletConfig {:Enabled true}
|
|
||||||
:ShhextConfig {:BackupDisabledDataDir (utils.platform/no-backup-directory)
|
:ShhextConfig {:BackupDisabledDataDir (utils.platform/no-backup-directory)
|
||||||
:InstallationID installation-id
|
:InstallationID installation-id
|
||||||
:MaxMessageDeliveryAttempts config/max-message-delivery-attempts
|
:MaxMessageDeliveryAttempts config/max-message-delivery-attempts
|
||||||
|
|
Loading…
Reference in New Issue