[wallet] Optimized watching for tx confirmation

Update e2e
This commit is contained in:
Roman Volosovskyi 2021-03-22 16:27:46 +02:00
parent 0c55f1208b
commit a364ce1906
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
5 changed files with 24 additions and 59 deletions

View File

@ -148,6 +148,7 @@
"wallet_getFavourites" {}
"wallet_deleteCustomToken" {}
"wallet_getCryptoOnRamps" {}
"wallet_watchTransaction" {}
"browsers_getBrowsers" {}
"browsers_addBrowser" {}
"browsers_deleteBrowser" {}

View File

@ -230,12 +230,6 @@
(seq transfers)
(concat (mapv add-transfer transfers))
(seq transfers)
(concat
(mapv (fn [{:keys [hash]}]
(wallet/stop-watching-tx hash))
transfers))
(and max-known-block
(some #(> (:block %) max-known-block) transfers))
(conj (wallet/update-balances

View File

@ -643,21 +643,18 @@
[{:keys [db] :as cofx}
{:keys [force-start? watch-new-blocks? ignore-syncing-settings? on-recent-history-fetching]}]
(when (or force-start? (:multiaccount db))
(let [watching-txs? (get db :wallet/watch-txs)
waiting? (get db :wallet/waiting-for-recent-history?)
(let [waiting? (get db :wallet/waiting-for-recent-history?)
syncing-allowed? (mobile-network-utils/syncing-allowed? cofx)]
(log/info "restart-wallet-service"
"force-start?" force-start?
"watching-txs?" watching-txs?
"syncing-allowed?" syncing-allowed?
"watch-new-blocks?" watch-new-blocks?)
(if (and (or syncing-allowed?
ignore-syncing-settings?)
(or
waiting?
force-start?
watching-txs?))
(start-wallet cofx (boolean (or watch-new-blocks? watching-txs?)) on-recent-history-fetching)
force-start?))
(start-wallet cofx (boolean watch-new-blocks?) on-recent-history-fetching)
(stop-wallet cofx)))))
(def background-cooldown-time (datetime/minutes 3))
@ -686,10 +683,8 @@
{:events [:wallet.ui/pull-to-refresh-history]}
[{:keys [db now] :as cofx}]
(let [last-pull (get db :wallet/last-pull-time)
watching? (get db :wallet/watch-txs)
fetching-history? (get db :wallet/recent-history-fetching-started?)]
(when (and (not watching?)
(not fetching-history?)
(when (and (not fetching-history?)
(or (not last-pull)
(> (- now last-pull) pull-to-refresh-cooldown-period)))
(fx/merge
@ -700,50 +695,27 @@
{:force-start? true
:ignore-syncing-settings? true})))))
(re-frame/reg-fx
::start-watching
(fn [hash]
(log/info "[wallet] watch transaction" hash)
(json-rpc/call
{:method "wallet_watchTransaction"
:params [hash]
:on-success #(re-frame.core/dispatch [::restart])
:on-error #(log/info "[wallet] watch transaction error" % "hash" hash)})))
(fx/defn watch-tx
{:events [:watch-tx]}
[{:keys [db] :as cofx} tx-id]
(let [txs (get db :wallet/watch-txs)
old-timeout (get db :wallet-service/restart-timeout)
timeout (utils.utils/set-timeout
(fn []
(re-frame.core/dispatch [::stop-watching-txs]))
(get-watching-interval db))]
(fx/merge
{:db (-> db
(update :wallet/watch-txs (fnil conj #{}) tx-id)
(assoc :wallet/watch-txs-timeout timeout))
::utils.utils/clear-timeouts
[old-timeout]}
(restart-wallet-service {:force-start? true
:watch-new-blocks? true}))))
(fx/defn stop-watching-txs
{:events [::stop-watching-txs]}
[{:keys [db] :as cofx}]
(fx/merge
{:db (dissoc db
:wallet/watch-txs
:wallet/watch-txs-timeout)}
(restart-wallet-service-default)))
(fx/defn stop-watching-tx
[{:keys [db] :as cofx} tx]
(let [txs (get db :wallet/watch-txs)
new-txs ((fnil disj #{}) txs tx)]
(when (get txs tx)
(if (empty? new-txs)
(stop-watching-txs cofx)
{:db (assoc db :wallet/watch-txs new-txs)}))))
{::start-watching tx-id})
(fx/defn clear-timeouts
[{:keys [db]}]
(log/info "[wallet] clear-timeouts")
(let [watch-timeout-id (get db :wallet/watch-txs-timeout)
restart-timeout-id (get db :wallet-service/restart-timeout)]
{:db (dissoc db :wallet/watch-txs-timeout
:wallet-service/restart-timeout)
::utils.utils/clear-timeouts [watch-timeout-id restart-timeout-id]}))
(let [restart-timeout-id (get db :wallet-service/restart-timeout)]
{:db (dissoc db :wallet-service/restart-timeout)
::utils.utils/clear-timeouts [restart-timeout-id]}))
(fx/defn get-buy-crypto-preference
{:events [::get-buy-crypto]}
@ -806,14 +778,13 @@
(when on-close
{:dispatch on-close})
(navigation/navigate-back)))
(fx/defn stop-fetching-on-empty-tx-history
[{:keys [db] :as cofx} transfers]
(let [non-empty-history? (get db :wallet/non-empty-tx-history?)
watching-outgoing-tx? (get db :wallet/watch-txs-timeout)
custom-node? (ethereum/custom-rpc-node?
(ethereum/current-network db))]
(if (and (not non-empty-history?)
(not watching-outgoing-tx?)
(empty? transfers)
(not custom-node?))
(clear-timeouts cofx)

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "patch/on_ramp",
"commit-sha1": "fc56ce65d05a35447384655846d1930680f904af",
"src-sha256": "0941p2k5ks61kakbsh1mn96hygsnbpll58dlmscjxyzam50z6sf8"
"version": "v0.74.1",
"commit-sha1": "5a76e93063e3b9ef2ded83a5f545f7149401e8f0",
"src-sha256": "0581048fvqg0fxv03pm9a0drfiq32slxliwamnch3052avpdkycj"
}

View File

@ -149,11 +149,10 @@ class TestCommandsMultipleDevices(MultipleDeviceTestCase):
send_message = chat_2_sender_message.sign_and_send.click()
send_message.next_button.click()
send_message.sign_transaction(default_gas_price=False)
chat_2_sender_message.transaction_status.wait_for_element_text(chat_2_sender_message.pending)
home_2.just_fyi('Check that transaction message is updated with new status after offline')
chat_2.toggle_airplane_mode()
self.network_api.wait_for_confirmation_of_transaction(sender['address'], amount, confirmations=15, token=True)
self.network_api.wait_for_confirmation_of_transaction(sender['address'], amount, confirmations=12, token=True)
chat_2.toggle_airplane_mode()
[message.transaction_status.wait_for_element_text(message.confirmed, wait_time=60) for message in
(chat_2_sender_message, chat_1_request_message)]