Skip to content

Commit

Permalink
Add fetch messages behind a toggle & some advanced settings
Browse files Browse the repository at this point in the history
This PR does a few things:

1) Add fetch messages implementation on any kind of chat. It's behind a
   toggle (on by default) as design is still unsure whether we want it,
   but it's very useful for debugging.
2) Allow setting light client from mobile

It also partially remove node config management from the clojure part,
as it's better if that's not explicitly managed by clients.
Some parts are still relying on it but they are not functional
(keycard), while others are still using it and will need to be updated
eventually (syncing), in order to get rid completely of node config.

status-im/status-go@8a4c2d8...8cf9986
  • Loading branch information
cammellos committed Nov 27, 2023
1 parent 1385e27 commit a76d93e
Show file tree
Hide file tree
Showing 19 changed files with 149 additions and 313 deletions.
17 changes: 0 additions & 17 deletions src/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@
config
#(callback (types/json->clj %))))

(defn save-account-and-login
"NOTE: beware, the password has to be sha3 hashed"
[key-uid multiaccount-data hashed-password settings config accounts-data]
(log/debug "[native-module] save-account-and-login"
"multiaccount-data"
multiaccount-data)
(clear-web-data)
(init-keystore
key-uid
#(.saveAccountAndLogin
^js (status)
multiaccount-data
hashed-password
settings
config
accounts-data)))

(defn save-multiaccount-and-login-with-keycard
"NOTE: chat-key is a whisper private key sent from keycard"
[key-uid multiaccount-data password settings config accounts-data chat-key]
Expand Down
11 changes: 5 additions & 6 deletions src/status_im/fleet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@
[{:keys [db now] :as cofx} fleet]
(let [old-fleet (get-in db [:profile/profile :fleet])]
(when (not= fleet old-fleet)
(rf/merge
(multiaccounts.update/multiaccount-update
cofx
(multiaccounts.update/multiaccount-update :fleet fleet {})
(node/prepare-new-config
{:on-success
#(re-frame/dispatch
[:multiaccounts.update.callback/save-settings-success])})))))
:fleet
fleet
{:on-success
#(re-frame/dispatch [:logout])}))))
43 changes: 22 additions & 21 deletions src/status_im/keycard/recovery.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
[taoensso.timbre :as log]
[utils.address :as address]
[utils.datetime :as datetime]
[utils.ethereum.eip.eip55 :as eip55]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[utils.security.core :as security]))
Expand Down Expand Up @@ -183,26 +182,28 @@
{:db (-> db
(assoc-in [:keycard :setup-step] nil)
(dissoc :intro-wizard))}
(multiaccounts.create/on-multiaccount-created
{:recovered (or recovered (get-in db [:intro-wizard :recovering?]))
:derived {constants/path-wallet-root-keyword
{:public-key wallet-root-public-key
:address (eip55/address->checksum wallet-root-address)}
constants/path-whisper-keyword
{:public-key whisper-public-key
:address (eip55/address->checksum whisper-address)}
constants/path-default-wallet-keyword
{:public-key wallet-public-key
:address (eip55/address->checksum wallet-address)}}
:address address
:public-key public-key
:keycard-instance-uid instance-uid
:key-uid (address/normalized-hex key-uid)
:keycard-pairing pairing
:keycard-paired-on paired-on
:chat-key whisper-private-key}
encryption-public-key
{}))))
;; NOTE: Disabling as keycard not functional and this needs to be moved to
;; status-go
#_(multiaccounts.create/on-multiaccount-created
{:recovered (or recovered (get-in db [:intro-wizard :recovering?]))
:derived {constants/path-wallet-root-keyword
{:public-key wallet-root-public-key
:address (eip55/address->checksum wallet-root-address)}
constants/path-whisper-keyword
{:public-key whisper-public-key
:address (eip55/address->checksum whisper-address)}
constants/path-default-wallet-keyword
{:public-key wallet-public-key
:address (eip55/address->checksum wallet-address)}}
:address address
:public-key public-key
:keycard-instance-uid instance-uid
:key-uid (address/normalized-hex key-uid)
:keycard-pairing pairing
:keycard-paired-on paired-on
:chat-key whisper-private-key}
encryption-public-key
{}))))

(rf/defn return-to-keycard-login
[{:keys [db] :as cofx}]
Expand Down
17 changes: 9 additions & 8 deletions src/status_im/keycard/simulated_keycard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,15 @@
(log/warn "sign-typed-data not implemented" args))

(defn save-multiaccount-and-login
[{:keys [key-uid multiaccount-data password settings node-config accounts-data]}]
(native-module/save-account-and-login
key-uid
(types/clj->json multiaccount-data)
password
(types/clj->json settings)
node-config
(types/clj->json accounts-data)))
[_]
;; NOTE: disabling as we don't support keycard for now and it's using an outdated endpoint
#_(native-module/save-account-and-login
key-uid
(types/clj->json multiaccount-data)
password
(types/clj->json settings)
node-config
(types/clj->json accounts-data)))

(defn login
[{:keys [key-uid multiaccount-data password]}]
Expand Down
13 changes: 5 additions & 8 deletions src/status_im/log_level/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require
[re-frame.core :as re-frame]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.node.core :as node]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

Expand All @@ -11,13 +10,11 @@
[{:keys [db now] :as cofx} log-level]
(let [old-log-level (get-in db [:profile/profile :log-level])]
(when (not= old-log-level log-level)
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:log-level
log-level
{})
(node/prepare-new-config
{:on-success #(re-frame/dispatch [:logout])})))))
(multiaccounts.update/multiaccount-update
cofx
:log-level
log-level
{:on-success #(re-frame/dispatch [:logout])}))))

(rf/defn show-change-log-level-confirmation
{:events [:log-level.ui/log-level-selected]}
Expand Down
140 changes: 1 addition & 139 deletions src/status_im/multiaccounts/create/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
(:require
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.data-store.settings :as data-store.settings]
[status-im.node.core :as node]
[status-im.ui.components.colors :as colors]
[status-im.utils.deprecated-types :as types]
[status-im.utils.signing-phrase.core :as signing-phrase]
[status-im2.config :as config]
[status-im2.constants :as constants]
[utils.ethereum.eip.eip55 :as eip55]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[utils.security.core :as security]))
[utils.re-frame :as rf]))

(defn normalize-derived-data-keys
[derived-data]
Expand Down Expand Up @@ -82,134 +75,3 @@
(rf/defn save-multiaccount-and-login-with-keycard
[_ args]
{:keycard/save-multiaccount-and-login args})

(re-frame/reg-fx
::save-account-and-login
(fn [[key-uid multiaccount-data hashed-password settings config accounts-data]]
(native-module/save-account-and-login
key-uid
multiaccount-data
hashed-password
settings
config
accounts-data)))

(rf/defn save-account-and-login
[_ key-uid multiaccount-data password settings node-config accounts-data]
{::save-account-and-login [key-uid
(types/clj->json multiaccount-data)
password
(types/clj->json settings)
node-config
(types/clj->json accounts-data)]})

(defn prepare-accounts-data
[multiaccount]
[(let [{:keys [public-key address]}
(get-in multiaccount [:derived constants/path-default-wallet-keyword])]
{:public-key public-key
:address (eip55/address->checksum address)
:color colors/blue-persist
:wallet true
:path constants/path-default-wallet
:name (i18n/label :t/main-account)})
(let [{:keys [compressed-key public-key address name]}
(get-in multiaccount [:derived constants/path-whisper-keyword])]
{:public-key public-key
:compressed-key compressed-key
:address (eip55/address->checksum address)
:name name
:path constants/path-whisper
:chat true})])

(rf/defn on-multiaccount-created
[{:keys [signing-phrase random-guid-generator db] :as cofx}
{:keys [address chat-key keycard-instance-uid key-uid
keycard-pairing keycard-paired-on mnemonic recovered]
:as multiaccount}
password
{:keys [save-mnemonic? login?] :or {login? true save-mnemonic? false}}]
(let [[wallet-account
{:keys [public-key
compressed-key
name]} :as accounts-data]
(prepare-accounts-data
multiaccount)
multiaccount-data {:name name
:address address
:key-uid key-uid
:keycard-pairing keycard-pairing}
keycard-multiaccount? (boolean keycard-pairing)
eip1581-address (get-in multiaccount
[:derived
constants/path-eip1581-keyword
:address])
new-multiaccount
(cond->
(merge
{;; address of the master key
:address address
;; sha256 of master public key
:key-uid key-uid
;; The address from which we derive any wallet
:wallet-root-address
(get-in multiaccount
[:derived
constants/path-wallet-root-keyword
:address])
:name name
;; public key of the chat account
:public-key public-key
;; compressed key of the chat account
:compressed-key compressed-key
;; default address for Dapps
:dapps-address (:address wallet-account)
:latest-derived-path 0
:signing-phrase signing-phrase
:backup-enabled? true
:installation-id (random-guid-generator)
;; default mailserver (history node) setting
:use-mailservers? true
:recovered recovered}
config/default-multiaccount)
;; The address from which we derive any chat
;; account/encryption keys
eip1581-address
(assoc :eip1581-address eip1581-address)
save-mnemonic?
(assoc :mnemonic mnemonic)
keycard-multiaccount?
(assoc :keycard-instance-uid keycard-instance-uid
:keycard-pairing keycard-pairing
:keycard-paired-on keycard-paired-on))
db (assoc db
:profile/login {:key-uid key-uid
:name name
:password password
:creating? true
:processing true}
:profile/profile new-multiaccount
:profile/wallet-accounts [wallet-account]
:networks/current-network config/default-network
:networks/networks (data-store.settings/rpc->networks config/default-networks))
settings (assoc new-multiaccount
:networks/current-network config/default-network
:networks/networks config/default-networks)]
(rf/merge cofx
{:db db}
(if keycard-multiaccount?
(save-multiaccount-and-login-with-keycard
{:key-uid key-uid
:multiaccount-data multiaccount-data
:password password
:settings settings
:node-config (node/get-new-config db)
:accounts-data accounts-data
:chat-key chat-key})
(save-account-and-login
key-uid
multiaccount-data
(native-module/sha3 (security/safe-unmask-data password))
settings
(node/get-new-config db)
accounts-data)))))
11 changes: 4 additions & 7 deletions src/status_im/network/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require
[clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.node.core :as node]
[status-im2.navigation.events :as navigation]
[utils.ethereum.chain :as chain]
[utils.i18n :as i18n]
Expand Down Expand Up @@ -117,12 +116,10 @@
(rf/defn save-network-settings
{:events [::save-network-settings-pressed]}
[{:keys [db] :as cofx} network]
(rf/merge cofx
{:db (assoc db :networks/current-network network)
:json-rpc/call [{:method "settings_saveSetting"
:params [:networks/current-network network]
:on-success #()}]}
(node/prepare-new-config {:on-success #(re-frame/dispatch [:logout])})))
{:db (assoc db :networks/current-network network)
:json-rpc/call [{:method "settings_saveSetting"
:params [:networks/current-network network]
:on-success #(re-frame/dispatch [:logout])}]})

(rf/defn remove-network
{:events [::remove-network-confirmed]}
Expand Down
35 changes: 2 additions & 33 deletions src/status_im/node/core.cljs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
(ns status-im.node.core
(:require
[clojure.string :as string]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[react-native.platform :as platform]
[status-im.utils.deprecated-types :as types]
[status-im2.config :as config]
[utils.re-frame :as rf]))
[status-im2.config :as config]))

(defn- add-custom-bootnodes
[config network all-bootnodes]
Expand Down Expand Up @@ -195,32 +192,4 @@
:always
(add-log-level log-level))))

(defn get-new-config
[db]
(types/clj->json (get-multiaccount-node-config db)))

(rf/defn save-new-config
"Saves a new status-go config for the current account
This RPC method is the only way to change the node config of an account.
NOTE: it is better used indirectly through `prepare-new-config`,
which will take care of building up the proper config based on settings in
app-db"
{:events [::save-new-config]}
[_ config {:keys [on-success]}]
{:json-rpc/call [{:method "settings_saveSetting"
:params [:node-config config]
:on-success on-success}]})

(rf/defn prepare-new-config
"Use this function to apply settings to the current account node config"
[{:keys [db]} {:keys [on-success]}]
(let [key-uid (get-in db [:profile/profile :key-uid])]
{::prepare-new-config [key-uid
(get-new-config db)
#(re-frame/dispatch
[::save-new-config % {:on-success on-success}])]}))

(re-frame/reg-fx
::prepare-new-config
(fn [[key-uid config callback]]
(native-module/prepare-dir-and-update-config key-uid config callback)))

Loading

0 comments on commit a76d93e

Please sign in to comment.