[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_getFavourites" {}
"wallet_deleteCustomToken" {} "wallet_deleteCustomToken" {}
"wallet_getCryptoOnRamps" {} "wallet_getCryptoOnRamps" {}
"wallet_watchTransaction" {}
"browsers_getBrowsers" {} "browsers_getBrowsers" {}
"browsers_addBrowser" {} "browsers_addBrowser" {}
"browsers_deleteBrowser" {} "browsers_deleteBrowser" {}

View File

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

View File

@ -643,21 +643,18 @@
[{:keys [db] :as cofx} [{:keys [db] :as cofx}
{:keys [force-start? watch-new-blocks? ignore-syncing-settings? on-recent-history-fetching]}] {:keys [force-start? watch-new-blocks? ignore-syncing-settings? on-recent-history-fetching]}]
(when (or force-start? (:multiaccount db)) (when (or force-start? (:multiaccount db))
(let [watching-txs? (get db :wallet/watch-txs) (let [waiting? (get db :wallet/waiting-for-recent-history?)
waiting? (get db :wallet/waiting-for-recent-history?)
syncing-allowed? (mobile-network-utils/syncing-allowed? cofx)] syncing-allowed? (mobile-network-utils/syncing-allowed? cofx)]
(log/info "restart-wallet-service" (log/info "restart-wallet-service"
"force-start?" force-start? "force-start?" force-start?
"watching-txs?" watching-txs?
"syncing-allowed?" syncing-allowed? "syncing-allowed?" syncing-allowed?
"watch-new-blocks?" watch-new-blocks?) "watch-new-blocks?" watch-new-blocks?)
(if (and (or syncing-allowed? (if (and (or syncing-allowed?
ignore-syncing-settings?) ignore-syncing-settings?)
(or (or
waiting? waiting?
force-start? force-start?))
watching-txs?)) (start-wallet cofx (boolean watch-new-blocks?) on-recent-history-fetching)
(start-wallet cofx (boolean (or watch-new-blocks? watching-txs?)) on-recent-history-fetching)
(stop-wallet cofx))))) (stop-wallet cofx)))))
(def background-cooldown-time (datetime/minutes 3)) (def background-cooldown-time (datetime/minutes 3))
@ -686,10 +683,8 @@
{:events [:wallet.ui/pull-to-refresh-history]} {:events [:wallet.ui/pull-to-refresh-history]}
[{:keys [db now] :as cofx}] [{:keys [db now] :as cofx}]
(let [last-pull (get db :wallet/last-pull-time) (let [last-pull (get db :wallet/last-pull-time)
watching? (get db :wallet/watch-txs)
fetching-history? (get db :wallet/recent-history-fetching-started?)] fetching-history? (get db :wallet/recent-history-fetching-started?)]
(when (and (not watching?) (when (and (not fetching-history?)
(not fetching-history?)
(or (not last-pull) (or (not last-pull)
(> (- now last-pull) pull-to-refresh-cooldown-period))) (> (- now last-pull) pull-to-refresh-cooldown-period)))
(fx/merge (fx/merge
@ -700,50 +695,27 @@
{:force-start? true {:force-start? true
:ignore-syncing-settings? 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 (fx/defn watch-tx
{:events [:watch-tx]} {:events [:watch-tx]}
[{:keys [db] :as cofx} tx-id] [{:keys [db] :as cofx} tx-id]
(let [txs (get db :wallet/watch-txs) {::start-watching tx-id})
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)}))))
(fx/defn clear-timeouts (fx/defn clear-timeouts
[{:keys [db]}] [{:keys [db]}]
(log/info "[wallet] clear-timeouts") (log/info "[wallet] clear-timeouts")
(let [watch-timeout-id (get db :wallet/watch-txs-timeout) (let [restart-timeout-id (get db :wallet-service/restart-timeout)]
restart-timeout-id (get db :wallet-service/restart-timeout)] {:db (dissoc db :wallet-service/restart-timeout)
{:db (dissoc db :wallet/watch-txs-timeout ::utils.utils/clear-timeouts [restart-timeout-id]}))
:wallet-service/restart-timeout)
::utils.utils/clear-timeouts [watch-timeout-id restart-timeout-id]}))
(fx/defn get-buy-crypto-preference (fx/defn get-buy-crypto-preference
{:events [::get-buy-crypto]} {:events [::get-buy-crypto]}
@ -806,14 +778,13 @@
(when on-close (when on-close
{:dispatch on-close}) {:dispatch on-close})
(navigation/navigate-back))) (navigation/navigate-back)))
(fx/defn stop-fetching-on-empty-tx-history (fx/defn stop-fetching-on-empty-tx-history
[{:keys [db] :as cofx} transfers] [{:keys [db] :as cofx} transfers]
(let [non-empty-history? (get db :wallet/non-empty-tx-history?) (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? custom-node? (ethereum/custom-rpc-node?
(ethereum/current-network db))] (ethereum/current-network db))]
(if (and (not non-empty-history?) (if (and (not non-empty-history?)
(not watching-outgoing-tx?)
(empty? transfers) (empty? transfers)
(not custom-node?)) (not custom-node?))
(clear-timeouts cofx) (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", "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "patch/on_ramp", "version": "v0.74.1",
"commit-sha1": "fc56ce65d05a35447384655846d1930680f904af", "commit-sha1": "5a76e93063e3b9ef2ded83a5f545f7149401e8f0",
"src-sha256": "0941p2k5ks61kakbsh1mn96hygsnbpll58dlmscjxyzam50z6sf8" "src-sha256": "0581048fvqg0fxv03pm9a0drfiq32slxliwamnch3052avpdkycj"
} }

View File

@ -149,11 +149,10 @@ class TestCommandsMultipleDevices(MultipleDeviceTestCase):
send_message = chat_2_sender_message.sign_and_send.click() send_message = chat_2_sender_message.sign_and_send.click()
send_message.next_button.click() send_message.next_button.click()
send_message.sign_transaction(default_gas_price=False) 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') home_2.just_fyi('Check that transaction message is updated with new status after offline')
chat_2.toggle_airplane_mode() 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() chat_2.toggle_airplane_mode()
[message.transaction_status.wait_for_element_text(message.confirmed, wait_time=60) for message in [message.transaction_status.wait_for_element_text(message.confirmed, wait_time=60) for message in
(chat_2_sender_message, chat_1_request_message)] (chat_2_sender_message, chat_1_request_message)]