From 87d82343e0dd7f03ad1af4afcbaf37631ae3767a Mon Sep 17 00:00:00 2001 From: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> Date: Fri, 6 Sep 2024 17:57:46 +0530 Subject: [PATCH 1/2] fix(wallet)_: token max value not updated when switching Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> --- .../contexts/wallet/send/input_amount/view.cljs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 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 8cb71b157e9..46127398aa7 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -178,12 +178,7 @@ utils/token-usd-price utils/one-cent-value utils/calc-max-crypto-decimals) - [input-state set-input-state] (rn/use-state - (-> controlled-input/init-state - (controlled-input/set-upper-limit - (utils/cut-crypto-decimals-to-fit-usd-cents - (or default-limit-crypto token-balance) - conversion-rate)))) + [input-state set-input-state] (rn/use-state controlled-input/init-state) clear-input! #(set-input-state controlled-input/delete-all) currency-symbol (rf/sub [:profile/currency-symbol]) loading-routes? (rf/sub @@ -291,6 +286,15 @@ app-keyboard-listener (.addEventListener rn/app-state "change" dismiss-keyboard-fn)] #(.remove app-keyboard-listener)))) (hot-reload/use-safe-unmount on-navigate-back) + (rn/use-effect + (fn [] + (set-input-state + #(-> % + (controlled-input/set-upper-limit + (utils/cut-crypto-decimals-to-fit-usd-cents + (or default-limit-crypto token-balance) + conversion-rate))))) + [token-symbol]) (rn/use-effect (fn [] (when input-error (debounce/clear-all)) From 62384ce7814c082e74d0c047b7d099b76288fa35 Mon Sep 17 00:00:00 2001 From: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:08:26 +0530 Subject: [PATCH 2/2] fix(wallet)_: token max value not updated when switching accounts or disabling networks Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> --- .../wallet/send/input_amount/view.cljs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 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 46127398aa7..7daa392858b 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -165,10 +165,12 @@ :as token} (rf/sub [:wallet/wallet-send-token]) send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts]) - {token-balance :total-balance - :as token-by-symbol} (rf/sub [:wallet/token-by-symbol + {:keys [total-balance] + :as token-by-symbol} (rf/sub [:wallet/token-by-symbol (str token-symbol) enabled-from-chain-ids]) + token-balance (or default-limit-crypto total-balance) + usd-conversion-rate (utils/token-usd-price token) currency (rf/sub [:profile/currency]) conversion-rate (-> token :market-values-per-currency @@ -186,6 +188,14 @@ route (rf/sub [:wallet/wallet-send-route]) on-confirm (or default-on-confirm handle-on-confirm) crypto-decimals (or token-decimals default-crypto-decimals) + max-limit (if crypto-currency? + (utils/cut-crypto-decimals-to-fit-usd-cents + token-balance + usd-conversion-rate) + (-> (money/crypto->fiat + token-balance + conversion-rate) + utils/cut-fiat-balance-to-two-decimals)) input-value (controlled-input/input-value input-state) valid-input? (not (or (controlled-input/empty-value? input-state) (controlled-input/input-error input-state))) @@ -288,13 +298,8 @@ (hot-reload/use-safe-unmount on-navigate-back) (rn/use-effect (fn [] - (set-input-state - #(-> % - (controlled-input/set-upper-limit - (utils/cut-crypto-decimals-to-fit-usd-cents - (or default-limit-crypto token-balance) - conversion-rate))))) - [token-symbol]) + (set-input-state #(controlled-input/set-upper-limit % max-limit))) + [max-limit]) (rn/use-effect (fn [] (when input-error (debounce/clear-all))