fix: suggested routes are not calculated with preferred networks (#19668)

Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
Brian Sztamfater 2024-04-24 04:50:25 -03:00 committed by GitHub
parent e6f9932dc5
commit 782d038fb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 9 deletions

View File

@ -15,4 +15,5 @@
:button-one-props {:icon-left :i/bridge}
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-send-amount])
(rf/dispatch [:navigate-back]))}]])

View File

@ -76,6 +76,10 @@
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui :send] dissoc :recipient :to-address)}))
(rf/reg-event-fx :wallet/clean-send-amount
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui :send] dissoc :amount)}))
(rf/reg-event-fx :wallet/clean-disabled-from-networks
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui :send] dissoc :disabled-from-chain-ids)}))
@ -86,7 +90,7 @@
(let [[prefix to-address] (utils/split-prefix-and-address address)
testnet-enabled? (get-in db [:profile/profile :test-networks-enabled?])
goerli-enabled? (get-in db [:profile/profile :is-goerli-enabled?])
selected-networks (network-utils/resolve-receiver-networks
receiver-networks (network-utils/resolve-receiver-networks
{:prefix prefix
:testnet-enabled? testnet-enabled?
:goerli-enabled? goerli-enabled?})]
@ -94,7 +98,7 @@
(assoc-in [:wallet :ui :send :recipient] (or recipient address))
(assoc-in [:wallet :ui :send :to-address] to-address)
(assoc-in [:wallet :ui :send :address-prefix] prefix)
(assoc-in [:wallet :ui :send :selected-networks] selected-networks))
(assoc-in [:wallet :ui :send :receiver-networks] receiver-networks))
:fx [[:dispatch
[:wallet/wizard-navigate-forward
{:current-screen stack-id
@ -104,7 +108,16 @@
(rf/reg-event-fx
:wallet/update-receiver-networks
(fn [{:keys [db]} [selected-networks]]
{:db (assoc-in db [:wallet :ui :send :selected-networks] selected-networks)}))
(let [amount (get-in db [:wallet :ui :send :amount])
disabled-from-chain-ids (get-in db [:wallet :ui :send :disabled-from-chain-ids])
filtered-disabled-from-chain-ids (filter (fn [chain-id]
(some #(= chain-id %)
selected-networks))
disabled-from-chain-ids)]
{:db (-> db
(assoc-in [:wallet :ui :send :receiver-networks] selected-networks)
(assoc-in [:wallet :ui :send :disabled-from-chain-ids] filtered-disabled-from-chain-ids))
:fx [[:dispatch [:wallet/get-suggested-routes {:amount amount}]]]})))
(rf/reg-event-fx
:wallet/send-select-token
@ -195,6 +208,7 @@
transaction-type (get-in db [:wallet :ui :send :tx-type])
collectible (get-in db [:wallet :ui :send :collectible])
to-address (get-in db [:wallet :ui :send :to-address])
receiver-networks (get-in db [:wallet :ui :send :receiver-networks])
disabled-from-chain-ids (or (get-in db [:wallet :ui :send :disabled-from-chain-ids]) [])
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
networks ((if test-networks-enabled? :test :prod)
@ -215,7 +229,10 @@
disabled-from-chain-ids disabled-from-chain-ids
disabled-to-chain-ids (if (= transaction-type :bridge)
(filter #(not= % bridge-to-chain-id) network-chain-ids)
[])
(filter (fn [chain-id]
(not (some #(= chain-id %)
receiver-networks)))
network-chain-ids))
from-locked-amount {}
transaction-type-param (case transaction-type
:collectible constants/send-type-erc-721-transfer
@ -233,6 +250,7 @@
gas-rates
from-locked-amount]]
{:db (-> db
(assoc-in [:wallet :ui :send :amount] amount)
(assoc-in [:wallet :ui :send :loading-suggested-routes?] true)
(assoc-in [:wallet :ui :send :suggested-routes-call-timestamp] now))
:json-rpc/call [{:method "wallet_getSuggestedRoutes"

View File

@ -64,7 +64,7 @@
:max-priority-fee-per-gas "0.011000001"
:eip1559-enabled true}}]
:wallet/wallet-send-suggested-routes {:candidates []}
:wallet/wallet-send-selected-networks [1]
:wallet/wallet-send-receiver-networks [1]
:view-id :screen/wallet.send-input-amount
:wallet/wallet-send-to-address "0x04371e2d9d66b82f056bc128064"
:profile/currency-symbol "$"

View File

@ -283,7 +283,7 @@
{:content (fn []
[select-asset-bottom-sheet
clear-input!])}])
selected-networks (rf/sub [:wallet/wallet-send-selected-networks])
selected-networks (rf/sub [:wallet/wallet-send-receiver-networks])
affordable-networks (send-utils/find-affordable-networks
{:balances-per-chain token-balances-per-chain
:input-value @input-value

View File

@ -66,7 +66,7 @@
[{:keys [fetch-routes theme]}]
(let [network-details (rf/sub [:wallet/network-details])
{:keys [color]} (rf/sub [:wallet/current-viewing-account])
selected-networks (rf/sub [:wallet/wallet-send-selected-networks])
selected-networks (rf/sub [:wallet/wallet-send-receiver-networks])
prefix (rf/sub [:wallet/wallet-send-address-prefix])
prefix-seq (string/split prefix #":")
grouped-details (group-by #(contains? (set prefix-seq) (:short-name %)) network-details)

View File

@ -12,4 +12,5 @@
:button-one-label (i18n/label :t/confirm)
:on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-send-amount])
(rf/dispatch [:navigate-back]))}])

View File

@ -81,9 +81,9 @@
:-> :address-prefix)
(rf/reg-sub
:wallet/wallet-send-selected-networks
:wallet/wallet-send-receiver-networks
:<- [:wallet/wallet-send]
:-> :selected-networks)
:-> :receiver-networks)
(rf/reg-sub
:wallet/wallet-send-route