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.

Sets fleet to shards.test

status-im/status-go@90c31af...1adcf02
  • Loading branch information
cammellos committed Dec 20, 2023
1 parent 800ca19 commit 32cfd21
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,11 @@ public String keystoreDir() {
return pathCombine(absRootDirPath, "keystore");
}

@ReactMethod(isBlockingSynchronousMethod = true)
public String fleets() {
return Statusgo.fleets();
}

@ReactMethod(isBlockingSynchronousMethod = true)
public String backupDisabledDataDir() {
return this.getNoBackupDirectory();
Expand Down
4 changes: 4 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,10 @@ - (void) migrateKeystore:(NSString *)accountData
return StatusgoIsAddress(address);
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(fleets) {
return StatusgoFleets();
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(toChecksumAddress:(NSString *)address) {
return StatusgoToChecksumAddress(address);
}
Expand Down
13 changes: 13 additions & 0 deletions modules/react-native-status/nodejs/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ void _MultiAccountStoreAccount(const FunctionCallbackInfo<Value>& args) {
delete c;
}


void _InitKeystore(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
Expand Down Expand Up @@ -562,6 +563,17 @@ void _CheckAddressChecksum(const FunctionCallbackInfo<Value>& args) {

}

void _Fleets(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// Call exported Go function, which returns a C string
char *c = Fleets();

Local<String> ret = String::NewFromUtf8(isolate, c).ToLocalChecked();
args.GetReturnValue().Set(ret);
delete c;
}


void _IsAddress(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
Expand Down Expand Up @@ -1888,6 +1900,7 @@ void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "multiAccountStoreDerivedAccounts", _MultiAccountStoreDerivedAccounts);
NODE_SET_METHOD(exports, "multiAccountStoreAccount", _MultiAccountStoreAccount);
NODE_SET_METHOD(exports, "initKeystore", _InitKeystore);
NODE_SET_METHOD(exports, "fleets", _Fleets);
NODE_SET_METHOD(exports, "stopCPUProfiling", _StopCPUProfiling);
NODE_SET_METHOD(exports, "encodeTransfer", _EncodeTransfer);
NODE_SET_METHOD(exports, "encodeFunctionCall", _EncodeFunctionCall);
Expand Down
26 changes: 17 additions & 9 deletions src/legacy/status_im/fleet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@
(:require
[legacy.status-im.multiaccounts.update.core :as multiaccounts.update]
[legacy.status-im.node.core :as node]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.config :as config]
[status-im.constants :as constants]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
[utils.re-frame :as rf]
[utils.transforms :as transforms]))

(def ^:private default-fleets (transforms/json->clj (native-module/fleets)))
(def ^:private default-fleet (:defaultFleet default-fleets))
(def fleets
(->> default-fleets
:fleets
keys
(map name)))

(defn current-fleet-sub
[multiaccount]
(keyword (or (get multiaccount :fleet)
config/fleet)))
default-fleet)))

(defn format-mailserver
[mailserver address]
Expand Down Expand Up @@ -78,10 +87,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])}))))
18 changes: 1 addition & 17 deletions src/legacy/status_im/keycard/card.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -527,23 +527,7 @@
(error-object->map response)]))}))

(defn save-multiaccount-and-login
[{:keys [key-uid multiaccount-data password settings node-config accounts-data chat-key]}]
(if config/keycard-test-menu-enabled?
(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))
(native-module/save-multiaccount-and-login-with-keycard
key-uid
(types/clj->json multiaccount-data)
password
(types/clj->json settings)
node-config
(types/clj->json accounts-data)
chat-key)))
[_])

(defn login
[{:keys [key-uid multiaccount-data password] :as args}]
Expand Down
24 changes: 2 additions & 22 deletions src/legacy/status_im/keycard/recovery.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 @@ -151,6 +150,7 @@
:keycard/check-nfc-enabled nil}
(intro-wizard)))

;; NOTE: currently non functional, keycard needs to be reimplemented
(rf/defn create-keycard-multiaccount
{:events [::create-keycard-multiaccount]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
Expand Down Expand Up @@ -181,27 +181,7 @@
(rf/merge cofx
{: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
{}))))
(dissoc :intro-wizard))})))

(rf/defn return-to-keycard-login
[{:keys [db] :as cofx}]
Expand Down
13 changes: 5 additions & 8 deletions src/legacy/status_im/log_level/core.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns legacy.status-im.log-level.core
(:require
[legacy.status-im.multiaccounts.update.core :as multiaccounts.update]
[legacy.status-im.node.core :as node]
[re-frame.core :as re-frame]
[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/legacy/status_im/multiaccounts/create/core.cljs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
(ns legacy.status-im.multiaccounts.create.core
(:require
[legacy.status-im.data-store.settings :as data-store.settings]
[legacy.status-im.node.core :as node]
[legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.utils.deprecated-types :as types]
[legacy.status-im.utils.signing-phrase.core :as signing-phrase]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.config :as config]
[status-im.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
[{:keys [db]} key-uid multiaccount-data password settings node-config accounts-data]
{:db (assoc-in db [:syncing :login-sha3-password] password)
::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/legacy/status_im/network/core.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns legacy.status-im.network.core
(:require
[clojure.string :as string]
[legacy.status-im.node.core :as node]
[re-frame.core :as re-frame]
[status-im.navigation.events :as navigation]
[utils.ethereum.chain :as chain]
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
Loading

0 comments on commit 32cfd21

Please sign in to comment.