fix(wallet): "Not enough assets" case in send screen (#21425)

* Make `->bignumbers` more general

* Fix case when there are not enough assets to pay gas fees:
  - Fix the UI to match Figma
  - Fix logic to handle the case
  - Perform refactoring to surrounding code
This commit is contained in:
Ulises Manuel 2024-10-16 13:45:21 -06:00 committed by GitHub
parent d58553f67a
commit 711fd19967
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 312 additions and 280 deletions

View File

@ -28,95 +28,108 @@
{:fx [[:dispatch [:wallet/stop-get-suggested-routes]] {:fx [[:dispatch [:wallet/stop-get-suggested-routes]]
[:dispatch [:wallet/clean-suggested-routes]]]})) [:dispatch [:wallet/clean-suggested-routes]]]}))
(rf/reg-event-fx :wallet/suggested-routes-success (defn- add-not-enough-assets-data
(fn [{:keys [db]} [suggested-routes-data]] [send-data chosen-route]
(let [chosen-route (:best suggested-routes-data) (-> send-data
{:keys [token collectible token-display-name (assoc :route chosen-route
receiver-networks :loading-suggested-routes? false
receiver-network-values :suggested-routes {:best []}
sender-network-values tx-type :enough-assets? false)
disabled-from-chain-ids (update :sender-network-values send-utils/reset-loading-network-amounts-to-zero)
from-locked-amounts]} (get-in db [:wallet :ui :send]) (update :receiver-network-values send-utils/reset-loading-network-amounts-to-zero)))
token-decimals (if collectible 0 (:decimals token))
native-token? (and token (= token-display-name "ETH")) (rf/reg-event-fx
routes-available? (pos? (count chosen-route)) :wallet/suggested-routes-success
token-networks (:networks token) (fn [{:keys [db]} [suggested-routes-data enough-assets?]]
token-networks-ids (when token-networks (if-not enough-assets?
(map #(:chain-id %) token-networks)) {:db (update-in db [:wallet :ui :send] add-not-enough-assets-data (:best suggested-routes-data))}
from-network-amounts-by-chain (send-utils/network-amounts-by-chain (let [chosen-route (:best suggested-routes-data)
{:route chosen-route {:keys [token collectible token-display-name
:token-decimals token-decimals receiver-networks
:native-token? native-token? receiver-network-values
:receiver? false}) sender-network-values tx-type
to-network-amounts-by-chain (send-utils/network-amounts-by-chain disabled-from-chain-ids
{:route chosen-route from-locked-amounts]} (get-in db [:wallet :ui :send])
:token-decimals token-decimals token-decimals (if collectible 0 (:decimals token))
:native-token? native-token? native-token? (and token (= token-display-name "ETH"))
:receiver? true}) routes-available? (pos? (count chosen-route))
sender-possible-chain-ids (map :chain-id sender-network-values) token-networks (:networks token)
sender-network-values (if routes-available? token-networks-ids (when token-networks
(send-utils/network-amounts (map #(:chain-id %) token-networks))
{:network-values from-network-amounts-by-chain (send-utils/network-amounts-by-chain
(if (= tx-type :tx/bridge) {:route chosen-route
from-network-amounts-by-chain :token-decimals token-decimals
(send-utils/add-zero-values-to-network-values :native-token? native-token?
from-network-amounts-by-chain :receiver? false})
sender-possible-chain-ids)) to-network-amounts-by-chain (send-utils/network-amounts-by-chain
:disabled-chain-ids disabled-from-chain-ids {:route chosen-route
:receiver-networks receiver-networks :token-decimals token-decimals
:token-networks-ids token-networks-ids :native-token? native-token?
:from-locked-amounts from-locked-amounts :receiver? true})
:tx-type tx-type sender-possible-chain-ids (map :chain-id sender-network-values)
:receiver? false}) sender-network-values (if routes-available?
(send-utils/reset-loading-network-amounts-to-zero (send-utils/network-amounts
sender-network-values)) {:network-values
receiver-network-values (if routes-available? (if (= tx-type :tx/bridge)
(send-utils/network-amounts from-network-amounts-by-chain
{:network-values to-network-amounts-by-chain (send-utils/add-zero-values-to-network-values
:disabled-chain-ids disabled-from-chain-ids from-network-amounts-by-chain
:receiver-networks receiver-networks sender-possible-chain-ids))
:token-networks-ids token-networks-ids :disabled-chain-ids disabled-from-chain-ids
:tx-type tx-type :receiver-networks receiver-networks
:receiver? true}) :token-networks-ids token-networks-ids
(cond-> :from-locked-amounts from-locked-amounts
:tx-type tx-type
:receiver? false})
(send-utils/reset-loading-network-amounts-to-zero (send-utils/reset-loading-network-amounts-to-zero
receiver-network-values) sender-network-values))
receiver-network-values (if routes-available?
(send-utils/network-amounts
{:network-values to-network-amounts-by-chain
:disabled-chain-ids disabled-from-chain-ids
:receiver-networks receiver-networks
:token-networks-ids token-networks-ids
:tx-type tx-type
:receiver? true})
(cond->
(send-utils/reset-loading-network-amounts-to-zero
receiver-network-values)
(not= tx-type :tx/bridge) (not= tx-type :tx/bridge)
send-utils/safe-add-type-edit)) send-utils/safe-add-type-edit))
network-links (when routes-available? network-links (when routes-available?
(send-utils/network-links chosen-route (send-utils/network-links chosen-route
sender-network-values sender-network-values
receiver-network-values))] receiver-network-values))]
{:db (update-in db {:db (update-in db
[:wallet :ui :send] [:wallet :ui :send]
assoc assoc
:suggested-routes suggested-routes-data :suggested-routes suggested-routes-data
:route chosen-route :route chosen-route
:from-values-by-chain from-network-amounts-by-chain :from-values-by-chain from-network-amounts-by-chain
:to-values-by-chain to-network-amounts-by-chain :to-values-by-chain to-network-amounts-by-chain
:sender-network-values sender-network-values :sender-network-values sender-network-values
:receiver-network-values receiver-network-values :receiver-network-values receiver-network-values
:network-links network-links :network-links network-links
:loading-suggested-routes? false)}))) :loading-suggested-routes? false
:enough-assets? true)}))))
(rf/reg-event-fx :wallet/suggested-routes-error (rf/reg-event-fx
:wallet/suggested-routes-error
(fn [{:keys [db]} [error-message]] (fn [{:keys [db]} [error-message]]
(let [cleaned-sender-network-values (-> (get-in db [:wallet :ui :send :sender-network-values]) {:db (-> db
(send-utils/reset-loading-network-amounts-to-zero)) (update-in [:wallet :ui :send] dissoc :route)
cleaned-receiver-network-values (-> (get-in db [:wallet :ui :send :receiver-network-values]) (update-in [:wallet :ui :send :sender-network-values]
(send-utils/reset-loading-network-amounts-to-zero))] send-utils/reset-loading-network-amounts-to-zero)
{:db (-> db (update-in [:wallet :ui :send :receiver-network-values]
(update-in [:wallet :ui :send] dissoc :route) send-utils/reset-loading-network-amounts-to-zero)
(assoc-in [:wallet :ui :send :sender-network-values] cleaned-sender-network-values) (assoc-in [:wallet :ui :send :loading-suggested-routes?] false)
(assoc-in [:wallet :ui :send :receiver-network-values] cleaned-receiver-network-values) (assoc-in [:wallet :ui :send :suggested-routes] {:best []}))
(assoc-in [:wallet :ui :send :loading-suggested-routes?] false) :fx [[:dispatch
(assoc-in [:wallet :ui :send :suggested-routes] {:best []})) [:toasts/upsert
:fx [[:dispatch {:id :send-transaction-error
[:toasts/upsert :type :negative
{:id :send-transaction-error :text error-message}]]]}))
:type :negative
:text error-message}]]]})))
(rf/reg-event-fx :wallet/clean-send-address (rf/reg-event-fx :wallet/clean-send-address
(fn [{:keys [db]}] (fn [{:keys [db]}]
@ -378,8 +391,7 @@
from-locked-amounts bridge-to-chain-id] from-locked-amounts bridge-to-chain-id]
:or {token updated-token}} (get-in db [:wallet :ui :send]) :or {token updated-token}} (get-in db [:wallet :ui :send])
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?]) test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
networks ((if test-networks-enabled? :test :prod) networks (get-in db [:wallet :networks (if test-networks-enabled? :test :prod)])
(get-in db [:wallet :networks]))
network-chain-ids (map :chain-id networks) network-chain-ids (map :chain-id networks)
token-decimal (when token (:decimals token)) token-decimal (when token (:decimals token))
token-id (utils/format-token-id token collectible) token-id (utils/format-token-id token collectible)
@ -509,40 +521,43 @@
[routes] [routes]
(map data-store/new->old-route-path routes)) (map data-store/new->old-route-path routes))
(def ^:private best-routes-fix
(comp ->old-route-paths
remove-invalid-bonder-fees-routes
remove-multichain-routes))
(def ^:private candidates-fix
(comp ->old-route-paths remove-invalid-bonder-fees-routes))
(defn- fix-routes
[data]
(-> data
(data-store/rpc->suggested-routes)
(update :best best-routes-fix)
(update :candidates candidates-fix)))
(rf/reg-event-fx (rf/reg-event-fx
:wallet/handle-suggested-routes :wallet/handle-suggested-routes
(fn [{:keys [db]} [data]] (fn [{:keys [db]} [data]]
(let [swap? (get-in db [:wallet :ui :swap]) (let [{send :send swap? :swap} (-> db :wallet :ui)
{:keys [code details] :as error-response} (-> data :ErrorResponse) skip-processing-routes? (:skip-processing-suggested-routes? send)]
skip-processing-suggested-routes? (get-in db (when (or swap? (not skip-processing-routes?))
[:wallet :ui :send (let [{error-code :code
:skip-processing-suggested-routes?]) :as error} (:ErrorResponse data)
process-response? (and (not swap?) enough-assets? (not (and (:Best data) (= error-code "WR-002")))
(not skip-processing-suggested-routes?))] failure? (and error enough-assets? (not swap?))
(if (and (not swap?) error-response) error-message (if (zero? error-code) "An error occurred" (:details error))]
(let [error-message (if (= code "0") "An error occurred" details)] (when failure?
(log/error "failed to get suggested routes (async)" (log/error "failed to get suggested routes (async)"
{:event :wallet/handle-suggested-routes {:event :wallet/handle-suggested-routes
:error error-message}) :error error-message}))
{:fx [(cond {:fx [[:dispatch
swap? (cond
[:dispatch [:wallet/swap-proposal-error error-message]] (and failure? swap?) [:wallet/swap-proposal-error error-message]
process-response? failure? [:wallet/suggested-routes-error error-message]
[:dispatch [:wallet/suggested-routes-error error-message]])]}) swap? [:wallet/swap-proposal-success (fix-routes data)]
(let [best-routes-fix (comp ->old-route-paths :else [:wallet/suggested-routes-success (fix-routes data)
remove-invalid-bonder-fees-routes enough-assets?])]]})))))
remove-multichain-routes)
candidates-fix (comp ->old-route-paths
remove-invalid-bonder-fees-routes)
routes (-> data
(data-store/rpc->suggested-routes)
(update :best best-routes-fix)
(update :candidates candidates-fix))]
{:fx [(cond
swap?
[:dispatch [:wallet/swap-proposal-success routes]]
process-response?
[:dispatch [:wallet/suggested-routes-success routes]])]})))))
(rf/reg-event-fx :wallet/add-authorized-transaction (rf/reg-event-fx :wallet/add-authorized-transaction
(fn [{:keys [db]} [transaction]] (fn [{:keys [db]} [transaction]]

View File

@ -41,6 +41,8 @@
:mixedcase-address "0x7bcDfc75c431" :mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064" :public-key "0x04371e2d9d66b82f056bc128064"
:removed false} :removed false}
:wallet/current-viewing-account-color :purple
:wallet/wallet-send-enough-assets? true
:wallet/wallet-send-token {:symbol :eth :wallet/wallet-send-token {:symbol :eth
:networks [{:source 879 :networks [{:source 879
:short-name "eth" :short-name "eth"

View File

@ -140,6 +140,26 @@
:else (rf/dispatch [:wallet/stop-and-clean-suggested-routes]))) :else (rf/dispatch [:wallet/stop-and-clean-suggested-routes])))
(defn- get-fee-formatted
[route]
(when-let [native-currency-symbol (-> route first :from :native-currency-symbol)]
(rf/sub [:wallet/wallet-send-fee-fiat-formatted native-currency-symbol])))
(defn- insufficient-asset-amount?
[{:keys [token-symbol owned-eth-token input-state no-routes-found? limit-exceeded?
sender-network-values enough-assets?]}]
(let [eth-selected? (= token-symbol (string/upper-case constants/mainnet-short-name))
zero-owned-eth? (money/equal-to (:total-balance owned-eth-token) 0)
input-at-max-owned-amount? (money/equal-to
(controlled-input/value-bn input-state)
(controlled-input/upper-limit-bn input-state))
exceeded-input? (if eth-selected?
input-at-max-owned-amount?
zero-owned-eth?)]
(and (or no-routes-found? limit-exceeded?)
(seq sender-network-values)
(or exceeded-input? (not enough-assets?)))))
(defn view (defn view
;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed ;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed
;; for component tests only ;; for component tests only
@ -154,143 +174,129 @@
enabled-from-chain-ids :enabled-from-chain-ids enabled-from-chain-ids :enabled-from-chain-ids
from-enabled-networks :from-enabled-networks from-enabled-networks :from-enabled-networks
:or {initial-crypto-currency? true}}] :or {initial-crypto-currency? true}}]
(let [view-id (rf/sub [:view-id]) (let [view-id (rf/sub [:view-id])
active-screen? (= view-id current-screen-id) active-screen? (= view-id current-screen-id)
bottom (safe-area/get-bottom) bottom (safe-area/get-bottom)
[crypto-currency? set-crypto-currency] (rn/use-state initial-crypto-currency?) [crypto-currency?
handle-on-confirm (fn [amount] set-crypto-currency] (rn/use-state initial-crypto-currency?)
(rf/dispatch [:wallet/set-token-amount-to-send handle-on-confirm (fn [amount]
{:amount amount (rf/dispatch [:wallet/set-token-amount-to-send
:stack-id current-screen-id}])) {:amount amount
{fiat-currency :currency} (rf/sub [:profile/profile]) :stack-id current-screen-id}]))
{fiat-currency :currency} (rf/sub [:profile/profile])
{token-symbol :symbol {token-symbol :symbol
token-networks :networks token-networks :networks
:as token} (rf/sub [:wallet/wallet-send-token]) :as token} (rf/sub [:wallet/wallet-send-token])
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts]) send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
{:keys [total-balance] {:keys [total-balance]
:as token-by-symbol} (rf/sub [:wallet/token-by-symbol :as token-by-symbol} (rf/sub [:wallet/token-by-symbol
(str token-symbol) (str token-symbol)
enabled-from-chain-ids]) enabled-from-chain-ids])
token-balance (or default-limit-crypto total-balance) token-balance (or default-limit-crypto total-balance)
usd-conversion-rate (utils/token-usd-price token) usd-conversion-rate (utils/token-usd-price token)
currency (rf/sub [:profile/currency]) currency (rf/sub [:profile/currency])
conversion-rate (-> token conversion-rate (-> token
:market-values-per-currency :market-values-per-currency
currency currency
:price) :price)
token-decimals (-> token token-decimals (-> token
utils/token-usd-price utils/token-usd-price
utils/one-cent-value utils/one-cent-value
utils/calc-max-crypto-decimals) utils/calc-max-crypto-decimals)
[input-state set-input-state] (rn/use-state controlled-input/init-state) [input-state set-input-state] (rn/use-state controlled-input/init-state)
clear-input! #(set-input-state controlled-input/delete-all) clear-input! #(set-input-state controlled-input/delete-all)
currency-symbol (rf/sub [:profile/currency-symbol]) currency-symbol (rf/sub [:profile/currency-symbol])
loading-routes? (rf/sub loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
[:wallet/wallet-send-loading-suggested-routes?]) route (rf/sub [:wallet/wallet-send-route])
route (rf/sub [:wallet/wallet-send-route]) on-confirm (or default-on-confirm handle-on-confirm)
on-confirm (or default-on-confirm handle-on-confirm) crypto-decimals (or token-decimals default-crypto-decimals)
crypto-decimals (or token-decimals default-crypto-decimals) max-limit (if crypto-currency?
max-limit (if crypto-currency? (utils/cut-crypto-decimals-to-fit-usd-cents
(utils/cut-crypto-decimals-to-fit-usd-cents token-balance
token-balance usd-conversion-rate)
usd-conversion-rate) (utils/cut-fiat-balance-to-two-decimals
(utils/cut-fiat-balance-to-two-decimals (money/crypto->fiat token-balance conversion-rate)))
(money/crypto->fiat token-balance conversion-rate))) input-value (controlled-input/input-value input-state)
input-value (controlled-input/input-value input-state) valid-input? (not (or (controlled-input/empty-value? input-state)
valid-input? (not (or (controlled-input/empty-value? input-state) (controlled-input/input-error input-state)))
(controlled-input/input-error input-state))) amount-in-crypto (if crypto-currency?
confirm-disabled? (or (nil? route) input-value
(empty? route) (number/remove-trailing-zeroes
(not valid-input?)) (.toFixed (/ input-value conversion-rate)
amount-in-crypto (if crypto-currency? crypto-decimals)))
input-value total-amount-receiver (rf/sub [:wallet/total-amount true])
(number/remove-trailing-zeroes amount-text (str (number/remove-trailing-zeroes
(.toFixed (/ input-value conversion-rate) (.toFixed total-amount-receiver
crypto-decimals))) (min token-decimals 6)))
total-amount-receiver (rf/sub [:wallet/total-amount true]) " "
amount-text (str (number/remove-trailing-zeroes token-symbol)
(.toFixed total-amount-receiver show-select-asset-sheet #(rf/dispatch
(min token-decimals 6))) [:show-bottom-sheet
" " {:content (fn []
token-symbol) [select-asset-bottom-sheet
first-route (first route) clear-input!])}])
native-currency-symbol (when-not confirm-disabled? sender-network-values (rf/sub [:wallet/wallet-send-sender-network-values])
(get-in first-route receiver-network-values (rf/sub [:wallet/wallet-send-receiver-network-values])
[:from :native-currency-symbol])) tx-type (rf/sub [:wallet/wallet-send-tx-type])
fee-formatted (when native-currency-symbol unsupported-token-in-receiver? (and (not= tx-type :tx/bridge)
(rf/sub [:wallet/wallet-send-fee-fiat-formatted (->> receiver-network-values
native-currency-symbol])) (remove #(= (:type %) :add))
show-select-asset-sheet #(rf/dispatch (every? #(= (:type %) :not-available))))
[:show-bottom-sheet suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
{:content (fn [] routes (when suggested-routes
[select-asset-bottom-sheet (or (:best suggested-routes) []))
clear-input!])}]) no-routes-found? (and
sender-network-values (rf/sub (every-network-value-is-zero? sender-network-values)
[:wallet/wallet-send-sender-network-values]) (some? routes)
receiver-network-values (rf/sub (not loading-routes?)
[:wallet/wallet-send-receiver-network-values]) (not unsupported-token-in-receiver?))
tx-type (rf/sub [:wallet/wallet-send-tx-type]) receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
token-not-supported-in-receiver-networks? (and (not= tx-type :tx/bridge) receiver-preferred-networks (rf/sub [:wallet/wallet-send-receiver-preferred-networks])
(->> receiver-network-values receiver-preferred-network? (set receiver-preferred-networks)
(remove #(= (:type %) :add)) sending-to-unpreferred-networks? (some (comp not receiver-preferred-network?)
(every? #(= (:type %) :not-available)))) receiver-networks)
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes]) input-error (controlled-input/input-error input-state)
routes (when suggested-routes limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
(or (:best suggested-routes) [])) current-address (rf/sub [:wallet/current-viewing-account-address])
no-routes-found? (and current-color (rf/sub [:wallet/current-viewing-account-color])
(every-network-value-is-zero? enough-assets? (rf/sub [:wallet/wallet-send-enough-assets?])
sender-network-values) owned-eth-token (rf/sub [:wallet/token-by-symbol
(not (nil? routes)) (string/upper-case constants/mainnet-short-name)
(not loading-routes?) enabled-from-chain-ids])
(not token-not-supported-in-receiver-networks?)) not-enough-asset? (insufficient-asset-amount?
receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks]) {:enough-assets? enough-assets?
receiver-preferred-networks (rf/sub :token-symbol token-symbol
[:wallet/wallet-send-receiver-preferred-networks]) :owned-eth-token owned-eth-token
receiver-preferred-networks-set (set receiver-preferred-networks) :input-state input-state
sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network] :no-routes-found? no-routes-found?
(contains? :limit-exceeded? limit-exceeded?
receiver-preferred-networks-set :sender-network-values sender-network-values})
receiver-selected-network)) should-try-again? (and (not limit-exceeded?)
receiver-networks)) no-routes-found?
input-error (controlled-input/input-error input-state) (not not-enough-asset?))
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state) show-no-routes? (and (or no-routes-found? limit-exceeded?)
should-try-again? (and (not limit-exceeded?) no-routes-found?) (not-empty sender-network-values)
current-address (rf/sub [:wallet/current-viewing-account-address]) (not not-enough-asset?))
owned-eth-token (rf/sub [:wallet/token-by-symbol confirm-disabled? (or (nil? route)
(string/upper-case (empty? route)
constants/mainnet-short-name) (not valid-input?))
enabled-from-chain-ids]) fee-formatted (when (or (not confirm-disabled?) not-enough-asset?)
not-enough-asset? (and (get-fee-formatted route))
(or no-routes-found? limit-exceeded?) request-fetch-routes (fn [bounce-duration-ms]
(not-empty sender-network-values) (fetch-routes
(if (= token-symbol {:amount amount-in-crypto
(string/upper-case :valid-input? valid-input?
constants/mainnet-short-name)) :bounce-duration-ms bounce-duration-ms
(money/equal-to :token token
(controlled-input/value-bn input-state) :reset-amounts-to-zero? (and limit-exceeded?
(controlled-input/upper-limit-bn input-state)) (some? routes))}))
(money/equal-to (:total-balance swap-between-fiat-and-crypto (fn []
owned-eth-token) (if crypto-currency?
0))) (set-input-state
show-no-routes? (and #(controlled-input/->fiat % conversion-rate))
(or no-routes-found? limit-exceeded?) (set-input-state
(not-empty sender-network-values) #(controlled-input/->crypto % conversion-rate)))
(not not-enough-asset?)) (set-crypto-currency (not crypto-currency?)))]
request-fetch-routes (fn [bounce-duration-ms]
(fetch-routes
{:amount amount-in-crypto
:valid-input? valid-input?
:bounce-duration-ms bounce-duration-ms
:token token
:reset-amounts-to-zero? (and limit-exceeded?
(some? routes))}))
swap-between-fiat-and-crypto (fn []
(if crypto-currency?
(set-input-state
#(controlled-input/->fiat % conversion-rate))
(set-input-state
#(controlled-input/->crypto % conversion-rate)))
(set-crypto-currency (not crypto-currency?)))]
(rn/use-effect (rn/use-effect
(fn [] (fn []
(when active-screen? (when active-screen?
@ -365,21 +371,23 @@
{:token token-by-symbol {:token token-by-symbol
:send-amount-in-crypto amount-in-crypto :send-amount-in-crypto amount-in-crypto
:valid-input? valid-input? :valid-input? valid-input?
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks? :token-not-supported-in-receiver-networks? unsupported-token-in-receiver?
:current-screen-id current-screen-id :current-screen-id current-screen-id
:request-fetch-routes request-fetch-routes}] :request-fetch-routes request-fetch-routes}]
(when (and (not loading-routes?) (when (and (not loading-routes?)
sender-network-values sender-network-values
token-not-supported-in-receiver-networks?) unsupported-token-in-receiver?)
[token-not-available token-symbol receiver-networks token-networks]) [token-not-available token-symbol receiver-networks token-networks])
(when (and (not no-routes-found?) (or loading-routes? route)) (when not-enough-asset?
[not-enough-asset])
(when (or (and (not no-routes-found?) (or loading-routes? route))
not-enough-asset?)
[estimated-fees [estimated-fees
{:loading-routes? loading-routes? {:loading-routes? loading-routes?
:fees fee-formatted :fees fee-formatted
:amount amount-text}]) :amount amount-text}])
(cond (when show-no-routes?
show-no-routes? [no-routes-found] [no-routes-found])
not-enough-asset? [not-enough-asset])
[quo/bottom-actions [quo/bottom-actions
{:actions :one-action {:actions :one-action
:button-one-label (if should-try-again? :button-one-label (if should-try-again?
@ -387,17 +395,20 @@
button-one-label) button-one-label)
:button-one-props (merge (when-not should-try-again? :button-one-props (merge (when-not should-try-again?
button-one-props) button-one-props)
{:disabled? (or loading-routes? {:disabled? (or not-enough-asset?
(and (not should-try-again?) confirm-disabled?)) loading-routes?
:on-press (cond (and (not should-try-again?)
should-try-again? confirm-disabled?))
#(rf/dispatch [:wallet/start-get-suggested-routes :on-press (cond
{:amount amount-in-crypto should-try-again?
:updated-token token-by-symbol}]) #(rf/dispatch [:wallet/start-get-suggested-routes
sending-to-unpreferred-networks? {:amount amount-in-crypto
#(show-unpreferred-networks-alert on-confirm) :updated-token token-by-symbol}])
:else sending-to-unpreferred-networks?
#(on-confirm amount-in-crypto))} #(show-unpreferred-networks-alert on-confirm)
:else
#(on-confirm amount-in-crypto))
:customization-color current-color}
(when should-try-again? (when should-try-again?
{:type :grey}))}] {:type :grey}))}]
[quo/numbered-keyboard [quo/numbered-keyboard

View File

@ -126,18 +126,23 @@
:<- [:wallet/wallet-send] :<- [:wallet/wallet-send]
:-> :route) :-> :route)
(rf/reg-sub
:wallet/wallet-send-enough-assets?
:<- [:wallet/wallet-send]
:-> :enough-assets?)
(rf/reg-sub (rf/reg-sub
:wallet/wallet-send-token :wallet/wallet-send-token
:<- [:wallet/wallet-send] :<- [:wallet/wallet-send]
:<- [:wallet/network-details] :<- [:wallet/network-details]
:<- [:wallet/wallet-send-disabled-from-chain-ids] :<- [:wallet/wallet-send-disabled-from-chain-ids]
(fn [[wallet-send networks disabled-from-chain-ids]] (fn [[wallet-send networks disabled-from-chain-ids]]
(let [token (:token wallet-send) (let [token (:token wallet-send)
enabled-from-chain-ids (->> networks disabled-from-chain-ids? (set disabled-from-chain-ids)
(filter #(not (contains? (set disabled-from-chain-ids) enabled-from-chain-ids (->> networks
(:chain-id %)))) (map :chain-id)
(map :chain-id) (remove disabled-from-chain-ids?)
set)] set)]
(some-> token (some-> token
(assoc :networks (network-utils/network-list token networks) (assoc :networks (network-utils/network-list token networks)
:available-balance (utils/calculate-total-token-balance token) :available-balance (utils/calculate-total-token-balance token)

View File

@ -47,11 +47,10 @@
(if (bignumber? n) n (bignumber n))) (if (bignumber? n) n (bignumber n)))
(defn ->bignumbers (defn ->bignumbers
[n1 n2] [& numbers]
(when-let [bn1 (->bignumber n1)] (let [transformed-numbers (map ->bignumber numbers)]
(when-let [bn2 (->bignumber n2)] (when (every? bignumber? transformed-numbers)
(when (and (bignumber? bn1) (bignumber? bn2)) transformed-numbers)))
[bn1 bn2]))))
(defn greater-than-or-equals (defn greater-than-or-equals
[^js n1 ^js n2] [^js n1 ^js n2]