From ec2b95c3709d2f5c73b2000689777aaa2bb73421 Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Thu, 11 Jan 2024 20:44:20 +0400 Subject: [PATCH] Fix: Asset decimals on select asset screen (#18427) * fix: assets decimals --- .clj-kondo/rewrite-clj/rewrite-clj/config.edn | 5 ++ .clj-kondo/taoensso/encore/config.edn | 1 + .../taoensso/encore/taoensso/encore.clj | 16 +++++ .../list_items/token_network/style.cljs | 4 +- .../wallet/common/token_value/view.cljs | 59 +++++++++++-------- .../contexts/wallet/common/utils.cljs | 10 +++- .../contexts/wallet/send/events.cljs | 18 ++++-- .../wallet/send/input_amount/view.cljs | 4 +- .../wallet/send/select_asset/view.cljs | 20 ++++--- 9 files changed, 93 insertions(+), 44 deletions(-) create mode 100644 .clj-kondo/rewrite-clj/rewrite-clj/config.edn create mode 100644 .clj-kondo/taoensso/encore/config.edn create mode 100644 .clj-kondo/taoensso/encore/taoensso/encore.clj diff --git a/.clj-kondo/rewrite-clj/rewrite-clj/config.edn b/.clj-kondo/rewrite-clj/rewrite-clj/config.edn new file mode 100644 index 0000000000..19ecae96a0 --- /dev/null +++ b/.clj-kondo/rewrite-clj/rewrite-clj/config.edn @@ -0,0 +1,5 @@ +{:lint-as + {rewrite-clj.zip/subedit-> clojure.core/-> + rewrite-clj.zip/subedit->> clojure.core/->> + rewrite-clj.zip/edit-> clojure.core/-> + rewrite-clj.zip/edit->> clojure.core/->>}} diff --git a/.clj-kondo/taoensso/encore/config.edn b/.clj-kondo/taoensso/encore/config.edn new file mode 100644 index 0000000000..7b0ff3c2b7 --- /dev/null +++ b/.clj-kondo/taoensso/encore/config.edn @@ -0,0 +1 @@ +{:hooks {:analyze-call {taoensso.encore/defalias taoensso.encore/defalias}}} diff --git a/.clj-kondo/taoensso/encore/taoensso/encore.clj b/.clj-kondo/taoensso/encore/taoensso/encore.clj new file mode 100644 index 0000000000..7f6d30ac94 --- /dev/null +++ b/.clj-kondo/taoensso/encore/taoensso/encore.clj @@ -0,0 +1,16 @@ +(ns taoensso.encore + (:require + [clj-kondo.hooks-api :as hooks])) + +(defn defalias [{:keys [node]}] + (let [[sym-raw src-raw] (rest (:children node)) + src (if src-raw src-raw sym-raw) + sym (if src-raw + sym-raw + (symbol (name (hooks/sexpr src))))] + {:node (with-meta + (hooks/list-node + [(hooks/token-node 'def) + (hooks/token-node (hooks/sexpr sym)) + (hooks/token-node (hooks/sexpr src))]) + (meta src))})) diff --git a/src/quo/components/list_items/token_network/style.cljs b/src/quo/components/list_items/token_network/style.cljs index 0ce4ec51f6..efd651ec6f 100644 --- a/src/quo/components/list_items/token_network/style.cljs +++ b/src/quo/components/list_items/token_network/style.cljs @@ -27,7 +27,7 @@ (def info {:flex-direction :row :align-items :center - :width "70%"}) + :width "60%"}) (def token-info {:height 40 @@ -42,7 +42,7 @@ (def values-container {:align-items :flex-end - :max-width "30%"}) + :max-width "40%"}) (defn fiat-value [theme] diff --git a/src/status_im/contexts/wallet/common/token_value/view.cljs b/src/status_im/contexts/wallet/common/token_value/view.cljs index 98c2c0cb03..e93f2e4619 100644 --- a/src/status_im/contexts/wallet/common/token_value/view.cljs +++ b/src/status_im/contexts/wallet/common/token_value/view.cljs @@ -4,30 +4,39 @@ [utils.re-frame :as rf])) (defn token-value-drawer - [] - [:<> - [quo/action-drawer - [[{:icon :i/buy - :accessibility-label :buy - :label (i18n/label :t/buy) - :on-press #(js/alert "to be implemented") - :right-icon :i/external} - {:icon :i/send - :accessibility-label :send - :label (i18n/label :t/send)} - {:icon :i/receive - :accessibility-label :receive - :label (i18n/label :t/receive)} - {:icon :i/bridge - :accessibility-label :bridge - :label (i18n/label :t/bridge)} - {:icon :i/settings - :accessibility-label :settings - :label (i18n/label :t/manage-tokens) - :add-divider? true} - {:icon :i/hide - :accessibility-label :hide - :label (i18n/label :t/hide)}]]]]) + [token] + (let [token-data (first (rf/sub [:wallet/tokens-filtered (:token token)]))] + [:<> + [quo/action-drawer + [[{:icon :i/buy + :accessibility-label :buy + :label (i18n/label :t/buy) + :on-press #(js/alert "to be implemented") + :right-icon :i/external} + {:icon :i/send + :accessibility-label :send + :label (i18n/label :t/send) + :on-press (fn [] + (rf/dispatch [:hide-bottom-sheet]) + (rf/dispatch [:wallet/send-select-token-drawer {:token token-data}]) + (rf/dispatch [:open-modal :wallet-select-address]))} + {:icon :i/receive + :accessibility-label :receive + :label (i18n/label :t/receive) + :on-press #(js/alert "to be implemented")} + {:icon :i/bridge + :accessibility-label :bridge + :label (i18n/label :t/bridge) + :on-press #(js/alert "to be implemented")} + {:icon :i/settings + :accessibility-label :settings + :label (i18n/label :t/manage-tokens) + :on-press #(js/alert "to be implemented") + :add-divider? true} + {:icon :i/hide + :accessibility-label :hide + :label (i18n/label :t/hide) + :on-press #(js/alert "to be implemented")}]]]])) (defn view [item] @@ -36,5 +45,5 @@ {:on-long-press #(rf/dispatch [:show-bottom-sheet - {:content token-value-drawer + {:content (fn [] [token-value-drawer item]) :selected-item (fn [] [quo/token-value item])}])})]) diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index c7005537bf..901012b050 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -173,6 +173,12 @@ constants/optimism-chain-id :optimism constants/arbitrum-chain-id :arbitrum}) +(defn get-standard-fiat-format + [crypto-value currency-symbol fiat-value] + (if (string/includes? crypto-value "<") + "<$0.01" + (prettify-balance currency-symbol fiat-value))) + (defn calculate-token-value "This function returns token values in the props of token-value (quo) component" [{:keys [token color currency currency-symbol]}] @@ -184,9 +190,7 @@ constants/profile-default-currency])) {:keys [change-pct-24hour]} market-values crypto-value (get-standard-crypto-format token token-units) - fiat-value (if (string/includes? crypto-value "<") - "<$0.01" - (prettify-balance currency-symbol fiat-value))] + fiat-value (get-standard-fiat-format crypto-value currency-symbol fiat-value)] {:token (:symbol token) :token-name (:name token) :state :default diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index d0ae295967..bf739d7f4e 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -47,18 +47,24 @@ (update-in [:wallet :ui :send] dissoc :to-address)) :fx [[:navigate-to-within-stack [:wallet-select-asset stack-id]]]})) -(rf/reg-event-fx :wallet/select-send-address - (fn [{:keys [db]} [{:keys [address stack-id]}]] - {:db (-> db - (assoc-in [:wallet :ui :send :to-address] address) - (update-in [:wallet :ui :send] dissoc :send-account-address)) - :fx [[:navigate-to-within-stack [:wallet-select-asset stack-id]]]})) +(fn [{:keys [db]} [{:keys [address token stack-id]}]] + {:db (assoc-in db [:wallet :ui :send :to-address] address) + :fx [[:navigate-to-within-stack + (if token [:wallet-send-input-amount stack-id] [:wallet-select-asset stack-id])]]}) (rf/reg-event-fx :wallet/send-select-token (fn [{:keys [db]} [{:keys [token stack-id]}]] {:db (assoc-in db [:wallet :ui :send :token] token) :fx [[:navigate-to-within-stack [:wallet-send-input-amount stack-id]]]})) +(rf/reg-event-fx :wallet/send-select-token-drawer + (fn [{:keys [db]} [{:keys [token]}]] + {:db (assoc-in db [:wallet :ui :send :token] token)})) + +(rf/reg-event-fx :wallet/clean-selected-token + (fn [{:keys [db]}] + {:db (assoc-in db [:wallet :ui :send :token] nil)})) + (rf/reg-event-fx :wallet/send-select-amount (fn [{:keys [db]} [{:keys [amount stack-id]}]] {:db (assoc-in db [:wallet :ui :send :amount] amount) diff --git a/src/status_im/contexts/wallet/send/input_amount/view.cljs b/src/status_im/contexts/wallet/send/input_amount/view.cljs index d0f2e438f9..4318a2738a 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -155,7 +155,9 @@ :left-action :dot :delete-key? true :on-press handle-keyboard-press - :on-delete handle-delete}]])))) + :on-delete handle-delete}] + ] + )))) (defn- view-internal [props] diff --git a/src/status_im/contexts/wallet/send/select_asset/view.cljs b/src/status_im/contexts/wallet/send/select_asset/view.cljs index bc63cc75c8..bff8aefb7e 100644 --- a/src/status_im/contexts/wallet/send/select_asset/view.cljs +++ b/src/status_im/contexts/wallet/send/select_asset/view.cljs @@ -6,6 +6,7 @@ [react-native.safe-area :as safe-area] [reagent.core :as reagent] [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] + [status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.send.select-asset.style :as style] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -16,27 +17,32 @@ (defn- asset-component [] - (fn [token _ _ _] + (fn [token _ _ {:keys [currency currency-symbol]}] (let [on-press #(rf/dispatch [:wallet/send-select-token {:token token :stack-id :wallet-select-asset}]) - total-balance-formatted (.toFixed (:total-balance token) 2) - balance-fiat-formatted (.toFixed (:total-balance-fiat token) 2) - currency-symbol (rf/sub [:profile/currency-symbol])] + token-units (utils/total-token-units-in-all-chains token) + crypto-formatted (utils/get-standard-crypto-format token token-units) + fiat-value (utils/total-token-fiat-value currency token) + fiat-formatted (utils/get-standard-fiat-format crypto-formatted currency-symbol fiat-value)] [quo/token-network {:token (:symbol token) :label (:name token) - :token-value (str total-balance-formatted " " (:symbol token)) - :fiat-value (str currency-symbol balance-fiat-formatted) + :token-value (str crypto-formatted " " (:symbol token)) + :fiat-value fiat-formatted :networks (:networks token) :on-press on-press}]))) (defn- asset-list [search-text] - (let [filtered-tokens (rf/sub [:wallet/tokens-filtered search-text])] + (let [filtered-tokens (rf/sub [:wallet/tokens-filtered search-text]) + currency (rf/sub [:profile/currency]) + currency-symbol (rf/sub [:profile/currency-symbol])] [rn/flat-list {:data filtered-tokens + :render-data {:currency currency + :currency-symbol currency-symbol} :style {:flex 1} :content-container-style {:padding-horizontal 8} :keyboard-should-persist-taps :handled