fix: avoid exceptions related to comparing invalid strings to BigNumber instances (#21282)
This change adapts the code to avoid persisting the string `"<0.01"` in the wallet-send UI state. This change also modifies some of the BigNumber utility functions to validate that only BigNumbers are used with the utility functions. And the this change also tries to stop requesting route suggestions after exiting the wallet-send flow.
This commit is contained in:
parent
5df1e6caf6
commit
27d1a5f3f4
|
@ -43,23 +43,19 @@
|
|||
:token-decimals token-decimals
|
||||
:native-token? native-token?
|
||||
:receiver? false})
|
||||
from-network-values-for-ui (send-utils/network-values-for-ui
|
||||
from-network-amounts-by-chain)
|
||||
to-network-amounts-by-chain (send-utils/network-amounts-by-chain
|
||||
{:route chosen-route
|
||||
:token-decimals token-decimals
|
||||
:native-token? native-token?
|
||||
:receiver? true})
|
||||
to-network-values-for-ui (send-utils/network-values-for-ui
|
||||
to-network-amounts-by-chain)
|
||||
sender-possible-chain-ids (map :chain-id sender-network-values)
|
||||
sender-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
{:network-values
|
||||
(if (= tx-type :tx/bridge)
|
||||
from-network-values-for-ui
|
||||
from-network-amounts-by-chain
|
||||
(send-utils/add-zero-values-to-network-values
|
||||
from-network-values-for-ui
|
||||
from-network-amounts-by-chain
|
||||
sender-possible-chain-ids))
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
|
@ -71,7 +67,7 @@
|
|||
sender-network-values))
|
||||
receiver-network-values (if routes-available?
|
||||
(send-utils/network-amounts
|
||||
{:network-values to-network-values-for-ui
|
||||
{:network-values to-network-amounts-by-chain
|
||||
:disabled-chain-ids disabled-from-chain-ids
|
||||
:receiver-networks receiver-networks
|
||||
:token-networks-ids token-networks-ids
|
||||
|
@ -91,8 +87,8 @@
|
|||
assoc
|
||||
:suggested-routes suggested-routes-data
|
||||
:route chosen-route
|
||||
:from-values-by-chain from-network-values-for-ui
|
||||
:to-values-by-chain to-network-values-for-ui
|
||||
:from-values-by-chain from-network-amounts-by-chain
|
||||
:to-values-by-chain to-network-amounts-by-chain
|
||||
:sender-network-values sender-network-values
|
||||
:receiver-network-values receiver-network-values
|
||||
:network-links network-links
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
(:require
|
||||
[quo.theme]
|
||||
[status-im.contexts.wallet.send.input-amount.view :as input-amount]
|
||||
[status-im.setup.hot-reload :as hot-reload]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn view
|
||||
[]
|
||||
(hot-reload/use-safe-unmount #(rf/dispatch [:wallet/stop-get-suggested-routes]))
|
||||
[input-amount/view
|
||||
{:current-screen-id :screen/wallet.send-input-amount
|
||||
:button-one-label (i18n/label :t/review-send)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
[status-im.common.standard-authentication.core :as standard-auth]
|
||||
[status-im.contexts.wallet.common.utils :as utils]
|
||||
[status-im.contexts.wallet.send.transaction-confirmation.style :as style]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]
|
||||
[utils.security.core :as security]))
|
||||
|
@ -142,7 +143,7 @@
|
|||
[quo/summary-info
|
||||
{:type summary-info-type
|
||||
:networks? true
|
||||
:values network-values
|
||||
:values (send-utils/network-values-for-ui network-values)
|
||||
:account-props (cond-> account-props
|
||||
(and account-to? (not bridge-tx?))
|
||||
(assoc
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
[status-im.common.floating-button-page.view :as floating-button-page]
|
||||
[status-im.common.standard-authentication.core :as standard-auth]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[status-im.contexts.wallet.swap.swap-confirmation.style :as style]
|
||||
[utils.address :as address-utils]
|
||||
[utils.i18n :as i18n]
|
||||
|
@ -76,7 +77,7 @@
|
|||
[quo/summary-info
|
||||
{:type :token
|
||||
:networks? true
|
||||
:values network-values
|
||||
:values (send-utils/network-values-for-ui network-values)
|
||||
:token-props {:token token-symbol
|
||||
:label (str amount " " token-symbol)
|
||||
:address (address-utils/get-shortened-compressed-key token-address)
|
||||
|
|
|
@ -42,25 +42,36 @@
|
|||
[x]
|
||||
(instance? BigNumber x))
|
||||
|
||||
(defn ->bignumber
|
||||
[n]
|
||||
(if (bignumber? n) n (bignumber n)))
|
||||
|
||||
(defn ->bignumbers
|
||||
[n1 n2]
|
||||
(when-let [bn1 (->bignumber n1)]
|
||||
(when-let [bn2 (->bignumber n2)]
|
||||
(when (and (bignumber? bn1) (bignumber? bn2))
|
||||
[bn1 bn2]))))
|
||||
|
||||
(defn greater-than-or-equals
|
||||
[^js bn1 ^js bn2]
|
||||
(when (bignumber? bn1)
|
||||
[^js n1 ^js n2]
|
||||
(when-let [[^js bn1 ^js bn2] (->bignumbers n1 n2)]
|
||||
(.greaterThanOrEqualTo bn1 bn2)))
|
||||
|
||||
(defn greater-than
|
||||
[bn1 bn2]
|
||||
(when (bignumber? bn1)
|
||||
[n1 n2]
|
||||
(when-let [[^js bn1 ^js bn2] (->bignumbers n1 n2)]
|
||||
(.greaterThan ^js bn1 bn2)))
|
||||
|
||||
(defn less-than
|
||||
[bn1 bn2]
|
||||
(when (bignumber? bn1)
|
||||
[n1 n2]
|
||||
(when-let [[^js bn1 ^js bn2] (->bignumbers n1 n2)]
|
||||
(.lessThan ^js bn1 bn2)))
|
||||
|
||||
(defn equal-to
|
||||
[n1 n2]
|
||||
(when-let [^js bn1 (bignumber n1)]
|
||||
(.eq ^js bn1 n2)))
|
||||
(when-let [[^js bn1 ^js bn2] (->bignumbers n1 n2)]
|
||||
(.eq ^js bn1 bn2)))
|
||||
|
||||
(extend-type BigNumber
|
||||
IEquiv
|
||||
|
@ -79,8 +90,9 @@
|
|||
:else 0)))
|
||||
|
||||
(defn sub
|
||||
[bn1 bn2]
|
||||
(.sub ^js bn1 bn2))
|
||||
[n1 n2]
|
||||
(when-let [[^js bn1 ^js bn2] (->bignumbers n1 n2)]
|
||||
(.sub ^js bn1 bn2)))
|
||||
|
||||
(defn valid?
|
||||
[^js bn]
|
||||
|
@ -125,7 +137,7 @@
|
|||
|
||||
(defn to-number
|
||||
[^js bn]
|
||||
(when bn
|
||||
(when (bignumber? bn)
|
||||
(.toNumber bn)))
|
||||
|
||||
(defn to-string
|
||||
|
@ -158,7 +170,7 @@
|
|||
|
||||
(defn ether->wei
|
||||
[^js bn]
|
||||
(when bn
|
||||
(when (bignumber? bn)
|
||||
(.times bn ^js (bignumber 1e18))))
|
||||
|
||||
(defn token->unit
|
||||
|
@ -228,7 +240,7 @@
|
|||
(defn sufficient-funds?
|
||||
[^js amount ^js balance]
|
||||
(when (and amount balance)
|
||||
(.greaterThanOrEqualTo balance amount)))
|
||||
(greater-than-or-equals balance amount)))
|
||||
|
||||
(defn fiat-amount-value
|
||||
[amount-str from to prices]
|
||||
|
@ -275,7 +287,7 @@
|
|||
|
||||
(defn absolute-value
|
||||
[bn]
|
||||
(when bn
|
||||
(when (bignumber? bn)
|
||||
(.absoluteValue ^js bn)))
|
||||
|
||||
(defn format-amount
|
||||
|
|
Loading…
Reference in New Issue