fix(wallet): adjust max amount to not include network being bridged to (#20604)

This commit is contained in:
Jamie Caprani 2024-07-24 09:54:12 +01:00 committed by GitHub
parent cef1308b3a
commit 3ab345563c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 20 deletions

View File

@ -12,13 +12,16 @@
(hot-reload/use-safe-unmount #(rf/dispatch [:wallet/clean-routes-calculation]))
[rn/view {:style style/bridge-send-wrapper}
[input-amount/view
{:current-screen-id :screen/wallet.bridge-input-amount
:button-one-label (i18n/label :t/review-bridge)
:button-one-props {:icon-left :i/bridge}
:on-confirm (fn [amount]
(rf/dispatch [:wallet/set-token-amount-to-bridge
{:amount amount
:stack-id :screen/wallet.bridge-input-amount}]))
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-send-amount]))}]])
{:current-screen-id :screen/wallet.bridge-input-amount
:button-one-label (i18n/label :t/review-bridge)
:button-one-props {:icon-left :i/bridge}
:enabled-from-chain-ids (rf/sub
[:wallet/bridge-from-chain-ids])
:from-enabled-networks (rf/sub [:wallet/bridge-from-networks])
:on-confirm (fn [amount]
(rf/dispatch [:wallet/set-token-amount-to-bridge
{:amount amount
:stack-id :screen/wallet.bridge-input-amount}]))
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-send-amount]))}]])

View File

@ -146,6 +146,8 @@
button-one-props :button-one-props
current-screen-id :current-screen-id
initial-crypto-currency? :initial-crypto-currency?
enabled-from-chain-ids :enabled-from-chain-ids
from-enabled-networks :from-enabled-networks
:or {initial-crypto-currency? true}}]
(let [_ (rn/dismiss-keyboard!)
bottom (safe-area/get-bottom)
@ -164,9 +166,6 @@
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])
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
{token-balance :total-balance
available-balance :available-balance
@ -355,7 +354,7 @@
:currency-symbol currency-symbol
:crypto-decimals (min token-decimals 6)
:error? (controlled-input/input-error input-state)
:networks (seq send-enabled-networks)
:networks (seq from-enabled-networks)
:title (i18n/label
:t/send-limit
{:limit (if crypto-currency?
@ -429,3 +428,4 @@
(set-just-toggled-mode? false)
(set-input-state controlled-input/delete-all)
(rf/dispatch [:wallet/clean-suggested-routes]))}]]))

View File

@ -8,9 +8,12 @@
(defn view
[]
[input-amount/view
{:current-screen-id :screen/wallet.send-input-amount
:button-one-label (i18n/label :t/review-send)
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-from-locked-amounts])
(rf/dispatch [:wallet/clean-send-amount]))}])
{:current-screen-id :screen/wallet.send-input-amount
:button-one-label (i18n/label :t/review-send)
:enabled-from-chain-ids (rf/sub
[:wallet/wallet-send-enabled-from-chain-ids])
:from-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks])
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-from-locked-amounts])
(rf/dispatch [:wallet/clean-send-amount]))}])

View File

@ -61,3 +61,22 @@
:wallet/send-token-not-supported-in-receiver-networks?
:<- [:wallet/wallet-send]
:-> :token-not-supported-in-receiver-networks?)
(rf/reg-sub
:wallet/bridge-from-networks
:<- [:wallet/wallet-send]
:<- [:wallet/network-details]
(fn [[{:keys [bridge-to-chain-id]} networks]]
(set (filter (fn [network]
(not= (:chain-id network) bridge-to-chain-id))
networks))))
(rf/reg-sub
:wallet/bridge-from-chain-ids
:<- [:wallet/wallet-send]
:<- [:wallet/networks-by-mode]
(fn [[{:keys [bridge-to-chain-id]} networks]]
(keep (fn [network]
(when (not= (:chain-id network) bridge-to-chain-id)
(:chain-id network)))
networks)))