[wallet] Finetuning RPC calls for new accounts

This commit is contained in:
Roman Volosovskyi 2021-03-24 17:32:37 +02:00
parent 46655dbd48
commit 460685212a
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
5 changed files with 60 additions and 16 deletions

View File

@ -54,7 +54,8 @@
status-im.bootnodes.core
status-im.browser.core
status-im.browser.permissions
status-im.chat.models.transport))
status-im.chat.models.transport
[status-im.navigation :as navigation]))
(re-frame/reg-fx
:dismiss-keyboard
@ -235,3 +236,11 @@
:params []
:on-success (fn [on-ramps]
(re-frame/dispatch [::crypto-loaded on-ramps]))}]})
(fx/defn open-buy-crypto-screen
{:events [:buy-crypto.ui/open-screen]}
[cofx]
(fx/merge
cofx
(navigation/navigate-to :buy-crypto nil)
(wallet/keep-watching-history)))

View File

@ -64,7 +64,7 @@
:color colors/white-transparent-70-persist}}
(ethereum/normalized-hex address)]]
[react/view {:position :absolute :top 12 :right 12}
[react/touchable-highlight {:on-press #(re-frame/dispatch [:show-popover {:view :share-account :address address}])}
[react/touchable-highlight {:on-press #(re-frame/dispatch [:wallet/share-popover address])}
[icons/icon :main-icons/share {:color colors/white-persist
:accessibility-label :share-wallet-address-icon}]]]
[react/view {:height button-group-height :background-color colors/black-transparent-20
@ -83,7 +83,7 @@
(i18n/label :t/receive)
:main-icons/receive
colors/white-persist
#(re-frame/dispatch [:show-popover {:view :share-account :address address}])]]]))
#(re-frame/dispatch [:wallet/share-popover address])]]]))
(defn render-collectible [{:keys [name icon amount] :as collectible}]
(let [items-number (money/to-fixed amount)]
@ -170,7 +170,7 @@
(i18n/label :t/receive)
:main-icons/receive
colors/blue-persist
#(re-frame/dispatch [:show-popover {:view :share-account :address address}])]])
#(re-frame/dispatch [:wallet/share-popover address])]])
(defn anim-listener [anim-y scroll-y]
(let [to-show (atom false)]

View File

@ -64,8 +64,7 @@
:icon :main-icons/share
:accessibility-label :share-account-button
:on-press #(hide-sheet-and-dispatch
[:show-popover {:view :share-account
:address (:address account)}])}]])
[:wallet/share-popover (:address account)])}]])
(defn add-account []
(let [keycard? @(re-frame/subscribe [:keycard-multiaccount?])]

View File

@ -15,7 +15,7 @@
(def learn-more-url "")
(defn on-buy-crypto-pressed []
(re-frame/dispatch [:navigate-to :buy-crypto]))
(re-frame/dispatch [:buy-crypto.ui/open-screen]))
(defn render-on-ramp [{:keys [name fees logo-url description] :as on-ramp}]
[react/touchable-highlight {:on-press #(re-frame/dispatch [:navigate-to :buy-crypto-website on-ramp])

View File

@ -27,7 +27,8 @@
[status-im.utils.datetime :as datetime]
status-im.wallet.recipient.core
[status-im.ui.screens.wallet.signing-phrase.views :as signing-phrase]
[status-im.async-storage.core :as async-storage]))
[status-im.async-storage.core :as async-storage]
[status-im.popover.core :as popover.core]))
(defn get-balance
[{:keys [address on-success on-error]}]
@ -590,7 +591,9 @@
(ethereum/current-network db))
ms-4-min
(and max-block (zero? max-block))
(and max-block
(zero? max-block)
(nil? (get db :wallet/keep-watching-until-ms)))
(log/info "[wallet] No transactions found")
:else
@ -780,15 +783,35 @@
(navigation/navigate-back)))
(fx/defn stop-fetching-on-empty-tx-history
[{:keys [db] :as cofx} transfers]
[{:keys [db now] :as cofx} transfers]
(let [non-empty-history? (get db :wallet/non-empty-tx-history?)
custom-node? (ethereum/custom-rpc-node?
(ethereum/current-network db))]
(if (and (not non-empty-history?)
(empty? transfers)
(not custom-node?))
(clear-timeouts cofx)
{:db (assoc db :wallet/non-empty-tx-history? true)})))
(ethereum/current-network db))
until-ms (get db :wallet/keep-watching-until-ms)]
(when-not (and until-ms (> until-ms now))
(fx/merge
cofx
{:db (dissoc db :wallet/keep-watching-until-ms)}
(if (and (not non-empty-history?)
(empty? transfers)
(not custom-node?))
(clear-timeouts)
(fn [{:keys [db]}]
{:db (assoc db :wallet/non-empty-tx-history? true)}))))))
(fx/defn keep-watching-history
{:events [:wallet/keep-watching]}
[{:keys [db now] :as cofx}]
(let [non-empty-history? (get db :wallet/non-empty-tx-history?)
restart? (and (not (get db :wallet/non-empty-tx-history?))
(not (get db :wallet-service/restart-timeout)))]
(fx/merge
cofx
(when-not non-empty-history?
{:db (assoc db :wallet/keep-watching-until-ms
(+ now (datetime/minutes 30)))})
(when restart?
(restart-wallet-service {:force-start? true})))))
(re-frame/reg-fx
::set-inital-range
@ -826,3 +849,16 @@
(get-in db [:wallet :accounts address :max-block] 0)
transfers)]
(set-max-block cofx address max-block)))
(fx/defn share
{:events [:wallet/share-popover]}
[{:keys [db] :as cofx} address]
(let [non-empty-history? (get db :wallet/non-empty-tx-history?)
restart? (and (not (get db :wallet/non-empty-tx-history?))
(not (get db :wallet-service/restart-timeout)))]
(fx/merge
cofx
(popover.core/show-popover
{:view :share-account
:address address})
(keep-watching-history))))