[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:
parent
93f488e61a
commit
7d6b2ac87a
|
@ -425,6 +425,9 @@
|
||||||
(def ^:const optimism-goerli-chain-id 420)
|
(def ^:const optimism-goerli-chain-id 420)
|
||||||
(def ^:const optimism-sepolia-chain-id 11155420)
|
(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 mainnet-short-name "eth")
|
||||||
(def ^:const optimism-short-name "opt")
|
(def ^:const optimism-short-name "opt")
|
||||||
(def ^:const arbitrum-short-name "arb1")
|
(def ^:const arbitrum-short-name "arb1")
|
||||||
|
|
|
@ -60,8 +60,7 @@
|
||||||
:color :colorId})
|
:color :colorId})
|
||||||
(update :prodPreferredChainIds chain-ids-set->string)
|
(update :prodPreferredChainIds chain-ids-set->string)
|
||||||
(update :testPreferredChainIds chain-ids-set->string)
|
(update :testPreferredChainIds chain-ids-set->string)
|
||||||
(dissoc :watch-only?)
|
(dissoc :watch-only? :default-account? :tokens :collectibles)))
|
||||||
(dissoc :default-account?)))
|
|
||||||
|
|
||||||
(defn- rpc->balances-per-chain
|
(defn- rpc->balances-per-chain
|
||||||
[token]
|
[token]
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[react-native.background-timer :as background-timer]
|
[react-native.background-timer :as background-timer]
|
||||||
[react-native.platform :as platform]
|
[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.data-store :as data-store]
|
||||||
[status-im.contexts.wallet.events.collectibles]
|
[status-im.contexts.wallet.events.collectibles]
|
||||||
[status-im.contexts.wallet.item-types :as item-types]
|
[status-im.contexts.wallet.item-types :as item-types]
|
||||||
|
@ -12,7 +14,8 @@
|
||||||
[utils.ethereum.eip.eip55 :as eip55]
|
[utils.ethereum.eip.eip55 :as eip55]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
[utils.number]
|
[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
|
(rf/reg-event-fx :wallet/show-account-created-toast
|
||||||
(fn [{:keys [db]} [address]]
|
(fn [{:keys [db]} [address]]
|
||||||
|
@ -426,7 +429,6 @@
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/store-secret-phrase store-secret-phrase)
|
(rf/reg-event-fx :wallet/store-secret-phrase store-secret-phrase)
|
||||||
|
|
||||||
|
|
||||||
(defn new-keypair-created
|
(defn new-keypair-created
|
||||||
[{:keys [db]} [{:keys [new-keypair]}]]
|
[{:keys [db]} [{:keys [new-keypair]}]]
|
||||||
{:db (assoc-in db [:wallet :ui :create-account :new-keypair] 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)})
|
{: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/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}]]])})))
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
(:require
|
(:require
|
||||||
[oops.core :as oops]
|
[oops.core :as oops]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]
|
||||||
|
[utils.transforms :as transforms]))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/pending-transaction-status-changed-received
|
:wallet/pending-transaction-status-changed-received
|
||||||
(fn [{:keys [db]} [{:keys [message]}]]
|
(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)]
|
tx-hash (:hash details)]
|
||||||
{:db (update-in db [:wallet :transactions tx-hash] assoc :status :confirmed :blocks 1)})))
|
{:db (update-in db [:wallet :transactions tx-hash] assoc :status :confirmed :blocks 1)})))
|
||||||
|
|
||||||
|
@ -25,22 +26,17 @@
|
||||||
"pending-transaction-status-changed" {:fx
|
"pending-transaction-status-changed" {:fx
|
||||||
[[:dispatch
|
[[:dispatch
|
||||||
[:wallet/pending-transaction-status-changed-received
|
[:wallet/pending-transaction-status-changed-received
|
||||||
(js->clj event-js
|
(transforms/js->clj event-js)]]]}
|
||||||
:keywordize-keys
|
|
||||||
true)]]]}
|
|
||||||
"wallet-owned-collectibles-filtering-done" {:fx [[:dispatch
|
"wallet-owned-collectibles-filtering-done" {:fx [[:dispatch
|
||||||
[:wallet/owned-collectibles-filtering-done
|
[:wallet/owned-collectibles-filtering-done
|
||||||
(js->clj event-js
|
(transforms/js->clj event-js)]]]}
|
||||||
:keywordize-keys
|
|
||||||
true)]]]}
|
|
||||||
"wallet-get-collectibles-details-done" {:fx [[:dispatch
|
"wallet-get-collectibles-details-done" {:fx [[:dispatch
|
||||||
[:wallet/get-collectible-details-done
|
[:wallet/get-collectible-details-done
|
||||||
(js->clj event-js
|
(transforms/js->clj event-js)]]]}
|
||||||
:keywordize-keys
|
|
||||||
true)]]]}
|
|
||||||
"wallet-tick-reload" {:fx [[:dispatch [:wallet/reload]]]}
|
"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
|
(log/debug ::unknown-wallet-event
|
||||||
:type type
|
:type event-type
|
||||||
:event (js->clj event-js
|
:event (transforms/js->clj event-js))))))
|
||||||
:keywordize-keys
|
|
||||||
true))))))
|
|
||||||
|
|
|
@ -213,10 +213,14 @@
|
||||||
"Add with defaults, this version is able to receive `nil` and takes them as 0."
|
"Add with defaults, this version is able to receive `nil` and takes them as 0."
|
||||||
(fnil add* (bignumber 0) (bignumber 0)))
|
(fnil add* (bignumber 0) (bignumber 0)))
|
||||||
|
|
||||||
(defn mul
|
(defn- mul*
|
||||||
[bn1 bn2]
|
[bn1 bn2]
|
||||||
(.mul ^js 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
|
(defn mul-and-round
|
||||||
[bn1 bn2]
|
[bn1 bn2]
|
||||||
(.round (.mul ^js bn1 bn2) 0))
|
(.round (.mul ^js bn1 bn2) 0))
|
||||||
|
|
|
@ -2514,5 +2514,6 @@
|
||||||
"keypair-name-input-placeholder": "Collectibles account, Old vault....",
|
"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.",
|
"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}}",
|
"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}}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue