From ba1d8fef971575db2beac715f18716b333f9370e Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Sat, 18 May 2024 00:08:38 +0100 Subject: [PATCH 1/6] chore(wallet): feature flag incomplete import private key flow --- .../create_account/select_keypair/view.cljs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs b/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs index 760ce3f1cb8..4130dc7abc9 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs @@ -23,11 +23,11 @@ :add-divider? true :on-press #(rf/dispatch [:navigate-to :screen/wallet.enter-seed-phrase {:recovering-keypair? true}])} - {:icon :i/key - :accessibility-label :import-private-key - :label (i18n/label :t/import-private-key) - :on-press (when (ff/enabled? ::wallet.import-private-key) - #(rf/dispatch [:navigate-to :screen/wallet.import-private-key]))}]]]) + (when (ff/enabled? ::wallet.import-private-key) + {:icon :i/key + :accessibility-label :import-private-key + :label (i18n/label :t/import-private-key) + :on-press #(rf/dispatch [:navigate-to :screen/wallet.import-private-key])})]]]) (defn- parse-accounts [given-accounts] From 647f1240e8cd28c29e59e73ee1544ebdb03331ac Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Sun, 19 May 2024 23:43:30 +0100 Subject: [PATCH 2/6] chore(wallet): flush input on amount input page for sending screens when swapping account --- .../list_items/network_list/view.cljs | 1 - .../wallet/send/input_amount/view.cljs | 67 ++++++++++--------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/quo/components/list_items/network_list/view.cljs b/src/quo/components/list_items/network_list/view.cljs index ec2a57baeae..9bdcb4f0faf 100644 --- a/src/quo/components/list_items/network_list/view.cljs +++ b/src/quo/components/list_items/network_list/view.cljs @@ -40,7 +40,6 @@ [:catn [:props [:map {:closed true} - [:theme :schema.common/theme] [:network-image :int] [:label :string] [:fiat-value :string] 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 c103444f477..6ce762a299a 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -1,25 +1,24 @@ (ns status-im.contexts.wallet.send.input-amount.view (:require - [clojure.string :as string] - [quo.core :as quo] - [quo.foundations.colors :as colors] - [quo.theme] - [react-native.core :as rn] - [react-native.safe-area :as safe-area] - [reagent.core :as reagent] - [status-im.common.controlled-input.utils :as controlled-input] - [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] - [status-im.contexts.wallet.common.asset-list.view :as asset-list] - [status-im.contexts.wallet.common.utils :as utils] - [status-im.contexts.wallet.send.input-amount.style :as style] - [status-im.contexts.wallet.send.routes.view :as routes] - [status-im.contexts.wallet.send.utils :as send-utils] - [status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert] - [utils.debounce :as debounce] - [utils.i18n :as i18n] - [utils.money :as money] - [utils.number :as number] - [utils.re-frame :as rf])) + [clojure.string :as string] + [quo.core :as quo] + [quo.foundations.colors :as colors] + [quo.theme] + [react-native.core :as rn] + [react-native.safe-area :as safe-area] + [status-im.common.controlled-input.utils :as controlled-input] + [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] + [status-im.contexts.wallet.common.asset-list.view :as asset-list] + [status-im.contexts.wallet.common.utils :as utils] + [status-im.contexts.wallet.send.input-amount.style :as style] + [status-im.contexts.wallet.send.routes.view :as routes] + [status-im.contexts.wallet.send.utils :as send-utils] + [status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert] + [utils.debounce :as debounce] + [utils.i18n :as i18n] + [utils.money :as money] + [utils.number :as number] + [utils.re-frame :as rf])) (defn- make-limit-label-crypto [amount currency] @@ -97,7 +96,7 @@ [rn/view [quo/icon :i/alert {:size 16 - :color colors/danger-50}]] + :color (colors/resolve-color :danger theme)}]] [rn/view {:style style/token-not-available-content-container} [quo/text {:style (style/token-not-available-text theme) @@ -105,7 +104,7 @@ (i18n/label :t/token-not-available-on-receiver-networks {:token-symbol token-symbol})] [quo/button {:size 24 - :customization-color colors/danger-50 + :customization-color (colors/resolve-color :danger theme) :on-press add-token-networks} (i18n/label :t/add-networks-token-can-be-sent-to {:token-symbol token-symbol})]]])) @@ -141,7 +140,7 @@ :or {initial-crypto-currency? true}}] (let [_ (rn/dismiss-keyboard!) bottom (safe-area/get-bottom) - crypto-currency? (reagent/atom initial-crypto-currency?) + [crypto-currency? set-crypto-currency] (rn/use-state initial-crypto-currency?) on-navigate-back on-navigate-back] (fn [] (let [[input-state set-input-state] (rn/use-state controlled-input/init-state) @@ -184,10 +183,10 @@ available-balance)) current-fiat-limit (.toFixed (* token-balance conversion-rate) 2) available-fiat-limit (.toFixed (* available-balance conversion-rate) 2) - current-limit (if @crypto-currency? + current-limit (if crypto-currency? current-crypto-limit current-fiat-limit) - available-limit (if @crypto-currency? + available-limit (if crypto-currency? available-crypto-limit available-fiat-limit) valid-input? (not (or (string/blank? @@ -207,7 +206,7 @@ input-state)) (<= input-num-value 0) (> input-num-value current-limit)) - amount (if @crypto-currency? + amount (if crypto-currency? input-amount (number/remove-trailing-zeroes (.toFixed (/ input-amount conversion-rate) @@ -274,7 +273,8 @@ input-error (controlled-input/input-error input-state) limit-insufficient? (> (controlled-input/numeric-value input-state) current-limit) - should-try-again? (and (not limit-insufficient?) no-routes-found?)] + should-try-again? (and (not limit-insufficient?) no-routes-found?) + current-address (rf/sub [:wallet/current-viewing-account-address])] (rn/use-mount (fn [] (let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!)) @@ -289,6 +289,11 @@ (when input-error (debounce/clear-all)) (when (and limit-insufficient? routes) (rf/dispatch [:wallet/reset-network-amounts-to-zero]))) [input-error]) + (rn/use-effect + (fn [] + (when (not= input-state controlled-input/init-state) + (set-input-state controlled-input/init-state))) + [current-address]) [rn/view {:style style/screen :accessibility-label (str "container" @@ -307,7 +312,7 @@ :networks (seq send-enabled-networks) :title (i18n/label :t/send-limit - {:limit (if @crypto-currency? + {:limit (if crypto-currency? (make-limit-label-crypto current-limit token-symbol) (make-limit-label-fiat current-limit currency-symbol))}) :conversion conversion-rate @@ -315,7 +320,7 @@ :value input-amount :on-swap (fn [swap-to-crypto-currency?] (set-just-toggled-mode? true) - (reset! crypto-currency? swap-to-crypto-currency?) + (set-crypto-currency swap-to-crypto-currency?) (set-input-state (fn [input-state] (controlled-input/set-input-value @@ -358,7 +363,7 @@ should-try-again? #(let [input-amount (controlled-input/input-value input-state) - amount (if @crypto-currency? + amount (if crypto-currency? input-amount (.toFixed (* token-balance conversion-rate) @@ -377,7 +382,7 @@ :delete-key? true :on-press (fn [c] (let [new-text (str input-amount c) - max-decimals (if @crypto-currency? crypto-decimals 2) + max-decimals (if crypto-currency? crypto-decimals 2) regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$") regex (re-pattern regex-pattern)] (when (and (not loading-routes?) From e8b8f2379d494f5980d75567918aaa3249ba56b0 Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Mon, 20 May 2024 00:33:29 +0100 Subject: [PATCH 3/6] chore: tests fixed --- src/quo/components/list_items/network_list/component_spec.cljs | 3 +-- .../contexts/wallet/send/input_amount/component_spec.cljs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/quo/components/list_items/network_list/component_spec.cljs b/src/quo/components/list_items/network_list/component_spec.cljs index a7f1706f28a..43e729258c6 100644 --- a/src/quo/components/list_items/network_list/component_spec.cljs +++ b/src/quo/components/list_items/network_list/component_spec.cljs @@ -8,8 +8,7 @@ (h/render-with-theme-provider component :light)) (def props - {:theme :light - :state :default + {:state :default :label "Mainnet" :network-image 873 :customization-color :blue diff --git a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs index 4cc77f58116..5578d993780 100644 --- a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs @@ -18,6 +18,7 @@ :network-name :mainnet :chain-id 1 :related-chain-id 5}] + :wallet/current-viewing-address "0x1" :wallet/current-viewing-account {:path "m/44'/60'/0'/0/1" :emoji "💎" :key-uid "0x2f5ea39" From eeb1ed2fdabc87b5af177a8a0243afd89403c9e8 Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Mon, 20 May 2024 12:04:35 +0100 Subject: [PATCH 4/6] fix tests --- .../contexts/wallet/send/input_amount/component_spec.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs index 5578d993780..ae6af79fa0b 100644 --- a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs @@ -18,7 +18,7 @@ :network-name :mainnet :chain-id 1 :related-chain-id 5}] - :wallet/current-viewing-address "0x1" + :wallet/current-viewing-account-address "0x1" :wallet/current-viewing-account {:path "m/44'/60'/0'/0/1" :emoji "💎" :key-uid "0x2f5ea39" From 99f4782c99f5c0695f1f2a4e4d9de2e7ef4765bd Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Mon, 20 May 2024 22:24:16 +0100 Subject: [PATCH 5/6] chore: fix --- .../send/input_amount/component_spec.cljs | 2 +- .../wallet/send/input_amount/view.cljs | 38 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs index ae6af79fa0b..bb55c9705f2 100644 --- a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs @@ -18,7 +18,7 @@ :network-name :mainnet :chain-id 1 :related-chain-id 5}] - :wallet/current-viewing-account-address "0x1" + :wallet/current-viewing-account-address "0x1" :wallet/current-viewing-account {:path "m/44'/60'/0'/0/1" :emoji "💎" :key-uid "0x2f5ea39" 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 6ce762a299a..1f15fcec430 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -1,24 +1,24 @@ (ns status-im.contexts.wallet.send.input-amount.view (:require - [clojure.string :as string] - [quo.core :as quo] - [quo.foundations.colors :as colors] - [quo.theme] - [react-native.core :as rn] - [react-native.safe-area :as safe-area] - [status-im.common.controlled-input.utils :as controlled-input] - [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] - [status-im.contexts.wallet.common.asset-list.view :as asset-list] - [status-im.contexts.wallet.common.utils :as utils] - [status-im.contexts.wallet.send.input-amount.style :as style] - [status-im.contexts.wallet.send.routes.view :as routes] - [status-im.contexts.wallet.send.utils :as send-utils] - [status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert] - [utils.debounce :as debounce] - [utils.i18n :as i18n] - [utils.money :as money] - [utils.number :as number] - [utils.re-frame :as rf])) + [clojure.string :as string] + [quo.core :as quo] + [quo.foundations.colors :as colors] + [quo.theme] + [react-native.core :as rn] + [react-native.safe-area :as safe-area] + [status-im.common.controlled-input.utils :as controlled-input] + [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] + [status-im.contexts.wallet.common.asset-list.view :as asset-list] + [status-im.contexts.wallet.common.utils :as utils] + [status-im.contexts.wallet.send.input-amount.style :as style] + [status-im.contexts.wallet.send.routes.view :as routes] + [status-im.contexts.wallet.send.utils :as send-utils] + [status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert] + [utils.debounce :as debounce] + [utils.i18n :as i18n] + [utils.money :as money] + [utils.number :as number] + [utils.re-frame :as rf])) (defn- make-limit-label-crypto [amount currency] From 77a0ffbf71a80a52d3c95b3be8327cf89f3aa23f Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Tue, 21 May 2024 20:01:09 +0100 Subject: [PATCH 6/6] fix --- .../wallet/send/input_amount/view.cljs | 524 +++++++++--------- 1 file changed, 263 insertions(+), 261 deletions(-) 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 1f15fcec430..00c294876e4 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -139,264 +139,266 @@ initial-crypto-currency? :initial-crypto-currency? :or {initial-crypto-currency? true}}] (let [_ (rn/dismiss-keyboard!) - bottom (safe-area/get-bottom) - [crypto-currency? set-crypto-currency] (rn/use-state initial-crypto-currency?) - on-navigate-back on-navigate-back] - (fn [] - (let [[input-state set-input-state] (rn/use-state controlled-input/init-state) - [just-toggled-mode? set-just-toggled-mode?] (rn/use-state false) - clear-input! #(set-input-state controlled-input/delete-all) - handle-on-confirm (fn [] - (rf/dispatch [:wallet/set-token-amount-to-send - {:amount - (controlled-input/input-value - input-state) - :stack-id current-screen-id}])) - {fiat-currency :currency} (rf/sub [:profile/profile]) - {token-symbol :symbol - token-networks :networks - token-decimals :decimals - :as - token} (rf/sub [:wallet/wallet-send-token]) - send-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks]) - enabled-from-chain-ids (rf/sub - [:wallet/wallet-send-enabled-from-chain-ids]) - {token-balance :total-balance - available-balance :available-balance} (rf/sub [:wallet/token-by-symbol - (str token-symbol) - enabled-from-chain-ids]) - currency-symbol (rf/sub [:profile/currency-symbol]) - currency (rf/sub [:profile/currency]) - conversion-rate (-> token :market-values-per-currency currency :price) - loading-routes? (rf/sub - [:wallet/wallet-send-loading-suggested-routes?]) - route (rf/sub [:wallet/wallet-send-route]) - on-confirm (or default-on-confirm handle-on-confirm) - crypto-decimals (or token-decimals default-crypto-decimals) - current-crypto-limit (or default-limit-crypto - (utils/get-standard-crypto-format - token - token-balance)) - available-crypto-limit (or default-limit-crypto - (utils/get-standard-crypto-format - token - available-balance)) - current-fiat-limit (.toFixed (* token-balance conversion-rate) 2) - available-fiat-limit (.toFixed (* available-balance conversion-rate) 2) - current-limit (if crypto-currency? - current-crypto-limit - current-fiat-limit) - available-limit (if crypto-currency? - available-crypto-limit - available-fiat-limit) - valid-input? (not (or (string/blank? - (controlled-input/input-value - input-state)) - (<= (controlled-input/numeric-value - input-state) - 0) - (> (controlled-input/numeric-value - input-state) - available-limit))) - input-num-value (controlled-input/numeric-value input-state) - input-amount (controlled-input/input-value input-state) - confirm-disabled? (or (nil? route) - (empty? route) - (string/blank? (controlled-input/input-value - input-state)) - (<= input-num-value 0) - (> input-num-value current-limit)) - amount (if crypto-currency? - input-amount - (number/remove-trailing-zeroes - (.toFixed (/ input-amount conversion-rate) - crypto-decimals))) - send-amount (rf/sub [:wallet/wallet-send-amount]) - amount-text (str (number/remove-trailing-zeroes - (.toFixed (js/parseFloat send-amount) - (min token-decimals 6))) - " " - token-symbol) - first-route (first route) - native-currency-symbol (when-not confirm-disabled? - (get-in first-route - [:from :native-currency-symbol])) - native-token (when native-currency-symbol - (rf/sub [:wallet/token-by-symbol - native-currency-symbol])) - fee-in-native-token (when-not confirm-disabled? - (send-utils/calculate-full-route-gas-fee route)) - fee-in-crypto-formatted (when fee-in-native-token - (utils/get-standard-crypto-format - native-token - fee-in-native-token)) - fee-in-fiat (when-not confirm-disabled? - (utils/calculate-token-fiat-value - {:currency fiat-currency - :balance fee-in-native-token - :token native-token})) - fee-formatted (when fee-in-fiat - (utils/get-standard-fiat-format - fee-in-crypto-formatted - currency-symbol - fee-in-fiat)) - show-select-asset-sheet #(rf/dispatch - [:show-bottom-sheet - {:content (fn [] - [select-asset-bottom-sheet - clear-input!])}]) - sender-network-values (rf/sub - [:wallet/wallet-send-sender-network-values]) - receiver-network-values (rf/sub - [:wallet/wallet-send-receiver-network-values]) - token-not-supported-in-receiver-networks? (every? #(= (:type %) :not-available) - (filter #(not= (:type %) :add) - receiver-network-values)) - suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes]) - routes (when suggested-routes - (or (:best suggested-routes) [])) - no-routes-found? (and - (every-network-value-is-zero? - sender-network-values) - (not (nil? routes)) - (not loading-routes?) - (not token-not-supported-in-receiver-networks?)) - receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks]) - receiver-preferred-networks (rf/sub - [:wallet/wallet-send-receiver-preferred-networks]) - receiver-preferred-networks-set (set receiver-preferred-networks) - sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network] - (contains? - receiver-preferred-networks-set - receiver-selected-network)) - receiver-networks)) - input-error (controlled-input/input-error input-state) - limit-insufficient? (> (controlled-input/numeric-value input-state) - current-limit) - should-try-again? (and (not limit-insufficient?) no-routes-found?) - current-address (rf/sub [:wallet/current-viewing-account-address])] - (rn/use-mount - (fn [] - (let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!)) - app-keyboard-listener (.addEventListener rn/app-state "change" dismiss-keyboard-fn)] - #(.remove app-keyboard-listener)))) - (rn/use-effect - (fn [] - (set-input-state #(controlled-input/set-upper-limit % current-limit))) - [current-limit]) - (rn/use-effect - (fn [] - (when input-error (debounce/clear-all)) - (when (and limit-insufficient? routes) (rf/dispatch [:wallet/reset-network-amounts-to-zero]))) - [input-error]) - (rn/use-effect - (fn [] - (when (not= input-state controlled-input/init-state) - (set-input-state controlled-input/init-state))) - [current-address]) - [rn/view - {:style style/screen - :accessibility-label (str "container" - (when (controlled-input/input-error input-state) "-error"))} - [account-switcher/view - {:icon-name :i/arrow-left - :on-press on-navigate-back - :switcher-type :select-account}] - [quo/token-input - {:container-style style/input-container - :token token-symbol - :currency fiat-currency - :currency-symbol currency-symbol - :crypto-decimals (min token-decimals 6) - :error? (controlled-input/input-error input-state) - :networks (seq send-enabled-networks) - :title (i18n/label - :t/send-limit - {:limit (if crypto-currency? - (make-limit-label-crypto current-limit token-symbol) - (make-limit-label-fiat current-limit currency-symbol))}) - :conversion conversion-rate - :show-keyboard? false - :value input-amount - :on-swap (fn [swap-to-crypto-currency?] - (set-just-toggled-mode? true) - (set-crypto-currency swap-to-crypto-currency?) - (set-input-state - (fn [input-state] - (controlled-input/set-input-value - input-state - (let [value (controlled-input/input-value input-state) - new-value (if swap-to-crypto-currency? - (.toFixed (/ value conversion-rate) - crypto-decimals) - (.toFixed (* value conversion-rate) 12))] - (number/remove-trailing-zeroes new-value)))))) - :on-token-press show-select-asset-sheet}] - [routes/view - {:token token - :input-value input-amount - :value amount - :valid-input? valid-input? - :token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks? - :lock-fetch-routes? just-toggled-mode? - :current-screen-id current-screen-id}] - (when (and (not loading-routes?) - sender-network-values - token-not-supported-in-receiver-networks?) - [token-not-available token-symbol receiver-networks token-networks]) - (when (or loading-routes? fee-formatted) - [estimated-fees - {:loading-routes? loading-routes? - :fees fee-formatted - :amount amount-text}]) - (when (and (or no-routes-found? limit-insufficient?) (not-empty sender-network-values)) - [no-routes-found]) - [quo/bottom-actions - {:actions :one-action - :button-one-label (if should-try-again? - (i18n/label :t/try-again) - button-one-label) - :button-one-props (merge (when-not should-try-again? button-one-props) - {:disabled? (or loading-routes? - (and (not should-try-again?) confirm-disabled?)) - :on-press (cond - should-try-again? - #(let [input-amount (controlled-input/input-value - input-state) - amount (if crypto-currency? - input-amount - (.toFixed (* token-balance - conversion-rate) - 2))] - (rf/dispatch [:wallet/get-suggested-routes - {:amount amount}])) - sending-to-unpreferred-networks? - #(show-unpreferred-networks-alert on-confirm) - :else - on-confirm)} - (when should-try-again? - {:type :grey}))}] - [quo/numbered-keyboard - {:container-style (style/keyboard-container bottom) - :left-action :dot - :delete-key? true - :on-press (fn [c] - (let [new-text (str input-amount c) - max-decimals (if crypto-currency? crypto-decimals 2) - regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$") - regex (re-pattern regex-pattern)] - (when (and (not loading-routes?) - (re-matches regex new-text)) - (debounce/clear-all) - (set-just-toggled-mode? false) - (set-input-state #(controlled-input/add-character % c))))) - :on-delete (fn [] - (when-not loading-routes? - (debounce/clear-all) - (set-just-toggled-mode? false) - (set-input-state controlled-input/delete-last))) - :on-long-press-delete (fn [] - (when-not loading-routes? - (debounce/clear-all) - (set-just-toggled-mode? false) - (set-input-state controlled-input/delete-all)))}]])))) + bottom (safe-area/get-bottom) + [crypto-currency? set-crypto-currency] (rn/use-state initial-crypto-currency?) + on-navigate-back on-navigate-back + [input-state set-input-state] (rn/use-state controlled-input/init-state) + [just-toggled-mode? set-just-toggled-mode?] (rn/use-state false) + clear-input! #(set-input-state controlled-input/delete-all) + handle-on-confirm (fn [] + (rf/dispatch [:wallet/set-token-amount-to-send + {:amount + (controlled-input/input-value + input-state) + :stack-id current-screen-id}])) + {fiat-currency :currency} (rf/sub [:profile/profile]) + {token-symbol :symbol + token-networks :networks + token-decimals :decimals + :as + token} (rf/sub [:wallet/wallet-send-token]) + send-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks]) + enabled-from-chain-ids (rf/sub + [:wallet/wallet-send-enabled-from-chain-ids]) + {token-balance :total-balance + available-balance :available-balance} (rf/sub [:wallet/token-by-symbol + (str token-symbol) + enabled-from-chain-ids]) + currency-symbol (rf/sub [:profile/currency-symbol]) + currency (rf/sub [:profile/currency]) + conversion-rate (-> token + :market-values-per-currency + currency + :price) + loading-routes? (rf/sub + [:wallet/wallet-send-loading-suggested-routes?]) + route (rf/sub [:wallet/wallet-send-route]) + on-confirm (or default-on-confirm handle-on-confirm) + crypto-decimals (or token-decimals default-crypto-decimals) + current-crypto-limit (or default-limit-crypto + (utils/get-standard-crypto-format + token + token-balance)) + available-crypto-limit (or default-limit-crypto + (utils/get-standard-crypto-format + token + available-balance)) + current-fiat-limit (.toFixed (* token-balance conversion-rate) 2) + available-fiat-limit (.toFixed (* available-balance conversion-rate) 2) + current-limit (if crypto-currency? + current-crypto-limit + current-fiat-limit) + available-limit (if crypto-currency? + available-crypto-limit + available-fiat-limit) + valid-input? (not (or (string/blank? + (controlled-input/input-value + input-state)) + (<= (controlled-input/numeric-value + input-state) + 0) + (> (controlled-input/numeric-value + input-state) + available-limit))) + input-num-value (controlled-input/numeric-value input-state) + input-amount (controlled-input/input-value input-state) + confirm-disabled? (or (nil? route) + (empty? route) + (string/blank? (controlled-input/input-value + input-state)) + (<= input-num-value 0) + (> input-num-value current-limit)) + amount (if crypto-currency? + input-amount + (number/remove-trailing-zeroes + (.toFixed (/ input-amount conversion-rate) + crypto-decimals))) + send-amount (rf/sub [:wallet/wallet-send-amount]) + amount-text (str (number/remove-trailing-zeroes + (.toFixed (js/parseFloat send-amount) + (min token-decimals 6))) + " " + token-symbol) + first-route (first route) + native-currency-symbol (when-not confirm-disabled? + (get-in first-route + [:from :native-currency-symbol])) + native-token (when native-currency-symbol + (rf/sub [:wallet/token-by-symbol + native-currency-symbol])) + fee-in-native-token (when-not confirm-disabled? + (send-utils/calculate-full-route-gas-fee route)) + fee-in-crypto-formatted (when fee-in-native-token + (utils/get-standard-crypto-format + native-token + fee-in-native-token)) + fee-in-fiat (when-not confirm-disabled? + (utils/calculate-token-fiat-value + {:currency fiat-currency + :balance fee-in-native-token + :token native-token})) + fee-formatted (when fee-in-fiat + (utils/get-standard-fiat-format + fee-in-crypto-formatted + currency-symbol + fee-in-fiat)) + show-select-asset-sheet #(rf/dispatch + [:show-bottom-sheet + {:content (fn [] + [select-asset-bottom-sheet + clear-input!])}]) + sender-network-values (rf/sub + [:wallet/wallet-send-sender-network-values]) + receiver-network-values (rf/sub + [:wallet/wallet-send-receiver-network-values]) + token-not-supported-in-receiver-networks? (every? #(= (:type %) :not-available) + (filter #(not= (:type %) :add) + receiver-network-values)) + suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes]) + routes (when suggested-routes + (or (:best suggested-routes) [])) + no-routes-found? (and + (every-network-value-is-zero? + sender-network-values) + (not (nil? routes)) + (not loading-routes?) + (not token-not-supported-in-receiver-networks?)) + receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks]) + receiver-preferred-networks (rf/sub + [:wallet/wallet-send-receiver-preferred-networks]) + receiver-preferred-networks-set (set receiver-preferred-networks) + sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network] + (contains? + receiver-preferred-networks-set + receiver-selected-network)) + receiver-networks)) + input-error (controlled-input/input-error input-state) + limit-insufficient? (> (controlled-input/numeric-value input-state) + current-limit) + should-try-again? (and (not limit-insufficient?) no-routes-found?) + current-address (rf/sub [:wallet/current-viewing-account-address])] + (rn/use-mount + (fn [] + (let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!)) + app-keyboard-listener (.addEventListener rn/app-state "change" dismiss-keyboard-fn)] + #(.remove app-keyboard-listener)))) + (rn/use-effect + (fn [] + (set-input-state #(controlled-input/set-upper-limit % current-limit))) + [current-limit]) + (rn/use-effect + (fn [] + (when input-error (debounce/clear-all)) + (when (and limit-insufficient? routes) (rf/dispatch [:wallet/reset-network-amounts-to-zero]))) + [input-error]) + (rn/use-effect + (fn [] + (clear-input!) + (rf/dispatch [:wallet/clean-suggested-routes])) + [current-address]) + [rn/view + {:style style/screen + :accessibility-label (str "container" + (when (controlled-input/input-error input-state) "-error"))} + [account-switcher/view + {:icon-name :i/arrow-left + :on-press on-navigate-back + :switcher-type :select-account}] + [quo/token-input + {:container-style style/input-container + :token token-symbol + :currency fiat-currency + :currency-symbol currency-symbol + :crypto-decimals (min token-decimals 6) + :error? (controlled-input/input-error input-state) + :networks (seq send-enabled-networks) + :title (i18n/label + :t/send-limit + {:limit (if crypto-currency? + (make-limit-label-crypto current-limit token-symbol) + (make-limit-label-fiat current-limit currency-symbol))}) + :conversion conversion-rate + :show-keyboard? false + :value input-amount + :on-swap (fn [swap-to-crypto-currency?] + (set-just-toggled-mode? true) + (set-crypto-currency swap-to-crypto-currency?) + (set-input-state + (fn [input-state] + (controlled-input/set-input-value + input-state + (let [value (controlled-input/input-value input-state) + new-value (if swap-to-crypto-currency? + (.toFixed (/ value conversion-rate) + crypto-decimals) + (.toFixed (* value conversion-rate) 12))] + (number/remove-trailing-zeroes new-value)))))) + :on-token-press show-select-asset-sheet}] + [routes/view + {:token token + :input-value input-amount + :value amount + :valid-input? valid-input? + :token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks? + :lock-fetch-routes? just-toggled-mode? + :current-screen-id current-screen-id}] + (when (and (not loading-routes?) + sender-network-values + token-not-supported-in-receiver-networks?) + [token-not-available token-symbol receiver-networks token-networks]) + (when (or loading-routes? fee-formatted) + [estimated-fees + {:loading-routes? loading-routes? + :fees fee-formatted + :amount amount-text}]) + (when (and (or no-routes-found? limit-insufficient?) (not-empty sender-network-values)) + [no-routes-found]) + [quo/bottom-actions + {:actions :one-action + :button-one-label (if should-try-again? + (i18n/label :t/try-again) + button-one-label) + :button-one-props (merge (when-not should-try-again? button-one-props) + {:disabled? (or loading-routes? + (and (not should-try-again?) confirm-disabled?)) + :on-press (cond + should-try-again? + #(let [input-amount (controlled-input/input-value + input-state) + amount (if crypto-currency? + input-amount + (.toFixed (* token-balance + conversion-rate) + 2))] + (rf/dispatch [:wallet/get-suggested-routes + {:amount amount}])) + sending-to-unpreferred-networks? + #(show-unpreferred-networks-alert on-confirm) + :else + on-confirm)} + (when should-try-again? + {:type :grey}))}] + [quo/numbered-keyboard + {:container-style (style/keyboard-container bottom) + :left-action :dot + :delete-key? true + :on-press (fn [c] + (let [new-text (str input-amount c) + max-decimals (if crypto-currency? crypto-decimals 2) + regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$") + regex (re-pattern regex-pattern)] + (when (and (not loading-routes?) + (re-matches regex new-text)) + (debounce/clear-all) + (set-just-toggled-mode? false) + (set-input-state #(controlled-input/add-character % c))))) + :on-delete (fn [] + (when-not loading-routes? + (debounce/clear-all) + (set-just-toggled-mode? false) + (set-input-state controlled-input/delete-last))) + :on-long-press-delete (fn [] + (when-not loading-routes? + (debounce/clear-all) + (set-just-toggled-mode? false) + (set-input-state controlled-input/delete-all)))}]]))