From e602f0493dab39fac1e94d27df7870c3de0fba3f Mon Sep 17 00:00:00 2001 From: andrey Date: Mon, 5 Oct 2020 12:11:57 +0200 Subject: [PATCH] do not show zeros for token balances, and fetch all tokens only when creating new account --- src/status_im/ethereum/transactions/core.cljs | 3 ++- src/status_im/events.cljs | 4 +++- src/status_im/keycard/recovery.cljs | 7 ++++-- src/status_im/multiaccounts/create/core.cljs | 5 ++-- src/status_im/multiaccounts/login/core.cljs | 8 +++---- src/status_im/network/net_info.cljs | 2 +- src/status_im/subs.cljs | 4 ++-- src/status_im/ui/screens/routing/main.cljs | 2 -- .../ui/screens/wallet/accounts/sheets.cljs | 7 ++++++ .../ui/screens/wallet/accounts/views.cljs | 6 +++-- src/status_im/ui/screens/wallet/events.cljs | 23 ++++++++++--------- src/status_im/wallet/accounts/core.cljs | 2 +- src/status_im/wallet/core.cljs | 23 +++++++++---------- translations/en.json | 1 + 14 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/status_im/ethereum/transactions/core.cljs b/src/status_im/ethereum/transactions/core.cljs index 42740389cd..6f414a169b 100644 --- a/src/status_im/ethereum/transactions/core.cljs +++ b/src/status_im/ethereum/transactions/core.cljs @@ -228,7 +228,8 @@ (conj acc address) acc)) #{} - transfers)))) + transfers)) + nil)) (< (count transfers) limit) (conj (tx-history-end-reached checksum)))] diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 281f243584..7406fd2264 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -67,7 +67,8 @@ status-im.ui.screens.profile.events status-im.chat.models.images status-im.ui.screens.privacy-and-security-settings.events - [status-im.data-store.invitations :as data-store.invitations])) + [status-im.data-store.invitations :as data-store.invitations] + [status-im.ui.screens.wallet.events :as wallet.events])) ;; init module (handlers/register-handler-fx @@ -1256,4 +1257,5 @@ ;; messages :chat (chat.loading/load-messages %) :multiaccounts (keycard/multiaccounts-screen-did-load %) + (:wallet-stack :wallet) (wallet.events/wallet-will-focus %) nil)))) diff --git a/src/status_im/keycard/recovery.cljs b/src/status_im/keycard/recovery.cljs index a3b40b40fd..ba5ce299da 100644 --- a/src/status_im/keycard/recovery.cljs +++ b/src/status_im/keycard/recovery.cljs @@ -148,7 +148,8 @@ whisper-private-key encryption-public-key instance-uid - key-uid]} multiaccount + key-uid + recovered]} multiaccount {:keys [pairing paired-on]} secrets {:keys [name photo-path]} (if (nil? name) @@ -167,7 +168,8 @@ (assoc-in [:keycard :setup-step] nil) (dissoc :intro-wizard))} (multiaccounts.create/on-multiaccount-created - {:derived {constants/path-wallet-root-keyword + {:recovered (or recovered (get-in db [:intro-wizard :recovering?])) + :derived {constants/path-wallet-root-keyword {:public-key wallet-root-public-key :address (eip55/address->checksum wallet-root-address)} constants/path-whisper-keyword @@ -268,6 +270,7 @@ {:db (update-in db [:keycard :multiaccount] (fn [multiacc] (assoc multiacc + :recovered true :name whisper-name :photo-path photo-path)))} (create-keycard-multiaccount))) diff --git a/src/status_im/multiaccounts/create/core.cljs b/src/status_im/multiaccounts/create/core.cljs index f319f10a3a..3cf937a666 100644 --- a/src/status_im/multiaccounts/create/core.cljs +++ b/src/status_im/multiaccounts/create/core.cljs @@ -218,7 +218,7 @@ (fx/defn on-multiaccount-created [{:keys [signing-phrase random-guid-generator db] :as cofx} {:keys [address chat-key keycard-instance-uid key-uid - keycard-pairing keycard-paired-on mnemonic public-key] + keycard-pairing keycard-paired-on mnemonic recovered] :as multiaccount} password {:keys [save-mnemonic? login?] :or {login? true save-mnemonic? false}}] @@ -252,7 +252,8 @@ :latest-derived-path 0 :signing-phrase signing-phrase :send-push-notifications? true - :installation-id (random-guid-generator)} + :installation-id (random-guid-generator) + :recovered (or recovered (get-in db [:intro-wizard :recovering?]))} constants/default-multiaccount) ;; The address from which we derive any chat ;; account/encryption keys diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index bd5a8eda0f..a81d2ae609 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -55,14 +55,14 @@ (fx/defn initialize-wallet {:events [::initialize-wallet]} - [{:keys [db] :as cofx} accounts custom-tokens favourites] + [{:keys [db] :as cofx} accounts custom-tokens favourites new-account?] (fx/merge cofx {:db (assoc db :multiaccount/accounts (rpc->accounts accounts))} (wallet/initialize-tokens custom-tokens) (wallet/initialize-favourites favourites) - (wallet/update-balances nil) + (wallet/update-balances nil new-account?) (prices/update-prices))) (fx/defn login @@ -264,6 +264,7 @@ ;;so here we set it at 1 already so that it passes the check once it has ;;been initialized :filters/initialized 1)) + :dispatch-later [{:ms 2000 :dispatch [::initialize-wallet accounts nil nil (:recovered multiaccount)]}] :filters/load-filters [[]]} (finish-keycard-setup) (when first-account? @@ -273,8 +274,7 @@ :mailserver-topics {} :default-mailserver true}) (multiaccounts/switch-preview-privacy-mode-flag) - (logging/set-log-level (:log-level multiaccount)) - (initialize-wallet accounts nil nil)))) + (logging/set-log-level (:log-level multiaccount))))) (defn- keycard-setup? [cofx] (boolean (get-in cofx [:db :keycard :flow]))) diff --git a/src/status_im/network/net_info.cljs b/src/status_im/network/net_info.cljs index 1902ac112a..8edbf5f9cd 100644 --- a/src/status_im/network/net_info.cljs +++ b/src/status_im/network/net_info.cljs @@ -13,7 +13,7 @@ {:db (assoc db :network-status (if is-connected? :online :offline))} (when is-connected? (if-not (= (count (get-in db [:wallet :accounts])) (count (get db :multiaccount/accounts))) - (wallet/update-balances nil))))) + (wallet/update-balances nil nil))))) (fx/defn change-network-type [{:keys [db] :as cofx} old-network-type network-type expensive?] diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index ce6c5ea961..7efec67827 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -1277,9 +1277,9 @@ (defn get-asset-amount [balances sym] (reduce #(if-let [^js bl (get %2 sym)] - (.plus ^js %1 bl) + (.plus ^js (or ^js %1 ^js (money/bignumber 0)) bl) %1) - ^js (money/bignumber 0) + nil balances)) (re-frame/reg-sub diff --git a/src/status_im/ui/screens/routing/main.cljs b/src/status_im/ui/screens/routing/main.cljs index 15a1c3d829..92c2866fa0 100644 --- a/src/status_im/ui/screens/routing/main.cljs +++ b/src/status_im/ui/screens/routing/main.cljs @@ -11,7 +11,6 @@ [status-im.ui.screens.routing.intro-login-stack :as intro-login-stack] [status-im.ui.screens.routing.chat-stack :as chat-stack] [status-im.ui.screens.routing.wallet-stack :as wallet-stack] - [status-im.ui.screens.wallet.events :as wallet.events] [status-im.ui.screens.group.views :as group-chat] [status-im.ui.screens.group.events :as group.events] [status-im.ui.screens.routing.profile-stack :as profile-stack] @@ -43,7 +42,6 @@ :insets {:top false} :component browser-stack/browser-stack} {:name :wallet-stack - :on-focus [::wallet.events/wallet-stack] :insets {:top false} :component wallet-stack/wallet-stack} {:name :profile-stack diff --git a/src/status_im/ui/screens/wallet/accounts/sheets.cljs b/src/status_im/ui/screens/wallet/accounts/sheets.cljs index 0684098ddb..2bfd9ae2b0 100644 --- a/src/status_im/ui/screens/wallet/accounts/sheets.cljs +++ b/src/status_im/ui/screens/wallet/accounts/sheets.cljs @@ -18,6 +18,13 @@ :accessibility-label :wallet-manage-assets :on-press #(hide-sheet-and-dispatch [:navigate-to :wallet-settings-assets])}] + [quo/list-item + {:theme :accent + :title (i18n/label :t/scan-tokens) + :icon :main-icons/refresh + :accessibility-label :wallet-manage-assets + :on-press #(hide-sheet-and-dispatch + [:wallet/update-balances nil true])}] [quo/list-item {:theme :accent :title (i18n/label :t/set-currency) diff --git a/src/status_im/ui/screens/wallet/accounts/views.cljs b/src/status_im/ui/screens/wallet/accounts/views.cljs index 95cd1d4cd0..962b7b46c3 100644 --- a/src/status_im/ui/screens/wallet/accounts/views.cljs +++ b/src/status_im/ui/screens/wallet/accounts/views.cljs @@ -74,12 +74,14 @@ [quo/list-item (merge {:title [quo/text {:weight :medium} [quo/text {:weight :inherit} - (str (wallet.utils/format-amount amount decimals) + (str (if amount + (wallet.utils/format-amount amount decimals) + "...") " ")] [quo/text {:color :secondary :weight :inherit} (wallet.utils/display-symbol token)]] - :subtitle (str (if value value "0.00") " " currency) + :subtitle (str (if value value "...") " " currency) :accessibility-label (str (:symbol token) "-asset-value") :icon (if icon [list/item-image icon] diff --git a/src/status_im/ui/screens/wallet/events.cljs b/src/status_im/ui/screens/wallet/events.cljs index 04d7ccd16b..deba112b6a 100644 --- a/src/status_im/ui/screens/wallet/events.cljs +++ b/src/status_im/ui/screens/wallet/events.cljs @@ -1,17 +1,18 @@ (ns status-im.ui.screens.wallet.events (:require [status-im.ui.screens.wallet.signing-phrase.views :as signing-phrase] - [status-im.utils.handlers :as handlers])) + [status-im.utils.handlers :as handlers] + [status-im.utils.fx :as fx])) -(handlers/register-handler-fx - ::wallet-stack - (fn [{:keys [db]}] - (let [wallet-set-up-passed? (get-in db [:multiaccount :wallet-set-up-passed?]) - sign-phrase-showed? (get db :wallet/sign-phrase-showed?)] - {:dispatch [:wallet.ui/pull-to-refresh] ;TODO temporary simple fix for v1 - :db (if (or wallet-set-up-passed? sign-phrase-showed?) - db - (assoc db :popover/popover {:view [signing-phrase/signing-phrase]} - :wallet/sign-phrase-showed? true))}))) +(fx/defn wallet-will-focus + {:events [::wallet-stack]} + [{:keys [db]}] + (let [wallet-set-up-passed? (get-in db [:multiaccount :wallet-set-up-passed?]) + sign-phrase-showed? (get db :wallet/sign-phrase-showed?)] + {:dispatch [:wallet.ui/pull-to-refresh] ;TODO temporary simple fix for v1 + :db (if (or wallet-set-up-passed? sign-phrase-showed?) + db + (assoc db :popover/popover {:view [signing-phrase/signing-phrase]} + :wallet/sign-phrase-showed? true))})) (handlers/register-handler-fx ::wallet-add-custom-token diff --git a/src/status_im/wallet/accounts/core.cljs b/src/status_im/wallet/accounts/core.cljs index d93a2e1cfe..3307bfc880 100644 --- a/src/status_im/wallet/accounts/core.cljs +++ b/src/status_im/wallet/accounts/core.cljs @@ -201,7 +201,7 @@ (fx/merge cofx {:db (update-in db [:add-account :account] merge account)} (save-new-account) - (wallet/update-balances nil) + (wallet/update-balances nil true) (prices/update-prices) (navigation/navigate-back))))) diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index b1c0ea8ced..7466cb2505 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -218,15 +218,14 @@ favourites))}) (fx/defn update-balances + {:events [:wallet/update-balances]} [{{:keys [network-status :wallet/all-tokens multiaccount :multiaccount/accounts] :as db} :db - :as cofx} addresses] + :as cofx} addresses init?] (let [addresses (or addresses (map (comp string/lower-case :address) accounts)) {:keys [:wallet/visible-tokens]} multiaccount chain (ethereum/chain-keyword db) assets (get visible-tokens chain) - init? (or (empty? assets) - (= assets (constants/default-visible-tokens chain))) tokens (->> (vals all-tokens) (remove #(or (:hidden? %) ;;if not init remove not visible tokens @@ -267,12 +266,14 @@ [{{:keys [multiaccount] :as db} :db :as cofx} symbol checked?] (let [chain (ethereum/chain-keyword db) visible-tokens (get multiaccount :wallet/visible-tokens)] - (multiaccounts.update/multiaccount-update - cofx - :wallet/visible-tokens (update visible-tokens - chain - #(set-checked % symbol checked?)) - {}))) + (fx/merge cofx + (multiaccounts.update/multiaccount-update + :wallet/visible-tokens (update visible-tokens + chain + #(set-checked % symbol checked?)) + {}) + #(when checked? + (update-balances % nil nil))))) (fx/defn toggle-visible-token [cofx symbol checked?] @@ -315,9 +316,7 @@ (fx/defn add-custom-token [cofx {:keys [symbol]}] - (fx/merge cofx - (update-toggle-in-settings symbol true) - (update-balances nil))) + (update-toggle-in-settings cofx symbol true)) (fx/defn remove-custom-token [cofx {:keys [symbol]}] diff --git a/translations/en.json b/translations/en.json index d616329dc7..81de8e5961 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1275,5 +1275,6 @@ "address-or-ens-name": "Address or ENS name", "name-optional": "Name (optional)", "mute": "Mute", + "scan-tokens": "Scan tokens", "warning-sending-to-contract-descr": "The address you entered is a smart contract, sending funds to this address may result in loss of funds. To interact with a DApp, open the DApp in the Status DApp Browser." }