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 285c7c4 commit fc18880
Show file tree
Hide file tree
Showing 30 changed files with 206 additions and 415 deletions.
1 change: 0 additions & 1 deletion .clj-kondo/babashka/fs/config.edn

This file was deleted.

1 change: 0 additions & 1 deletion .clj-kondo/babashka/sci/config.edn

This file was deleted.

9 changes: 0 additions & 9 deletions .clj-kondo/babashka/sci/sci/core.clj

This file was deleted.

67 changes: 0 additions & 67 deletions .clj-kondo/config.edn

This file was deleted.

2 changes: 0 additions & 2 deletions .clj-kondo/status-im/config.edn

This file was deleted.

26 changes: 0 additions & 26 deletions .clj-kondo/status-im/utils/i18n.clj

This file was deleted.

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
21 changes: 4 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 Expand Up @@ -536,6 +519,10 @@
[]
(.backupDisabledDataDir ^js (status)))

(defn fleets
[]
(.fleets ^js (status)))

(defn keystore-dir
[]
(.keystoreDir ^js (status)))
Expand Down
20 changes: 20 additions & 0 deletions src/status_im/contexts/profile/rpc.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns status-im.contexts.profile.rpc
(:require
clojure.set
[clojure.string :as string]
[utils.ens.core :as utils.ens]))

(defn rpc->wakuv2-config
[wakuv2-config]
(clojure.set/rename-keys wakuv2-config {:LightClient :light-client}))

(defn rpc->profiles-overview
[{:keys [customizationColor keycard-pairing] :as profile}]
(if (map? profile)
(-> profile
(update :wakuv2-config rpc->wakuv2-config)
(dissoc :customizationColor)
(assoc :customization-color (keyword customizationColor))
(assoc :ens-name? (utils.ens/is-valid-eth-name? (:name profile)))
(assoc :keycard-pairing (when-not (string/blank? keycard-pairing) keycard-pairing)))
profile))
25 changes: 17 additions & 8 deletions src/status_im/fleet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
[status-im.node.core :as node]
[status-im2.config :as config]
[status-im2.constants :as constants]
[native-module.core :as native-module]
[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 +88,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])}))))
3 changes: 1 addition & 2 deletions src/status_im/keycard/card.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@
(error-object->map response)]))}))

(defn save-multiaccount-and-login
[args]
(keycard/save-multiaccount-and-login card args))
[_])

(defn login
[args]
Expand Down
24 changes: 2 additions & 22 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 @@ -152,6 +151,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 @@ -182,27 +182,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
9 changes: 1 addition & 8 deletions src/status_im/keycard/simulated_keycard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,7 @@
(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)))
[_])

(defn login
[{:keys [key-uid multiaccount-data password]}]
Expand Down
12 changes: 5 additions & 7 deletions src/status_im/log_level/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,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
Loading

0 comments on commit fc18880

Please sign in to comment.