do not show zeros for token balances, and fetch all tokens only when creating new account

This commit is contained in:
andrey 2020-10-05 12:11:57 +02:00
parent 85991d2272
commit e602f0493d
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
14 changed files with 56 additions and 41 deletions

View File

@ -228,7 +228,8 @@
(conj acc address) (conj acc address)
acc)) acc))
#{} #{}
transfers)))) transfers))
nil))
(< (count transfers) limit) (< (count transfers) limit)
(conj (tx-history-end-reached checksum)))] (conj (tx-history-end-reached checksum)))]

View File

@ -67,7 +67,8 @@
status-im.ui.screens.profile.events status-im.ui.screens.profile.events
status-im.chat.models.images status-im.chat.models.images
status-im.ui.screens.privacy-and-security-settings.events 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 ;; init module
(handlers/register-handler-fx (handlers/register-handler-fx
@ -1256,4 +1257,5 @@
;; messages ;; messages
:chat (chat.loading/load-messages %) :chat (chat.loading/load-messages %)
:multiaccounts (keycard/multiaccounts-screen-did-load %) :multiaccounts (keycard/multiaccounts-screen-did-load %)
(:wallet-stack :wallet) (wallet.events/wallet-will-focus %)
nil)))) nil))))

View File

@ -148,7 +148,8 @@
whisper-private-key whisper-private-key
encryption-public-key encryption-public-key
instance-uid instance-uid
key-uid]} multiaccount key-uid
recovered]} multiaccount
{:keys [pairing paired-on]} secrets {:keys [pairing paired-on]} secrets
{:keys [name photo-path]} {:keys [name photo-path]}
(if (nil? name) (if (nil? name)
@ -167,7 +168,8 @@
(assoc-in [:keycard :setup-step] nil) (assoc-in [:keycard :setup-step] nil)
(dissoc :intro-wizard))} (dissoc :intro-wizard))}
(multiaccounts.create/on-multiaccount-created (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 {:public-key wallet-root-public-key
:address (eip55/address->checksum wallet-root-address)} :address (eip55/address->checksum wallet-root-address)}
constants/path-whisper-keyword constants/path-whisper-keyword
@ -268,6 +270,7 @@
{:db (update-in db [:keycard :multiaccount] {:db (update-in db [:keycard :multiaccount]
(fn [multiacc] (fn [multiacc]
(assoc multiacc (assoc multiacc
:recovered true
:name whisper-name :name whisper-name
:photo-path photo-path)))} :photo-path photo-path)))}
(create-keycard-multiaccount))) (create-keycard-multiaccount)))

View File

@ -218,7 +218,7 @@
(fx/defn on-multiaccount-created (fx/defn on-multiaccount-created
[{:keys [signing-phrase random-guid-generator db] :as cofx} [{:keys [signing-phrase random-guid-generator db] :as cofx}
{:keys [address chat-key keycard-instance-uid key-uid {: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} :as multiaccount}
password password
{:keys [save-mnemonic? login?] :or {login? true save-mnemonic? false}}] {:keys [save-mnemonic? login?] :or {login? true save-mnemonic? false}}]
@ -252,7 +252,8 @@
:latest-derived-path 0 :latest-derived-path 0
:signing-phrase signing-phrase :signing-phrase signing-phrase
:send-push-notifications? true :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) constants/default-multiaccount)
;; The address from which we derive any chat ;; The address from which we derive any chat
;; account/encryption keys ;; account/encryption keys

View File

@ -55,14 +55,14 @@
(fx/defn initialize-wallet (fx/defn initialize-wallet
{:events [::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 (fx/merge
cofx cofx
{:db (assoc db :multiaccount/accounts {:db (assoc db :multiaccount/accounts
(rpc->accounts accounts))} (rpc->accounts accounts))}
(wallet/initialize-tokens custom-tokens) (wallet/initialize-tokens custom-tokens)
(wallet/initialize-favourites favourites) (wallet/initialize-favourites favourites)
(wallet/update-balances nil) (wallet/update-balances nil new-account?)
(prices/update-prices))) (prices/update-prices)))
(fx/defn login (fx/defn login
@ -264,6 +264,7 @@
;;so here we set it at 1 already so that it passes the check once it has ;;so here we set it at 1 already so that it passes the check once it has
;;been initialized ;;been initialized
:filters/initialized 1)) :filters/initialized 1))
:dispatch-later [{:ms 2000 :dispatch [::initialize-wallet accounts nil nil (:recovered multiaccount)]}]
:filters/load-filters [[]]} :filters/load-filters [[]]}
(finish-keycard-setup) (finish-keycard-setup)
(when first-account? (when first-account?
@ -273,8 +274,7 @@
:mailserver-topics {} :mailserver-topics {}
:default-mailserver true}) :default-mailserver true})
(multiaccounts/switch-preview-privacy-mode-flag) (multiaccounts/switch-preview-privacy-mode-flag)
(logging/set-log-level (:log-level multiaccount)) (logging/set-log-level (:log-level multiaccount)))))
(initialize-wallet accounts nil nil))))
(defn- keycard-setup? [cofx] (defn- keycard-setup? [cofx]
(boolean (get-in cofx [:db :keycard :flow]))) (boolean (get-in cofx [:db :keycard :flow])))

View File

@ -13,7 +13,7 @@
{:db (assoc db :network-status (if is-connected? :online :offline))} {:db (assoc db :network-status (if is-connected? :online :offline))}
(when is-connected? (when is-connected?
(if-not (= (count (get-in db [:wallet :accounts])) (count (get db :multiaccount/accounts))) (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 (fx/defn change-network-type
[{:keys [db] :as cofx} old-network-type network-type expensive?] [{:keys [db] :as cofx} old-network-type network-type expensive?]

View File

@ -1277,9 +1277,9 @@
(defn get-asset-amount [balances sym] (defn get-asset-amount [balances sym]
(reduce #(if-let [^js bl (get %2 sym)] (reduce #(if-let [^js bl (get %2 sym)]
(.plus ^js %1 bl) (.plus ^js (or ^js %1 ^js (money/bignumber 0)) bl)
%1) %1)
^js (money/bignumber 0) nil
balances)) balances))
(re-frame/reg-sub (re-frame/reg-sub

View File

@ -11,7 +11,6 @@
[status-im.ui.screens.routing.intro-login-stack :as intro-login-stack] [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.chat-stack :as chat-stack]
[status-im.ui.screens.routing.wallet-stack :as wallet-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.views :as group-chat]
[status-im.ui.screens.group.events :as group.events] [status-im.ui.screens.group.events :as group.events]
[status-im.ui.screens.routing.profile-stack :as profile-stack] [status-im.ui.screens.routing.profile-stack :as profile-stack]
@ -43,7 +42,6 @@
:insets {:top false} :insets {:top false}
:component browser-stack/browser-stack} :component browser-stack/browser-stack}
{:name :wallet-stack {:name :wallet-stack
:on-focus [::wallet.events/wallet-stack]
:insets {:top false} :insets {:top false}
:component wallet-stack/wallet-stack} :component wallet-stack/wallet-stack}
{:name :profile-stack {:name :profile-stack

View File

@ -18,6 +18,13 @@
:accessibility-label :wallet-manage-assets :accessibility-label :wallet-manage-assets
:on-press #(hide-sheet-and-dispatch :on-press #(hide-sheet-and-dispatch
[:navigate-to :wallet-settings-assets])}] [: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 [quo/list-item
{:theme :accent {:theme :accent
:title (i18n/label :t/set-currency) :title (i18n/label :t/set-currency)

View File

@ -74,12 +74,14 @@
[quo/list-item [quo/list-item
(merge {:title [quo/text {:weight :medium} (merge {:title [quo/text {:weight :medium}
[quo/text {:weight :inherit} [quo/text {:weight :inherit}
(str (wallet.utils/format-amount amount decimals) (str (if amount
(wallet.utils/format-amount amount decimals)
"...")
" ")] " ")]
[quo/text {:color :secondary [quo/text {:color :secondary
:weight :inherit} :weight :inherit}
(wallet.utils/display-symbol token)]] (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") :accessibility-label (str (:symbol token) "-asset-value")
:icon (if icon :icon (if icon
[list/item-image icon] [list/item-image icon]

View File

@ -1,17 +1,18 @@
(ns status-im.ui.screens.wallet.events (ns status-im.ui.screens.wallet.events
(:require [status-im.ui.screens.wallet.signing-phrase.views :as signing-phrase] (: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 (fx/defn wallet-will-focus
::wallet-stack {:events [::wallet-stack]}
(fn [{:keys [db]}] [{:keys [db]}]
(let [wallet-set-up-passed? (get-in db [:multiaccount :wallet-set-up-passed?]) (let [wallet-set-up-passed? (get-in db [:multiaccount :wallet-set-up-passed?])
sign-phrase-showed? (get db :wallet/sign-phrase-showed?)] sign-phrase-showed? (get db :wallet/sign-phrase-showed?)]
{:dispatch [:wallet.ui/pull-to-refresh] ;TODO temporary simple fix for v1 {:dispatch [:wallet.ui/pull-to-refresh] ;TODO temporary simple fix for v1
:db (if (or wallet-set-up-passed? sign-phrase-showed?) :db (if (or wallet-set-up-passed? sign-phrase-showed?)
db db
(assoc db :popover/popover {:view [signing-phrase/signing-phrase]} (assoc db :popover/popover {:view [signing-phrase/signing-phrase]}
:wallet/sign-phrase-showed? true))}))) :wallet/sign-phrase-showed? true))}))
(handlers/register-handler-fx (handlers/register-handler-fx
::wallet-add-custom-token ::wallet-add-custom-token

View File

@ -201,7 +201,7 @@
(fx/merge cofx (fx/merge cofx
{:db (update-in db [:add-account :account] merge account)} {:db (update-in db [:add-account :account] merge account)}
(save-new-account) (save-new-account)
(wallet/update-balances nil) (wallet/update-balances nil true)
(prices/update-prices) (prices/update-prices)
(navigation/navigate-back))))) (navigation/navigate-back)))))

View File

@ -218,15 +218,14 @@
favourites))}) favourites))})
(fx/defn update-balances (fx/defn update-balances
{:events [:wallet/update-balances]}
[{{:keys [network-status :wallet/all-tokens [{{:keys [network-status :wallet/all-tokens
multiaccount :multiaccount/accounts] :as db} :db multiaccount :multiaccount/accounts] :as db} :db
:as cofx} addresses] :as cofx} addresses init?]
(let [addresses (or addresses (map (comp string/lower-case :address) accounts)) (let [addresses (or addresses (map (comp string/lower-case :address) accounts))
{:keys [:wallet/visible-tokens]} multiaccount {:keys [:wallet/visible-tokens]} multiaccount
chain (ethereum/chain-keyword db) chain (ethereum/chain-keyword db)
assets (get visible-tokens chain) assets (get visible-tokens chain)
init? (or (empty? assets)
(= assets (constants/default-visible-tokens chain)))
tokens (->> (vals all-tokens) tokens (->> (vals all-tokens)
(remove #(or (:hidden? %) (remove #(or (:hidden? %)
;;if not init remove not visible tokens ;;if not init remove not visible tokens
@ -267,12 +266,14 @@
[{{:keys [multiaccount] :as db} :db :as cofx} symbol checked?] [{{:keys [multiaccount] :as db} :db :as cofx} symbol checked?]
(let [chain (ethereum/chain-keyword db) (let [chain (ethereum/chain-keyword db)
visible-tokens (get multiaccount :wallet/visible-tokens)] visible-tokens (get multiaccount :wallet/visible-tokens)]
(fx/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
cofx
:wallet/visible-tokens (update visible-tokens :wallet/visible-tokens (update visible-tokens
chain chain
#(set-checked % symbol checked?)) #(set-checked % symbol checked?))
{}))) {})
#(when checked?
(update-balances % nil nil)))))
(fx/defn toggle-visible-token (fx/defn toggle-visible-token
[cofx symbol checked?] [cofx symbol checked?]
@ -315,9 +316,7 @@
(fx/defn add-custom-token (fx/defn add-custom-token
[cofx {:keys [symbol]}] [cofx {:keys [symbol]}]
(fx/merge cofx (update-toggle-in-settings cofx symbol true))
(update-toggle-in-settings symbol true)
(update-balances nil)))
(fx/defn remove-custom-token (fx/defn remove-custom-token
[cofx {:keys [symbol]}] [cofx {:keys [symbol]}]

View File

@ -1275,5 +1275,6 @@
"address-or-ens-name": "Address or ENS name", "address-or-ens-name": "Address or ENS name",
"name-optional": "Name (optional)", "name-optional": "Name (optional)",
"mute": "Mute", "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." "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."
} }