[Feature] Wallet - Handle Blockchain Status (#18850)

This commit adds the feature to handle blockchain status signals from the status-go and shows a toast if the provider for any of the blockchains is down.

Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2024-03-06 20:59:52 +05:30 committed by GitHub
parent 93f488e61a
commit 7d6b2ac87a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 61 additions and 21 deletions

View File

@ -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")

View File

@ -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)))
(defn- rpc->balances-per-chain
[token]

View File

@ -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]
@ -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]]
@ -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)
@ -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}]]])})))

View File

@ -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)})))
@ -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))))))

View File

@ -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))

View File

@ -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}}"
}