[#10203] Endless spinner when sending two TX in a batch in Dapp

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2020-04-16 15:54:33 +02:00 committed by Andrea Maria Piana
parent aebe68fa1a
commit cc70a7e8da
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
9 changed files with 92 additions and 85 deletions

View File

@ -1080,11 +1080,6 @@
;; wallet events ;; wallet events
(handlers/register-handler-fx
:wallet.ui/pull-to-refresh
(fn [cofx _]
(wallet/update-prices cofx)))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.transactions/add-filter :wallet.transactions/add-filter
(fn [{:keys [db]} [_ id]] (fn [{:keys [db]} [_ id]]

View File

@ -34,7 +34,8 @@
[status-im.popover.core :as popover] [status-im.popover.core :as popover]
[status-im.hardwallet.nfc :as nfc] [status-im.hardwallet.nfc :as nfc]
[status-im.multiaccounts.core :as multiaccounts] [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 rpc-endpoint "https://goerli.infura.io/v3/f315575765b14720b32382a61a89341a")
(def contract-address "0xfbf4c8e2B41fAfF8c616a0E49Fb4365a5355Ffaf") (def contract-address "0xfbf4c8e2B41fAfF8c616a0E49Fb4365a5355Ffaf")
@ -87,7 +88,7 @@
(rpc->accounts accounts))} (rpc->accounts accounts))}
(wallet/initialize-tokens custom-tokens) (wallet/initialize-tokens custom-tokens)
(wallet/update-balances nil) (wallet/update-balances nil)
(wallet/update-prices))) (prices/update-prices)))
(fx/defn login (fx/defn login
{:events [:multiaccounts.login.ui/password-input-submitted]} {:events [:multiaccounts.login.ui/password-input-submitted]}

View File

@ -22,7 +22,8 @@
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[taoensso.timbre :as log] [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 (re-frame/reg-fx
:signing/send-transaction-fx :signing/send-transaction-fx
@ -206,8 +207,8 @@
:signing/in-progress? true :signing/in-progress? true
:signing/queue (drop-last queue) :signing/queue (drop-last queue)
:signing/tx (prepare-tx updated-db tx)) :signing/tx (prepare-tx updated-db tx))
:dismiss-keyboard nil :dismiss-keyboard nil}
:dispatch [:wallet.ui/pull-to-refresh]} ;;TODO fix for v.1.2 (prices/update-prices)
#(when-not gas #(when-not gas
{:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true) {:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
:signing/update-estimated-gas {:obj tx-obj :signing/update-estimated-gas {:obj tx-obj

View File

@ -1,7 +1,7 @@
(ns status-im.ui.screens.currency-settings.models (ns status-im.ui.screens.currency-settings.models
(:require [status-im.multiaccounts.update.core :as multiaccounts.update] (:require [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.wallet.core :as wallet])) [status-im.wallet.prices :as prices]))
(defn get-currency [db] (defn get-currency [db]
(get-in db [:multiaccount :currency] :usd)) (get-in db [:multiaccount :currency] :usd))
@ -12,4 +12,4 @@
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:currency currency :currency currency
{}) {})
(wallet/update-prices))) (prices/update-prices)))

View File

@ -18,7 +18,8 @@
[status-im.utils.security :as security] [status-im.utils.security :as security]
[status-im.multiaccounts.recover.core :as recover] [status-im.multiaccounts.recover.core :as recover]
[status-im.ethereum.mnemonic :as mnemonic] [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 (fx/defn start-adding-new-account
{:events [:wallet.accounts/start-adding-new-account]} {:events [:wallet.accounts/start-adding-new-account]}
@ -194,7 +195,7 @@
{:db (update-in db [:add-account :account] merge account)} {:db (update-in db [:add-account :account] merge account)}
(save-new-account) (save-new-account)
(wallet/update-balances nil) (wallet/update-balances nil)
(wallet/update-prices) (prices/update-prices)
(navigation/navigate-back))))) (navigation/navigate-back)))))
(fx/defn add-watch-account (fx/defn add-watch-account

View File

@ -4,19 +4,16 @@
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.waku.core :as waku] [status-im.waku.core :as waku]
[status-im.chat.models.message :as chat.message]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.eip55 :as eip55] [status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.ethereum.tokens :as tokens] [status-im.ethereum.tokens :as tokens]
[status-im.i18n :as i18n] [status-im.i18n :as i18n]
[status-im.ui.screens.navigation :as navigation] [status-im.ui.screens.navigation :as navigation]
[status-im.wallet.utils :as wallet.utils]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.core :as utils.core] [status-im.utils.core :as utils.core]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.utils.prices :as prices]
[status-im.utils.utils :as utils.utils] [status-im.utils.utils :as utils.utils]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.wallet.db :as wallet.db] [status-im.wallet.db :as wallet.db]
@ -26,7 +23,8 @@
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.ethereum.stateofus :as stateofus] [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 (defn get-balance
[{:keys [address on-success on-error]}] [{:keys [address on-success on-error]}]
@ -46,29 +44,9 @@
:on-success #(re-frame/dispatch [::update-balance-success address %]) :on-success #(re-frame/dispatch [::update-balance-success address %])
:on-error #(re-frame/dispatch [::update-balance-fail %])})))) :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] (defn assoc-error-message [db error-type err]
(assoc-in db [:wallet :errors error-type] (or err :unknown-error))) (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 (fx/defn on-update-balance-fail
{:events [::update-balance-fail]} {:events [::update-balance-fail]}
[{:keys [db]} err] [{:keys [db]} err]
@ -196,14 +174,6 @@
:wallet/get-tokens-balances :wallet/get-tokens-balances
get-token-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] (defn rpc->token [tokens]
(reduce (fn [acc {:keys [address] :as token}] (reduce (fn [acc {:keys [address] :as token}]
(assoc acc (assoc acc
@ -248,52 +218,19 @@
:tokens tokens :tokens tokens
:assets assets :assets assets
:init? init?} :init? init?}
:db (clear-error-message db :balance-update)} :db (prices/clear-error-message db :balance-update)}
(when-not assets (when-not assets
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:wallet/visible-tokens (assoc visible-tokens chain (or (constants/default-visible-tokens chain) :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?] (defn- set-checked [tokens-id token-id checked?]
(let [tokens-id (or tokens-id #{})] (let [tokens-id (or tokens-id #{})]
(if checked? (if checked?
(conj tokens-id token-id) (conj tokens-id token-id)
(disj 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 (fx/defn update-balance
{:events [::update-balance-success]} {:events [::update-balance-success]}
[{:keys [db]} address balance] [{:keys [db]} address balance]
@ -349,7 +286,7 @@
chain-visible-tokens) chain-visible-tokens)
{}) {})
(update-tokens-balances balances) (update-tokens-balances balances)
(update-prices)))) (prices/update-prices))))
(fx/defn add-custom-token (fx/defn add-custom-token
[{:keys [db] :as cofx} {:keys [symbol]}] [{:keys [db] :as cofx} {:keys [symbol]}]

View File

@ -10,7 +10,8 @@
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
[status-im.ui.screens.navigation :as navigation] [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 (re-frame/reg-fx
:wallet.custom-token/get-decimals :wallet.custom-token/get-decimals
@ -180,7 +181,7 @@
:params [new-token] :params [new-token]
:on-success #()}]} :on-success #()}]}
(wallet/add-custom-token new-token) (wallet/add-custom-token new-token)
(wallet/update-prices) (prices/update-prices)
(navigation/navigate-back)))) (navigation/navigate-back))))
(fx/defn remove-custom-token (fx/defn remove-custom-token

View File

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

View File

@ -79,8 +79,6 @@ class TestTransactionDApp(SingleDeviceTestCase):
@marks.testrail_id(5743) @marks.testrail_id(5743)
@marks.high @marks.high
@marks.skip
# TODO: blocked by 10203
def test_send_two_transactions_in_batch_in_dapp(self): def test_send_two_transactions_in_batch_in_dapp(self):
sender = transaction_senders['W'] sender = transaction_senders['W']
sign_in_view = SignInView(self.driver) sign_in_view = SignInView(self.driver)