From 460685212a485e5698933c2c0411ff6253cb1f42 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 24 Mar 2021 17:32:37 +0200 Subject: [PATCH] [wallet] Finetuning RPC calls for new accounts --- src/status_im/events.cljs | 11 +++- .../ui/screens/wallet/account/views.cljs | 6 +-- .../ui/screens/wallet/accounts/sheets.cljs | 3 +- .../ui/screens/wallet/buy_crypto/views.cljs | 2 +- src/status_im/wallet/core.cljs | 54 +++++++++++++++---- 5 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 3b0c3e5e37..7fe0a3b941 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -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))) diff --git a/src/status_im/ui/screens/wallet/account/views.cljs b/src/status_im/ui/screens/wallet/account/views.cljs index d9e59262aa..6a6de85fcf 100644 --- a/src/status_im/ui/screens/wallet/account/views.cljs +++ b/src/status_im/ui/screens/wallet/account/views.cljs @@ -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)] diff --git a/src/status_im/ui/screens/wallet/accounts/sheets.cljs b/src/status_im/ui/screens/wallet/accounts/sheets.cljs index ccd1bc69c0..80b809e7eb 100644 --- a/src/status_im/ui/screens/wallet/accounts/sheets.cljs +++ b/src/status_im/ui/screens/wallet/accounts/sheets.cljs @@ -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?])] diff --git a/src/status_im/ui/screens/wallet/buy_crypto/views.cljs b/src/status_im/ui/screens/wallet/buy_crypto/views.cljs index f1db2d1a1b..b1780691a1 100644 --- a/src/status_im/ui/screens/wallet/buy_crypto/views.cljs +++ b/src/status_im/ui/screens/wallet/buy_crypto/views.cljs @@ -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]) diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index 93acf2597a..462d5409ec 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -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))))