fix: show network card with zero value on the sender side if the router does not return a route for that network (#20152)
Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
parent
72141e684f
commit
a8d36bf497
|
@ -56,14 +56,20 @@
|
||||||
native-token?
|
native-token?
|
||||||
:receiver? true})
|
:receiver? true})
|
||||||
to-network-values-for-ui (send-utils/network-values-for-ui to-network-amounts-by-chain)
|
to-network-values-for-ui (send-utils/network-values-for-ui to-network-amounts-by-chain)
|
||||||
|
sender-possible-chain-ids (mapv :chain-id sender-network-values)
|
||||||
sender-network-values (if routes-available?
|
sender-network-values (if routes-available?
|
||||||
(send-utils/network-amounts
|
(send-utils/network-amounts
|
||||||
{:network-values from-network-values-for-ui
|
{:network-values
|
||||||
|
(if (= tx-type :tx/bridge)
|
||||||
|
from-network-values-for-ui
|
||||||
|
(send-utils/add-zero-values-to-network-values
|
||||||
|
from-network-values-for-ui
|
||||||
|
sender-possible-chain-ids))
|
||||||
:disabled-chain-ids disabled-from-chain-ids
|
:disabled-chain-ids disabled-from-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
:token-networks-ids token-networks-ids
|
:token-networks-ids token-networks-ids
|
||||||
:tx-type tx-type
|
:tx-type tx-type
|
||||||
:receiver? false})
|
:receiver? false})
|
||||||
(send-utils/reset-loading-network-amounts-to-zero
|
(send-utils/reset-loading-network-amounts-to-zero
|
||||||
sender-network-values))
|
sender-network-values))
|
||||||
receiver-network-values (if routes-available?
|
receiver-network-values (if routes-available?
|
||||||
|
@ -322,9 +328,9 @@
|
||||||
(when (empty? receiver-network-values) :receiver-network-values)))})))
|
(when (empty? receiver-network-values) :receiver-network-values)))})))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/get-suggested-routes
|
(rf/reg-event-fx :wallet/get-suggested-routes
|
||||||
(fn [{:keys [db now]} [{:keys [amount]}]]
|
(fn [{:keys [db now]} [{:keys [amount updated-token]}]]
|
||||||
(let [wallet-address (get-in db [:wallet :current-viewing-account-address])
|
(let [wallet-address (get-in db [:wallet :current-viewing-account-address])
|
||||||
token (get-in db [:wallet :ui :send :token])
|
token (or updated-token (get-in db [:wallet :ui :send :token]))
|
||||||
transaction-type (get-in db [:wallet :ui :send :tx-type])
|
transaction-type (get-in db [:wallet :ui :send :tx-type])
|
||||||
collectible (get-in db [:wallet :ui :send :collectible])
|
collectible (get-in db [:wallet :ui :send :collectible])
|
||||||
to-address (get-in db [:wallet :ui :send :to-address])
|
to-address (get-in db [:wallet :ui :send :to-address])
|
||||||
|
@ -356,32 +362,41 @@
|
||||||
:tx/bridge constants/send-type-bridge
|
:tx/bridge constants/send-type-bridge
|
||||||
constants/send-type-transfer)
|
constants/send-type-transfer)
|
||||||
balances-per-chain (when token (:balances-per-chain token))
|
balances-per-chain (when token (:balances-per-chain token))
|
||||||
token-available-networks-for-suggested-routes
|
sender-token-available-networks-for-suggested-routes
|
||||||
(when token
|
(when token
|
||||||
(send-utils/token-available-networks-for-suggested-routes {:balances-per-chain
|
(send-utils/token-available-networks-for-suggested-routes {:balances-per-chain
|
||||||
balances-per-chain
|
balances-per-chain
|
||||||
:disabled-chain-ids
|
:disabled-chain-ids
|
||||||
disabled-from-chain-ids}))
|
disabled-from-chain-ids
|
||||||
|
:only-with-balance? true}))
|
||||||
|
receiver-token-available-networks-for-suggested-routes
|
||||||
|
(when token
|
||||||
|
(send-utils/token-available-networks-for-suggested-routes {:balances-per-chain
|
||||||
|
balances-per-chain
|
||||||
|
:disabled-chain-ids
|
||||||
|
disabled-from-chain-ids
|
||||||
|
:only-with-balance? false}))
|
||||||
token-networks-ids (when token (mapv #(:chain-id %) (:networks token)))
|
token-networks-ids (when token (mapv #(:chain-id %) (:networks token)))
|
||||||
sender-network-values (when token-available-networks-for-suggested-routes
|
sender-network-values (when sender-token-available-networks-for-suggested-routes
|
||||||
(send-utils/loading-network-amounts
|
(send-utils/loading-network-amounts
|
||||||
{:valid-networks (if (= transaction-type :tx/bridge)
|
{:valid-networks
|
||||||
(filter
|
(if (= transaction-type :tx/bridge)
|
||||||
#(not= bridge-to-chain-id %)
|
(remove #(= bridge-to-chain-id %)
|
||||||
token-available-networks-for-suggested-routes)
|
sender-token-available-networks-for-suggested-routes)
|
||||||
token-available-networks-for-suggested-routes)
|
sender-token-available-networks-for-suggested-routes)
|
||||||
:disabled-chain-ids disabled-from-chain-ids
|
:disabled-chain-ids disabled-from-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
:token-networks-ids token-networks-ids
|
:token-networks-ids token-networks-ids
|
||||||
:tx-type transaction-type
|
:tx-type transaction-type
|
||||||
:receiver? false}))
|
:receiver? false}))
|
||||||
receiver-network-values (when token-available-networks-for-suggested-routes
|
receiver-network-values (when receiver-token-available-networks-for-suggested-routes
|
||||||
(send-utils/loading-network-amounts
|
(send-utils/loading-network-amounts
|
||||||
{:valid-networks (if (= transaction-type :tx/bridge)
|
{:valid-networks
|
||||||
(filter
|
(if (= transaction-type :tx/bridge)
|
||||||
#(= bridge-to-chain-id %)
|
(filter
|
||||||
token-available-networks-for-suggested-routes)
|
#(= bridge-to-chain-id %)
|
||||||
token-available-networks-for-suggested-routes)
|
receiver-token-available-networks-for-suggested-routes)
|
||||||
|
receiver-token-available-networks-for-suggested-routes)
|
||||||
:disabled-chain-ids disabled-from-chain-ids
|
:disabled-chain-ids disabled-from-chain-ids
|
||||||
:receiver-networks receiver-networks
|
:receiver-networks receiver-networks
|
||||||
:token-networks-ids token-networks-ids
|
:token-networks-ids token-networks-ids
|
||||||
|
@ -398,13 +413,16 @@
|
||||||
network-preferences
|
network-preferences
|
||||||
gas-rates
|
gas-rates
|
||||||
from-locked-amount]]
|
from-locked-amount]]
|
||||||
{:db (-> db
|
{:db (cond-> db
|
||||||
(assoc-in [:wallet :ui :send :amount] amount)
|
:always (assoc-in [:wallet :ui :send :amount] amount)
|
||||||
(assoc-in [:wallet :ui :send :loading-suggested-routes?] true)
|
:always (assoc-in [:wallet :ui :send :loading-suggested-routes?] true)
|
||||||
(assoc-in [:wallet :ui :send :sender-network-values] sender-network-values)
|
:always (assoc-in [:wallet :ui :send :sender-network-values]
|
||||||
(assoc-in [:wallet :ui :send :receiver-network-values] receiver-network-values)
|
sender-network-values)
|
||||||
(assoc-in [:wallet :ui :send :suggested-routes-call-timestamp] now)
|
:always (assoc-in [:wallet :ui :send :receiver-network-values]
|
||||||
(update-in [:wallet :ui :send] dissoc :network-links))
|
receiver-network-values)
|
||||||
|
:always (assoc-in [:wallet :ui :send :suggested-routes-call-timestamp] now)
|
||||||
|
:always (update-in [:wallet :ui :send] dissoc :network-links)
|
||||||
|
token (assoc-in [:wallet :ui :send :token] token))
|
||||||
:json-rpc/call [{:method "wallet_getSuggestedRoutes"
|
:json-rpc/call [{:method "wallet_getSuggestedRoutes"
|
||||||
:params request-params
|
:params request-params
|
||||||
:on-success (fn [suggested-routes]
|
:on-success (fn [suggested-routes]
|
||||||
|
|
|
@ -161,7 +161,8 @@
|
||||||
enabled-from-chain-ids (rf/sub
|
enabled-from-chain-ids (rf/sub
|
||||||
[:wallet/wallet-send-enabled-from-chain-ids])
|
[:wallet/wallet-send-enabled-from-chain-ids])
|
||||||
{token-balance :total-balance
|
{token-balance :total-balance
|
||||||
available-balance :available-balance} (rf/sub [:wallet/token-by-symbol
|
available-balance :available-balance
|
||||||
|
:as token-by-symbol} (rf/sub [:wallet/token-by-symbol
|
||||||
(str token-symbol)
|
(str token-symbol)
|
||||||
enabled-from-chain-ids])
|
enabled-from-chain-ids])
|
||||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||||
|
@ -335,7 +336,7 @@
|
||||||
(number/remove-trailing-zeroes new-value))))))
|
(number/remove-trailing-zeroes new-value))))))
|
||||||
:on-token-press show-select-asset-sheet}]
|
:on-token-press show-select-asset-sheet}]
|
||||||
[routes/view
|
[routes/view
|
||||||
{:token token
|
{:token token-by-symbol
|
||||||
:input-value input-amount
|
:input-value input-amount
|
||||||
:value amount
|
:value amount
|
||||||
:valid-input? valid-input?
|
:valid-input? valid-input?
|
||||||
|
@ -371,7 +372,8 @@
|
||||||
conversion-rate)
|
conversion-rate)
|
||||||
2))]
|
2))]
|
||||||
(rf/dispatch [:wallet/get-suggested-routes
|
(rf/dispatch [:wallet/get-suggested-routes
|
||||||
{:amount amount}]))
|
{:amount amount
|
||||||
|
:updated-token token-by-symbol}]))
|
||||||
sending-to-unpreferred-networks?
|
sending-to-unpreferred-networks?
|
||||||
#(show-unpreferred-networks-alert on-confirm)
|
#(show-unpreferred-networks-alert on-confirm)
|
||||||
:else
|
:else
|
||||||
|
|
|
@ -17,10 +17,12 @@
|
||||||
(def network-link-2x-height 111)
|
(def network-link-2x-height 111)
|
||||||
|
|
||||||
(defn- fetch-routes
|
(defn- fetch-routes
|
||||||
[{:keys [amount bounce-duration-ms valid-input?]}]
|
[{:keys [amount bounce-duration-ms token valid-input?]}]
|
||||||
(if valid-input?
|
(if valid-input?
|
||||||
(debounce/debounce-and-dispatch
|
(debounce/debounce-and-dispatch
|
||||||
[:wallet/get-suggested-routes {:amount amount}]
|
[:wallet/get-suggested-routes
|
||||||
|
{:amount amount
|
||||||
|
:updated-token token}]
|
||||||
bounce-duration-ms)
|
bounce-duration-ms)
|
||||||
(rf/dispatch [:wallet/clean-suggested-routes])))
|
(rf/dispatch [:wallet/clean-suggested-routes])))
|
||||||
|
|
||||||
|
@ -203,14 +205,16 @@
|
||||||
(fetch-routes
|
(fetch-routes
|
||||||
{:amount value
|
{:amount value
|
||||||
:valid-input? valid-input?
|
:valid-input? valid-input?
|
||||||
:bounce-duration-ms 2000})))
|
:bounce-duration-ms 2000
|
||||||
|
:token token})))
|
||||||
[input-value valid-input?])
|
[input-value valid-input?])
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
#(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0))
|
#(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0))
|
||||||
(fetch-routes
|
(fetch-routes
|
||||||
{:amount value
|
{:amount value
|
||||||
:valid-input? valid-input?
|
:valid-input? valid-input?
|
||||||
:bounce-duration-ms 0}))
|
:bounce-duration-ms 0
|
||||||
|
:token token}))
|
||||||
[disabled-from-chain-ids])
|
[disabled-from-chain-ids])
|
||||||
[rn/scroll-view {:content-container-style style/routes-container}
|
[rn/scroll-view {:content-container-style style/routes-container}
|
||||||
(when show-routes?
|
(when show-routes?
|
||||||
|
|
|
@ -67,12 +67,25 @@
|
||||||
{}
|
{}
|
||||||
amounts))
|
amounts))
|
||||||
|
|
||||||
|
(defn add-zero-values-to-network-values
|
||||||
|
[network-values all-possible-chain-ids]
|
||||||
|
(reduce
|
||||||
|
(fn [acc chain-id]
|
||||||
|
(let [route-value (get network-values chain-id)]
|
||||||
|
(assoc acc chain-id (or route-value (money/bignumber "0")))))
|
||||||
|
{}
|
||||||
|
all-possible-chain-ids))
|
||||||
|
|
||||||
(defn token-available-networks-for-suggested-routes
|
(defn token-available-networks-for-suggested-routes
|
||||||
[{:keys [balances-per-chain disabled-chain-ids]}]
|
[{:keys [balances-per-chain disabled-chain-ids only-with-balance?]}]
|
||||||
(let [disabled-set (set disabled-chain-ids)]
|
(let [disabled-set (set disabled-chain-ids)]
|
||||||
(->> balances-per-chain
|
(->> balances-per-chain
|
||||||
(filter (fn [[_ {:keys [chain-id]}]]
|
(filter (fn [[_ {:keys [chain-id raw-balance]}]]
|
||||||
(not (contains? disabled-set chain-id))))
|
(and (not (contains? disabled-set chain-id))
|
||||||
|
(or (not only-with-balance?)
|
||||||
|
(and only-with-balance?
|
||||||
|
(money/bignumber? raw-balance)
|
||||||
|
(money/greater-than raw-balance (money/bignumber "0")))))))
|
||||||
(map first))))
|
(map first))))
|
||||||
|
|
||||||
(def ^:private network-priority-score
|
(def ^:private network-priority-score
|
||||||
|
|
Loading…
Reference in New Issue