feat: recalculate network max value (#19953)
This commit is contained in:
parent
8038fc5ceb
commit
3e4cbfeb69
|
@ -53,6 +53,7 @@
|
||||||
"2500")
|
"2500")
|
||||||
:has-error false}}
|
:has-error false}}
|
||||||
:total-balance 100
|
:total-balance 100
|
||||||
|
:available-balance 100
|
||||||
:market-values-per-currency {:usd {:price 10}}}
|
:market-values-per-currency {:usd {:price 10}}}
|
||||||
:wallet/wallet-send-loading-suggested-routes? false
|
:wallet/wallet-send-loading-suggested-routes? false
|
||||||
:wallet/wallet-send-route [{:from {:chainid 1
|
:wallet/wallet-send-route [{:from {:chainid 1
|
||||||
|
@ -77,7 +78,15 @@
|
||||||
:wallet/wallet-send-sender-network-values nil
|
:wallet/wallet-send-sender-network-values nil
|
||||||
:wallet/wallet-send-receiver-network-values nil
|
:wallet/wallet-send-receiver-network-values nil
|
||||||
:wallet/wallet-send-network-links nil
|
:wallet/wallet-send-network-links nil
|
||||||
:wallet/wallet-send-receiver-preferred-networks [1]})
|
:wallet/wallet-send-receiver-preferred-networks [1]
|
||||||
|
:wallet/wallet-send-enabled-networks [{:source 879
|
||||||
|
:short-name "eth"
|
||||||
|
:network-name :mainnet
|
||||||
|
:abbreviated-name "Eth."
|
||||||
|
:chain-id 1
|
||||||
|
:related-chain-id 1
|
||||||
|
:layer 1}]
|
||||||
|
:wallet/wallet-send-enabled-from-chain-ids [1]})
|
||||||
|
|
||||||
(h/describe "Send > input amount screen"
|
(h/describe "Send > input amount screen"
|
||||||
(h/setup-restorable-re-frame)
|
(h/setup-restorable-re-frame)
|
||||||
|
|
|
@ -138,11 +138,15 @@
|
||||||
{fiat-currency :currency} (rf/sub [:profile/profile])
|
{fiat-currency :currency} (rf/sub [:profile/profile])
|
||||||
{token-symbol :symbol
|
{token-symbol :symbol
|
||||||
token-networks :networks} (rf/sub [:wallet/wallet-send-token])
|
token-networks :networks} (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
|
{token-balance :total-balance
|
||||||
|
available-balance :available-balance
|
||||||
:as
|
:as
|
||||||
token} (rf/sub
|
token} (rf/sub
|
||||||
[:wallet/current-viewing-account-tokens-filtered
|
[:wallet/current-viewing-account-tokens-filtered
|
||||||
(str token-symbol)])
|
(str token-symbol) enabled-from-chain-ids])
|
||||||
conversion-rate (-> token :market-values-per-currency :usd :price)
|
conversion-rate (-> token :market-values-per-currency :usd :price)
|
||||||
loading-routes? (rf/sub
|
loading-routes? (rf/sub
|
||||||
[:wallet/wallet-send-loading-suggested-routes?])
|
[:wallet/wallet-send-loading-suggested-routes?])
|
||||||
|
@ -153,12 +157,22 @@
|
||||||
on-confirm (or default-on-confirm handle-on-confirm)
|
on-confirm (or default-on-confirm handle-on-confirm)
|
||||||
crypto-decimals (or default-crypto-decimals
|
crypto-decimals (or default-crypto-decimals
|
||||||
(utils/get-crypto-decimals-count token))
|
(utils/get-crypto-decimals-count token))
|
||||||
crypto-limit (or default-limit-crypto
|
current-crypto-limit (or default-limit-crypto
|
||||||
(utils/get-standard-crypto-format
|
(utils/get-standard-crypto-format
|
||||||
token
|
token
|
||||||
token-balance))
|
token-balance))
|
||||||
fiat-limit (.toFixed (* token-balance conversion-rate) 2)
|
available-crypto-limit (or default-limit-crypto
|
||||||
current-limit (if @crypto-currency? crypto-limit fiat-limit)
|
(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?
|
valid-input? (not (or (string/blank?
|
||||||
(controlled-input/input-value
|
(controlled-input/input-value
|
||||||
input-state))
|
input-state))
|
||||||
|
@ -167,7 +181,7 @@
|
||||||
0)
|
0)
|
||||||
(> (controlled-input/numeric-value
|
(> (controlled-input/numeric-value
|
||||||
input-state)
|
input-state)
|
||||||
current-limit)))
|
available-limit)))
|
||||||
current-currency (if @crypto-currency? token-symbol fiat-currency)
|
current-currency (if @crypto-currency? token-symbol fiat-currency)
|
||||||
input-num-value (controlled-input/numeric-value input-state)
|
input-num-value (controlled-input/numeric-value input-state)
|
||||||
confirm-disabled? (or (nil? route)
|
confirm-disabled? (or (nil? route)
|
||||||
|
@ -232,7 +246,10 @@
|
||||||
(contains?
|
(contains?
|
||||||
receiver-preferred-networks-set
|
receiver-preferred-networks-set
|
||||||
receiver-selected-network))
|
receiver-selected-network))
|
||||||
receiver-networks))]
|
receiver-networks))
|
||||||
|
limit-insufficient? (> (controlled-input/numeric-value input-state)
|
||||||
|
current-limit)
|
||||||
|
should-try-again? (and (not limit-insufficient?) no-routes-found?)]
|
||||||
(rn/use-mount
|
(rn/use-mount
|
||||||
(fn []
|
(fn []
|
||||||
(let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!))
|
(let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!))
|
||||||
|
@ -256,7 +273,7 @@
|
||||||
:currency current-currency
|
:currency current-currency
|
||||||
:crypto-decimals crypto-decimals
|
:crypto-decimals crypto-decimals
|
||||||
:error? (controlled-input/input-error input-state)
|
:error? (controlled-input/input-error input-state)
|
||||||
:networks (seq token-networks)
|
:networks (seq send-enabled-networks)
|
||||||
:title (i18n/label :t/send-limit
|
:title (i18n/label :t/send-limit
|
||||||
{:limit (make-limit-label current-limit current-currency)})
|
{:limit (make-limit-label current-limit current-currency)})
|
||||||
:conversion conversion-rate
|
:conversion conversion-rate
|
||||||
|
@ -280,7 +297,7 @@
|
||||||
:fees fee-formatted
|
:fees fee-formatted
|
||||||
:amount amount-text
|
:amount amount-text
|
||||||
:receiver (address/get-shortened-key to-address)}])
|
:receiver (address/get-shortened-key to-address)}])
|
||||||
(when no-routes-found?
|
(when (or no-routes-found? limit-insufficient?)
|
||||||
[rn/view {:style style/no-routes-found-container}
|
[rn/view {:style style/no-routes-found-container}
|
||||||
[quo/info-message
|
[quo/info-message
|
||||||
{:type :error
|
{:type :error
|
||||||
|
@ -290,13 +307,13 @@
|
||||||
(i18n/label :t/no-routes-found)]])
|
(i18n/label :t/no-routes-found)]])
|
||||||
[quo/bottom-actions
|
[quo/bottom-actions
|
||||||
{:actions :one-action
|
{:actions :one-action
|
||||||
:button-one-label (if no-routes-found?
|
:button-one-label (if should-try-again?
|
||||||
(i18n/label :t/try-again)
|
(i18n/label :t/try-again)
|
||||||
button-one-label)
|
button-one-label)
|
||||||
:button-one-props (merge button-one-props
|
:button-one-props (merge button-one-props
|
||||||
{:disabled? (and (not no-routes-found?) confirm-disabled?)
|
{:disabled? (and (not should-try-again?) confirm-disabled?)
|
||||||
:on-press (cond
|
:on-press (cond
|
||||||
no-routes-found?
|
should-try-again?
|
||||||
#(rf/dispatch [:wallet/get-suggested-routes
|
#(rf/dispatch [:wallet/get-suggested-routes
|
||||||
{:amount (controlled-input/input-value
|
{:amount (controlled-input/input-value
|
||||||
input-state)}])
|
input-state)}])
|
||||||
|
@ -304,7 +321,7 @@
|
||||||
#(show-unpreferred-networks-alert on-confirm)
|
#(show-unpreferred-networks-alert on-confirm)
|
||||||
:else
|
:else
|
||||||
on-confirm)}
|
on-confirm)}
|
||||||
(when no-routes-found?
|
(when should-try-again?
|
||||||
{:type :grey}))}]
|
{:type :grey}))}]
|
||||||
[quo/numbered-keyboard
|
[quo/numbered-keyboard
|
||||||
{:container-style (style/keyboard-container bottom)
|
{:container-style (style/keyboard-container bottom)
|
||||||
|
|
|
@ -290,11 +290,13 @@
|
||||||
:wallet/current-viewing-account-tokens-filtered
|
:wallet/current-viewing-account-tokens-filtered
|
||||||
:<- [:wallet/current-viewing-account]
|
:<- [:wallet/current-viewing-account]
|
||||||
:<- [:wallet/network-details]
|
:<- [:wallet/network-details]
|
||||||
(fn [[account networks] [_ query]]
|
(fn [[account networks] [_ query chain-ids]]
|
||||||
(let [tokens (map (fn [token]
|
(let [tokens (map (fn [token]
|
||||||
(assoc token
|
(assoc token
|
||||||
:networks (network-utils/network-list token networks)
|
:networks (network-utils/network-list token networks)
|
||||||
:total-balance (utils/calculate-total-token-balance token)))
|
:available-balance (utils/calculate-total-token-balance token)
|
||||||
|
:total-balance (utils/calculate-total-token-balance token
|
||||||
|
chain-ids)))
|
||||||
(:tokens account))
|
(:tokens account))
|
||||||
sorted-tokens (sort-by :name compare tokens)]
|
sorted-tokens (sort-by :name compare tokens)]
|
||||||
(if query
|
(if query
|
||||||
|
@ -452,3 +454,19 @@
|
||||||
:wallet/public-address
|
:wallet/public-address
|
||||||
:<- [:wallet/create-account]
|
:<- [:wallet/create-account]
|
||||||
:-> :public-address)
|
:-> :public-address)
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/wallet-send-enabled-networks
|
||||||
|
:<- [:wallet/wallet-send-token]
|
||||||
|
:<- [:wallet/wallet-send-disabled-from-chain-ids]
|
||||||
|
(fn [[{:keys [networks]} disabled-from-chain-ids]]
|
||||||
|
(->> networks
|
||||||
|
(filter #(not (contains? (set disabled-from-chain-ids)
|
||||||
|
(:chain-id %))))
|
||||||
|
set)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/wallet-send-enabled-from-chain-ids
|
||||||
|
:<- [:wallet/wallet-send-enabled-networks]
|
||||||
|
(fn [send-enabled-networks]
|
||||||
|
(map :chain-id send-enabled-networks)))
|
||||||
|
|
Loading…
Reference in New Issue