Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Wallet - Handle blockchain status #18850

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@
(def ^:const optimism-goerli-chain-id 420)
(def ^:const optimism-sepolia-chain-id 11155420)

(def ^:const mainnet-chain-ids
#{ethereum-mainnet-chain-id arbitrum-mainnet-chain-id optimism-mainnet-chain-id})

(def ^:const mainnet-short-name "eth")
(def ^:const optimism-short-name "opt")
(def ^:const arbitrum-short-name "arb1")
Expand Down
3 changes: 1 addition & 2 deletions src/status_im/contexts/wallet/data_store.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
:color :colorId})
(update :prodPreferredChainIds chain-ids-set->string)
(update :testPreferredChainIds chain-ids-set->string)
(dissoc :watch-only?)
(dissoc :default-account?)))
(dissoc :watch-only? :default-account? :tokens :collectibles)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been unnecessarily sending huge amounts of tokens and collectible data whenever we edit an account.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
I've faced some performance issues while just updating the profile!


(defn- rpc->balances-per-chain
[token]
Expand Down
41 changes: 39 additions & 2 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[clojure.string :as string]
[react-native.background-timer :as background-timer]
[react-native.platform :as platform]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.data-store :as data-store]
[status-im.contexts.wallet.events.collectibles]
[status-im.contexts.wallet.item-types :as item-types]
Expand All @@ -12,7 +14,8 @@
[utils.ethereum.eip.eip55 :as eip55]
[utils.i18n :as i18n]
[utils.number]
[utils.re-frame :as rf]))
[utils.re-frame :as rf]
[utils.transforms :as transforms]))

(rf/reg-event-fx :wallet/show-account-created-toast
(fn [{:keys [db]} [address]]
Expand Down Expand Up @@ -426,7 +429,6 @@

(rf/reg-event-fx :wallet/store-secret-phrase store-secret-phrase)


(defn new-keypair-created
[{:keys [db]} [{:keys [new-keypair]}]]
{:db (assoc-in db [:wallet :ui :create-account :new-keypair] new-keypair)
Expand All @@ -448,3 +450,38 @@
{:db (update-in db [:wallet :ui :create-account] dissoc :new-keypair)})

(rf/reg-event-fx :wallet/clear-new-keypair clear-new-keypair)

(rf/reg-event-fx
:wallet/blockchain-status-changed
(fn [{:keys [db]} [{:keys [message]}]]
(let [chains (-> (transforms/json->clj message)
(update-keys (comp utils.number/parse-int name)))
down-chains (-> (select-keys chains
(for [[k v] chains :when (= v "down")] k))
keys)
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
disabled-chain-id? (fn [chain-id]
(let [mainnet-chain? (contains? constants/mainnet-chain-ids chain-id)]
(if test-networks-enabled?
mainnet-chain?
(not mainnet-chain?))))
chains-filtered-by-mode (remove disabled-chain-id? down-chains)
chains-down? (seq chains-filtered-by-mode)
chain-names (when chains-down?
(->> (map #(-> (utils/id->network %)
name
string/capitalize)
chains-filtered-by-mode)
distinct
(string/join ", ")))]
(when (seq down-chains)
(log/info "[wallet] Chain(s) down: " down-chains)
(log/info "[wallet] Test network enabled: " (boolean test-networks-enabled?)))
{:db (assoc-in db [:wallet :statuses :blockchains] chains)
:fx (when chains-down?
[[:dispatch
[:toasts/upsert
{:id :chains-down
:type :negative
:text (i18n/label :t/provider-is-down {:chains chain-names})
:duration 10000}]]])})))
26 changes: 11 additions & 15 deletions src/status_im/contexts/wallet/signals.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
(:require
[oops.core :as oops]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
[utils.re-frame :as rf]
[utils.transforms :as transforms]))

(rf/reg-event-fx
:wallet/pending-transaction-status-changed-received
(fn [{:keys [db]} [{:keys [message]}]]
(let [details (js->clj (js/JSON.parse message) :keywordize-keys true)
(let [details (transforms/json->clj message)
tx-hash (:hash details)]
{:db (update-in db [:wallet :transactions tx-hash] assoc :status :confirmed :blocks 1)})))

Expand All @@ -25,22 +26,17 @@
"pending-transaction-status-changed" {:fx
[[:dispatch
[:wallet/pending-transaction-status-changed-received
(js->clj event-js
:keywordize-keys
true)]]]}
(transforms/js->clj event-js)]]]}
"wallet-owned-collectibles-filtering-done" {:fx [[:dispatch
[:wallet/owned-collectibles-filtering-done
(js->clj event-js
:keywordize-keys
true)]]]}
(transforms/js->clj event-js)]]]}
"wallet-get-collectibles-details-done" {:fx [[:dispatch
[:wallet/get-collectible-details-done
(js->clj event-js
:keywordize-keys
true)]]]}
(transforms/js->clj event-js)]]]}
"wallet-tick-reload" {:fx [[:dispatch [:wallet/reload]]]}
"wallet-blockchain-status-changed" {:fx [[:dispatch
[:wallet/blockchain-status-changed
(transforms/js->clj event-js)]]]}
(log/debug ::unknown-wallet-event
:type type
:event (js->clj event-js
:keywordize-keys
true))))))
:type event-type
:event (transforms/js->clj event-js))))))
6 changes: 5 additions & 1 deletion src/utils/money.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,14 @@
"Add with defaults, this version is able to receive `nil` and takes them as 0."
(fnil add* (bignumber 0) (bignumber 0)))

(defn mul
(defn- mul*
[bn1 bn2]
(.mul ^js bn1 bn2))

(def mul
"Multiply with defaults, this version is able to receive `nil` and takes them as 0."
(fnil mul* (bignumber 0) (bignumber 0)))

(defn mul-and-round
[bn1 bn2]
(.round (.mul ^js bn1 bn2) 0))
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2514,5 +2514,6 @@
"keypair-name-input-placeholder": "Collectibles account, Old vault....",
"goerli-testnet-toggle-confirmation": "Are you sure you want to toggle Goerli? This will log you out and you will have to login again.",
"bridged-to": "Bridged to {{network}}",
"slide-to-bridge": "Slide to bridge"
"slide-to-bridge": "Slide to bridge",
"provider-is-down": "The provider for the following chain(s) is down: {{chains}}"
}