integrate status-go permissions api

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-07-18 13:25:43 +02:00
parent 0c839860a2
commit 3ea8538377
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
15 changed files with 85 additions and 114 deletions

View File

@ -3,9 +3,9 @@
[re-frame.core :as re-frame]
[status-im.browser.permissions :as browser.permissions]
[status-im.constants :as constants]
[status-im.data-store.browser :as browser-store]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ens]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.ethereum.resolver :as resolver]
[status-im.i18n :as i18n]
[status-im.js-dependencies :as js-dependencies]
@ -23,11 +23,6 @@
[taoensso.timbre :as log]
[status-im.signing.core :as signing]))
(fx/defn initialize-dapp-permissions
[{:keys [db all-dapp-permissions]}]
(let [dapp-permissions (into {} (map #(vector (:dapp %) %) all-dapp-permissions))]
{:db (assoc db :dapps/permissions dapp-permissions)}))
(fx/defn update-browser-option
[{:keys [db]} option-key option-value]
{:db (assoc-in db [:browser/options option-key] option-value)})
@ -53,7 +48,9 @@
(fx/defn remove-browser
[{:keys [db]} browser-id]
{:db (update-in db [:browser/browsers] dissoc browser-id)
:data-store/delete-browser browser-id})
::json-rpc/call [{:method "browsers_deleteBrowser"
:params [browser-id]
:on-success #()}]})
(defn update-dapp-name [{:keys [name] :as browser}]
(assoc browser :dapp? false :name (or name (i18n/label :t/browser))))
@ -113,7 +110,9 @@
{:db (update-in db
[:browser/browsers browser-id]
merge updated-browser)
:data-store/save-browser updated-browser}))
::json-rpc/call [{:method "browsers_addBrowser"
:params [(select-keys updated-browser [:browser-id :timestamp :name :dapp? :history :history-index])]
:on-success #()}]}))
(defn can-go-back? [{:keys [history-index]}]
(pos? history-index))

View File

@ -1,7 +1,7 @@
(ns status-im.browser.permissions
(:require [status-im.constants :as constants]
[status-im.data-store.dapp-permissions :as dapp-permissions]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.extensions.module :as extensions.module]
[status-im.i18n :as i18n]
[status-im.qr-scanner.core :as qr-scanner]
@ -76,13 +76,17 @@
allowed-permissions {:dapp dapp-name
:permissions (vec allowed-permissions-set)}]
{:db (assoc-in db [:dapps/permissions dapp-name] allowed-permissions)
:data-store/tx [(dapp-permissions/save-dapp-permissions allowed-permissions)]}))
::json-rpc/call [{:method "permissions_addDappPermissions"
:params [allowed-permissions]
:on-success #()}]}))
(fx/defn revoke-dapp-permissions
[{:keys [db] :as cofx} dapp]
(fx/merge cofx
{:db (update-in db [:dapps/permissions] dissoc dapp)
:data-store/tx [(dapp-permissions/remove-dapp-permissions dapp)]}
::json-rpc/call [{:method "permissions_deleteDappPermissions"
:params [dapp]
:on-success #()}]}
(navigation/navigate-back)))
(fx/defn process-next-permission

View File

@ -5,6 +5,7 @@
[status-im.contact.core :as contact.core]
[status-im.data-store.chats :as chats-store]
[status-im.data-store.messages :as messages-store]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.i18n :as i18n]
[status-im.mailserver.core :as mailserver]
[status-im.transport.message.protocol :as transport.protocol]
@ -107,7 +108,7 @@
"Adds new public group chat to db & realm"
[cofx topic]
(if config/use-status-go-protocol?
{:json-rpc/call [{:method "status_joinPublicChat"
{::json-rpc/call [{:method "status_joinPublicChat"
:params [topic]
:on-success
#(log/debug "successfully joined a public chat:" topic)
@ -159,7 +160,7 @@
[{:keys [db now] :as cofx} chat-id]
(if config/use-status-go-protocol?
(fx/merge cofx
{:json-rpc/call [{:method "status_removeChat"
{::json-rpc/call [{:method "status_removeChat"
:params [chat-id]
:on-success
#(log/debug "successfully removed a chat:" chat-id)
@ -271,7 +272,7 @@
(when (not= (multiaccounts.model/current-public-key cofx) chat-id)
(if config/use-status-go-protocol?
(fx/merge cofx
{:json-rpc/call [{:method "status_startOneOnOneChat"
{::json-rpc/call [{:method "status_startOneOnOneChat"
:params [chat-id]
:on-success
#(log/debug "successfully started a 1-1 chat with:" chat-id)

View File

@ -2,6 +2,7 @@
(:require [re-frame.core :as re-frame]
[status-im.chat.commands.core :as commands]
[status-im.chat.models :as chat-model]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.mailserver.core :as mailserver]
[status-im.utils.config :as config]
[status-im.utils.datetime :as time]
@ -70,7 +71,7 @@
(defn load-chats-from-rpc
[cofx]
(fx/merge cofx
{:json-rpc/call [{:method "status_chats"
{::json-rpc/call [{:method "status_chats"
:params []
:on-error
#(log/error "can't retrieve chats list from status-go:" %)

View File

@ -1,36 +0,0 @@
(ns status-im.data-store.browser
(:require [re-frame.core :as re-frame]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx]))
(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)}))
(re-frame/reg-fx
:data-store/get-browsers
(fn []
(json-rpc/call
{:method "browsers_getBrowsers"
:on-success #(re-frame/dispatch [::initialize %])})))
(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

@ -8,7 +8,6 @@
status-im.data-store.contacts
status-im.data-store.installations
status-im.data-store.transport
status-im.data-store.browser
status-im.data-store.multiaccounts
status-im.data-store.mailservers))

View File

@ -1,22 +0,0 @@
(ns status-im.data-store.dapp-permissions
(:require [re-frame.core :as re-frame]
[status-im.data-store.realm.core :as core]))
(re-frame/reg-cofx
:data-store/all-dapp-permissions
(fn [cofx _]
(assoc cofx :all-dapp-permissions (-> @core/account-realm
(core/get-all :dapp-permissions)
(core/all-clj :dapp-permissions)))))
(defn save-dapp-permissions
"Returns tx function for saving dapp permissions"
[permissions]
(fn [realm]
(core/create realm :dapp-permissions permissions true)))
(defn remove-dapp-permissions
"Returns tx function for removing dapp permissions"
[dapp]
(fn [realm]
(core/delete realm (.objectForPrimaryKey realm "dapp" dapp))))

View File

@ -39,7 +39,10 @@
"wallet_getTransfers" {}
"browsers_getBrowsers" {}
"browsers_addBrowser" {}
"browsers_deleteBrowser" {}})
"browsers_deleteBrowser" {}
"permissions_addDappPermissions" {}
"permissions_getDappPermissions" {}
"permissions_deleteDappPermissions" {}})
(defn call
[{:keys [method params on-success on-error]}]
@ -92,7 +95,7 @@
;; effects
(re-frame/reg-fx
:json-rpc/call
::call
(fn [params]
(doseq [param params]
(call param))))

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-dapp-permissions)
(re-frame/inject-cofx :data-store/all-chats)
(re-frame/inject-cofx :data-store/all-chat-requests-ranges)]
multiaccount-change-success)

View File

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

View File

@ -3,6 +3,7 @@
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.chaos-mode.core :as chaos-mode]
[status-im.data-store.core :as data-store]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
[status-im.ethereum.transactions.core :as transactions]
[status-im.fleet.core :as fleet]
@ -146,6 +147,24 @@
(navigation/navigate-to-cofx :keycard-recovery-success nil)
(navigation/navigate-to-cofx :home nil))))))
(fx/defn initialize-dapp-permissions
{:events [::initialize-dapp-permissions]}
[{:keys [db]} all-dapp-permissions]
(let [dapp-permissions (reduce (fn [acc {:keys [dapp] :as dapp-permissions}]
(assoc acc dapp dapp-permissions))
{}
all-dapp-permissions)]
{:db (assoc db :dapps/permissions dapp-permissions)}))
(fx/defn initialize-browsers
{:events [::initialize-browsers]}
[{: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)}))
(fx/defn user-login-callback
{:events [:multiaccounts.login.callback/login-success]
:interceptors [(re-frame/inject-cofx :web3/get-web3)
@ -172,7 +191,11 @@
:card-read-in-progress?
:pin
:multiaccount))
:data-store/get-browsers nil
::json-rpc/call
[{:method "browsers_getBrowsers"
:on-success #(re-frame/dispatch [::initialize-browsers %])}
{:method "permissions_getDappPermissions"
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]
:web3/set-default-account [web3 address]
:web3/fetch-node-version [web3
#(re-frame/dispatch

View File

@ -118,6 +118,7 @@
:always
(assoc :WalletConfig {:Enabled true}
:BrowsersConfig {:Enabled true}
:PermissionsConfig {:Enabled true}
:WhisperConfig {:Enabled true
:LightClient true
:MinimumPoW 0.001

View File

@ -41,7 +41,7 @@
(fx/defn check-sync-state
[{:keys [db] :as cofx}]
(if (:multiaccount db)
{:json-rpc/call
{::json-rpc/call
[{:method "eth_syncing"
:on-success
(fn [sync]
@ -72,7 +72,7 @@
:rpc-url constants/ethereum-rpc-url
:transport/chats transport
:mailserver/topics mailserver-topics)
:json-rpc/call
::json-rpc/call
[{:method "net_version"
:on-success
(fn [fetched-network-id]

View File

@ -1,6 +1,7 @@
(ns status-im.utils.fx
(:require-macros status-im.utils.fx)
(:require [clojure.set :as set]
[status-im.ethereum.json-rpc :as json-rpc]
[taoensso.timbre :as log])
(:refer-clojure :exclude [merge]))
@ -15,7 +16,7 @@
:pairing/set-installation-metadata
:shh/send-direct-message :shh/remove-filter
:shh/generate-sym-key-from-password :transport/confirm-messages-processed
:group-chats/extract-membership-signature :utils/dispatch-later :json-rpc/call})
:group-chats/extract-membership-signature :utils/dispatch-later ::json-rpc/call})
(defn- safe-merge [fx new-fx]
(if (:merging-fx-with-common-keys fx)

View File

@ -3,8 +3,9 @@
flow has been changed. Such changes should be reflected in both these tests
and documents which describe the whole \"sign in\" flow."
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.multiaccounts.login.core :as login.core]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.events :as events]
[status-im.multiaccounts.login.core :as login.core]
[status-im.signals.core :as signals]
[status-im.test.sign-in.data :as data]))
@ -38,8 +39,6 @@
:web3 :web3
:all-contacts data/all-contacts
:all-installations []
:all-stored-browsers []
:all-dapp-permissions []
:get-all-stored-chats data/get-chats}
efx (events/multiaccount-change-success cofx [nil "address"])
new-db (:db efx)]
@ -183,7 +182,7 @@
login-result "{\"error\":\"\"}"
efx (login.core/user-login-callback cofx login-result)
new-db (:db efx)
json-rpc (into #{} (map :method (:json-rpc/call efx)))]
json-rpc-fx? (into #{} (map :method (::json-rpc/call efx)))]
(testing ":multiaccounts/login cleared."
(is (not (contains? new-db :multiaccounts/login))))
(testing "Check messaging related effects."
@ -198,8 +197,8 @@
(testing "Check the rest of effects."
(is (contains? efx :web3/set-default-account))
(is (contains? efx :web3/fetch-node-version))
(is (json-rpc "net_version"))
(is (json-rpc "eth_syncing"))
(is (json-rpc-fx? "net_version"))
(is (json-rpc-fx? "eth_syncing"))
(is (contains? efx :wallet/get-balance))
(is (contains? efx :wallet/get-tokens-balance))
(is (contains? efx :wallet/get-prices))))))