From cc70a7e8dab06a614a4f010b404105e218a1b413 Mon Sep 17 00:00:00 2001 From: Andrey Shovkoplyas Date: Thu, 16 Apr 2020 15:54:33 +0200 Subject: [PATCH] [#10203] Endless spinner when sending two TX in a batch in Dapp Signed-off-by: Andrea Maria Piana --- src/status_im/events.cljs | 5 -- src/status_im/multiaccounts/login/core.cljs | 5 +- src/status_im/signing/core.cljs | 7 +- .../ui/screens/currency_settings/models.cljs | 4 +- src/status_im/wallet/accounts/core.cljs | 5 +- src/status_im/wallet/core.cljs | 71 +----------------- src/status_im/wallet/custom_tokens/core.cljs | 5 +- src/status_im/wallet/prices.cljs | 73 +++++++++++++++++++ .../transactions/test_daaps_transactions.py | 2 - 9 files changed, 92 insertions(+), 85 deletions(-) create mode 100644 src/status_im/wallet/prices.cljs diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index fd50b98a44..7f118cfb52 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -1080,11 +1080,6 @@ ;; wallet events -(handlers/register-handler-fx - :wallet.ui/pull-to-refresh - (fn [cofx _] - (wallet/update-prices cofx))) - (handlers/register-handler-fx :wallet.transactions/add-filter (fn [{:keys [db]} [_ id]] diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 70a5a4cbe1..1d5f7c3173 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -34,7 +34,8 @@ [status-im.popover.core :as popover] [status-im.hardwallet.nfc :as nfc] [status-im.multiaccounts.core :as multiaccounts] - [status-im.data-store.settings :as data-store.settings])) + [status-im.data-store.settings :as data-store.settings] + [status-im.wallet.prices :as prices])) (def rpc-endpoint "https://goerli.infura.io/v3/f315575765b14720b32382a61a89341a") (def contract-address "0xfbf4c8e2B41fAfF8c616a0E49Fb4365a5355Ffaf") @@ -87,7 +88,7 @@ (rpc->accounts accounts))} (wallet/initialize-tokens custom-tokens) (wallet/update-balances nil) - (wallet/update-prices))) + (prices/update-prices))) (fx/defn login {:events [:multiaccounts.login.ui/password-input-submitted]} diff --git a/src/status_im/signing/core.cljs b/src/status_im/signing/core.cljs index cdddcf4496..5728f757c4 100644 --- a/src/status_im/signing/core.cljs +++ b/src/status_im/signing/core.cljs @@ -22,7 +22,8 @@ [status-im.utils.types :as types] [status-im.utils.utils :as utils] [taoensso.timbre :as log] - [re-frame.core :as re-frame.core])) + [re-frame.core :as re-frame.core] + [status-im.wallet.prices :as prices])) (re-frame/reg-fx :signing/send-transaction-fx @@ -206,8 +207,8 @@ :signing/in-progress? true :signing/queue (drop-last queue) :signing/tx (prepare-tx updated-db tx)) - :dismiss-keyboard nil - :dispatch [:wallet.ui/pull-to-refresh]} ;;TODO fix for v.1.2 + :dismiss-keyboard nil} + (prices/update-prices) #(when-not gas {:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true) :signing/update-estimated-gas {:obj tx-obj diff --git a/src/status_im/ui/screens/currency_settings/models.cljs b/src/status_im/ui/screens/currency_settings/models.cljs index 40c549ce52..88dace4ba5 100644 --- a/src/status_im/ui/screens/currency_settings/models.cljs +++ b/src/status_im/ui/screens/currency_settings/models.cljs @@ -1,7 +1,7 @@ (ns status-im.ui.screens.currency-settings.models (:require [status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.utils.fx :as fx] - [status-im.wallet.core :as wallet])) + [status-im.wallet.prices :as prices])) (defn get-currency [db] (get-in db [:multiaccount :currency] :usd)) @@ -12,4 +12,4 @@ (multiaccounts.update/multiaccount-update :currency currency {}) - (wallet/update-prices))) + (prices/update-prices))) diff --git a/src/status_im/wallet/accounts/core.cljs b/src/status_im/wallet/accounts/core.cljs index eba9858656..cf537f6f55 100644 --- a/src/status_im/wallet/accounts/core.cljs +++ b/src/status_im/wallet/accounts/core.cljs @@ -18,7 +18,8 @@ [status-im.utils.security :as security] [status-im.multiaccounts.recover.core :as recover] [status-im.ethereum.mnemonic :as mnemonic] - [taoensso.timbre :as log])) + [taoensso.timbre :as log] + [status-im.wallet.prices :as prices])) (fx/defn start-adding-new-account {:events [:wallet.accounts/start-adding-new-account]} @@ -194,7 +195,7 @@ {:db (update-in db [:add-account :account] merge account)} (save-new-account) (wallet/update-balances nil) - (wallet/update-prices) + (prices/update-prices) (navigation/navigate-back))))) (fx/defn add-watch-account diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index 98c5b2ba1a..14dc48730a 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -4,19 +4,16 @@ [status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.constants :as constants] [status-im.waku.core :as waku] - [status-im.chat.models.message :as chat.message] [status-im.ethereum.core :as ethereum] [status-im.ethereum.eip55 :as eip55] [status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.tokens :as tokens] [status-im.i18n :as i18n] [status-im.ui.screens.navigation :as navigation] - [status-im.wallet.utils :as wallet.utils] [status-im.utils.config :as config] [status-im.utils.core :as utils.core] [status-im.utils.fx :as fx] [status-im.utils.money :as money] - [status-im.utils.prices :as prices] [status-im.utils.utils :as utils.utils] [taoensso.timbre :as log] [status-im.wallet.db :as wallet.db] @@ -26,7 +23,8 @@ [status-im.contact.db :as contact.db] [status-im.ethereum.ens :as ens] [status-im.ethereum.stateofus :as stateofus] - [status-im.ui.components.bottom-sheet.core :as bottom-sheet])) + [status-im.ui.components.bottom-sheet.core :as bottom-sheet] + [status-im.wallet.prices :as prices])) (defn get-balance [{:keys [address on-success on-error]}] @@ -46,29 +44,9 @@ :on-success #(re-frame/dispatch [::update-balance-success address %]) :on-error #(re-frame/dispatch [::update-balance-fail %])})))) -;; TODO(oskarth): At some point we want to get list of relevant -;; assets to get prices for -(re-frame/reg-fx - :wallet/get-prices - (fn [{:keys [from to mainnet? success-event error-event chaos-mode?]}] - (prices/get-prices from - to - mainnet? - #(re-frame/dispatch [success-event %]) - #(re-frame/dispatch [error-event %]) - chaos-mode?))) - (defn assoc-error-message [db error-type err] (assoc-in db [:wallet :errors error-type] (or err :unknown-error))) -(fx/defn on-update-prices-fail - {:events [::update-prices-fail]} - [{:keys [db]} err] - (log/debug "Unable to get prices: " err) - {:db (-> db - (assoc-error-message :prices-update :error-unable-to-get-prices) - (assoc :prices-loading? false))}) - (fx/defn on-update-balance-fail {:events [::update-balance-fail]} [{:keys [db]} err] @@ -196,14 +174,6 @@ :wallet/get-tokens-balances get-token-balances) -(defn clear-error-message [db error-type] - (update-in db [:wallet :errors] dissoc error-type)) - -(defn tokens-symbols - [visible-token-symbols all-tokens] - (set/difference (set visible-token-symbols) - (set (map :symbol (tokens/nfts-for all-tokens))))) - (defn rpc->token [tokens] (reduce (fn [acc {:keys [address] :as token}] (assoc acc @@ -248,52 +218,19 @@ :tokens tokens :assets assets :init? init?} - :db (clear-error-message db :balance-update)} + :db (prices/clear-error-message db :balance-update)} (when-not assets (multiaccounts.update/multiaccount-update :wallet/visible-tokens (assoc visible-tokens chain (or (constants/default-visible-tokens chain) #{})) {})))))) -(fx/defn update-prices - [{{:keys [network-status :wallet/all-tokens] - {:keys [address currency chaos-mode? :wallet/visible-tokens] - :or {currency :usd}} :multiaccount :as db} :db}] - (let [chain (ethereum/chain-keyword db) - mainnet? (= :mainnet chain) - assets (get visible-tokens chain #{}) - tokens (tokens-symbols assets all-tokens) - currency (get constants/currencies currency)] - (when (not= network-status :offline) - {:wallet/get-prices - {:from (if mainnet? - (conj tokens "ETH") - [(-> (tokens/native-currency chain) - (wallet.utils/exchange-symbol))]) - :to [(:code currency)] - :mainnet? mainnet? - :success-event ::update-prices-success - :error-event ::update-prices-fail - :chaos-mode? chaos-mode?} - - :db - (-> db - (clear-error-message :prices-update) - (assoc :prices-loading? true))}))) - (defn- set-checked [tokens-id token-id checked?] (let [tokens-id (or tokens-id #{})] (if checked? (conj tokens-id token-id) (disj tokens-id token-id)))) -(fx/defn on-update-prices-success - {:events [::update-prices-success]} - [{:keys [db]} prices] - {:db (assoc db - :prices prices - :prices-loading? false)}) - (fx/defn update-balance {:events [::update-balance-success]} [{:keys [db]} address balance] @@ -349,7 +286,7 @@ chain-visible-tokens) {}) (update-tokens-balances balances) - (update-prices)))) + (prices/update-prices)))) (fx/defn add-custom-token [{:keys [db] :as cofx} {:keys [symbol]}] diff --git a/src/status_im/wallet/custom_tokens/core.cljs b/src/status_im/wallet/custom_tokens/core.cljs index bd92cd0f35..e4c1e16793 100644 --- a/src/status_im/wallet/custom_tokens/core.cljs +++ b/src/status_im/wallet/custom_tokens/core.cljs @@ -10,7 +10,8 @@ [status-im.utils.money :as money] [status-im.wallet.core :as wallet] [status-im.ui.screens.navigation :as navigation] - [status-im.multiaccounts.update.core :as multiaccounts.update])) + [status-im.multiaccounts.update.core :as multiaccounts.update] + [status-im.wallet.prices :as prices])) (re-frame/reg-fx :wallet.custom-token/get-decimals @@ -180,7 +181,7 @@ :params [new-token] :on-success #()}]} (wallet/add-custom-token new-token) - (wallet/update-prices) + (prices/update-prices) (navigation/navigate-back)))) (fx/defn remove-custom-token diff --git a/src/status_im/wallet/prices.cljs b/src/status_im/wallet/prices.cljs new file mode 100644 index 0000000000..fcb3fe66db --- /dev/null +++ b/src/status_im/wallet/prices.cljs @@ -0,0 +1,73 @@ +(ns status-im.wallet.prices + (:require [re-frame.core :as re-frame] + [status-im.utils.fx :as fx] + [status-im.utils.prices :as prices] + [status-im.ethereum.core :as ethereum] + [status-im.ethereum.tokens :as tokens] + [status-im.wallet.utils :as wallet.utils] + [status-im.constants :as constants] + [clojure.set :as set] + [taoensso.timbre :as log])) + +(defn assoc-error-message [db error-type err] + (assoc-in db [:wallet :errors error-type] (or err :unknown-error))) + +(defn clear-error-message [db error-type] + (update-in db [:wallet :errors] dissoc error-type)) + +(defn tokens-symbols + [visible-token-symbols all-tokens] + (set/difference (set visible-token-symbols) + (set (map :symbol (tokens/nfts-for all-tokens))))) + +(re-frame/reg-fx + :wallet/get-prices + (fn [{:keys [from to mainnet? success-event error-event chaos-mode?]}] + (prices/get-prices from + to + mainnet? + #(re-frame/dispatch [success-event %]) + #(re-frame/dispatch [error-event %]) + chaos-mode?))) + +(fx/defn on-update-prices-success + {:events [::update-prices-success]} + [{:keys [db]} prices] + {:db (assoc db + :prices prices + :prices-loading? false)}) + +(fx/defn on-update-prices-fail + {:events [::update-prices-fail]} + [{:keys [db]} err] + (log/debug "Unable to get prices: " err) + {:db (-> db + (assoc-error-message :prices-update :error-unable-to-get-prices) + (assoc :prices-loading? false))}) + +(fx/defn update-prices + {:events [:wallet.ui/pull-to-refresh]} + [{{:keys [network-status :wallet/all-tokens] + {:keys [currency chaos-mode? :wallet/visible-tokens] + :or {currency :usd}} :multiaccount :as db} :db}] + (let [chain (ethereum/chain-keyword db) + mainnet? (= :mainnet chain) + assets (get visible-tokens chain #{}) + tokens (tokens-symbols assets all-tokens) + currency (get constants/currencies currency)] + (when (not= network-status :offline) + {:wallet/get-prices + {:from (if mainnet? + (conj tokens "ETH") + [(-> (tokens/native-currency chain) + (wallet.utils/exchange-symbol))]) + :to [(:code currency)] + :mainnet? mainnet? + :success-event ::update-prices-success + :error-event ::update-prices-fail + :chaos-mode? chaos-mode?} + + :db + (-> db + (clear-error-message :prices-update) + (assoc :prices-loading? true))}))) \ No newline at end of file diff --git a/test/appium/tests/atomic/transactions/test_daaps_transactions.py b/test/appium/tests/atomic/transactions/test_daaps_transactions.py index 03d133405c..ef0407aa2c 100644 --- a/test/appium/tests/atomic/transactions/test_daaps_transactions.py +++ b/test/appium/tests/atomic/transactions/test_daaps_transactions.py @@ -79,8 +79,6 @@ class TestTransactionDApp(SingleDeviceTestCase): @marks.testrail_id(5743) @marks.high - @marks.skip - # TODO: blocked by 10203 def test_send_two_transactions_in_batch_in_dapp(self): sender = transaction_senders['W'] sign_in_view = SignInView(self.driver)