progress on getsuggestedroutes cleanup

This commit is contained in:
Brian Sztamfater 2024-11-09 21:41:09 +03:00
parent 47c2c3653f
commit 327fa1e47e
No known key found for this signature in database
GPG Key ID: 59EB921E0706B48F
4 changed files with 56 additions and 96 deletions

View File

@ -411,11 +411,13 @@
(fn [{:keys [db]} [{:keys [amount amount-out updated-token] :as args :or {amount-out "0"}}]] (fn [{:keys [db]} [{:keys [amount amount-out updated-token] :as args :or {amount-out "0"}}]]
(let [wallet-address (get-in db [:wallet :current-viewing-account-address]) (let [wallet-address (get-in db [:wallet :current-viewing-account-address])
{:keys [token tx-type collectible to-address {:keys [token tx-type collectible to-address
receiver-networks disabled-from-chain-ids network 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])
network-chain-id (:chain-id network)
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?]) test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
networks (get-in db [:wallet :networks (if test-networks-enabled? :test :prod)]) networks (get-in db
[:wallet :networks
(if test-networks-enabled? :test :prod)])
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)
@ -425,57 +427,17 @@
amount-in (to-hex amount) amount-in (to-hex amount)
amount-out (to-hex amount-out) amount-out (to-hex amount-out)
from-address wallet-address from-address wallet-address
disabled-to-chain-ids (if (= tx-type :tx/bridge) disabled-from-chain-ids (filter #(not= % network-chain-id) network-chain-ids)
(filter #(not= % bridge-to-chain-id) network-chain-ids) disabled-to-chain-ids (filter #(not= %
(filter (fn [chain-id] (if (= tx-type :tx/bridge)
(not (some #(= chain-id %) bridge-to-chain-id
receiver-networks))) network-chain-id))
network-chain-ids)) network-chain-ids)
from-locked-amount (update-vals from-locked-amounts to-hex)
send-type (case tx-type send-type (case tx-type
:tx/collectible-erc-721 constants/send-type-erc-721-transfer :tx/collectible-erc-721 constants/send-type-erc-721-transfer
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer :tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
: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))
sender-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? 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 (map #(:chain-id %) (:supported-networks token)))
sender-network-values (when sender-token-available-networks-for-suggested-routes
(send-utils/loading-network-amounts
{:valid-networks
(if (= tx-type :tx/bridge)
(remove #(= bridge-to-chain-id %)
sender-token-available-networks-for-suggested-routes)
sender-token-available-networks-for-suggested-routes)
:disabled-chain-ids disabled-from-chain-ids
:receiver-networks receiver-networks
:token-networks-ids token-networks-ids
:tx-type tx-type
:receiver? false}))
receiver-network-values (when receiver-token-available-networks-for-suggested-routes
(send-utils/loading-network-amounts
{:valid-networks
(if (= tx-type :tx/bridge)
(filter
#(= bridge-to-chain-id %)
receiver-token-available-networks-for-suggested-routes)
receiver-token-available-networks-for-suggested-routes)
:disabled-chain-ids disabled-from-chain-ids
:receiver-networks receiver-networks
:token-networks-ids token-networks-ids
:tx-type tx-type
:receiver? true}))
params [{:uuid (str (random-uuid)) params [{:uuid (str (random-uuid))
:sendType send-type :sendType send-type
:addrFrom from-address :addrFrom from-address
@ -487,7 +449,7 @@
:disabledFromChainIDs disabled-from-chain-ids :disabledFromChainIDs disabled-from-chain-ids
:disabledToChainIDs disabled-to-chain-ids :disabledToChainIDs disabled-to-chain-ids
:gasFeeMode gas-rates :gasFeeMode gas-rates
:fromLockedAmount from-locked-amount :fromLockedAmount {}
:username (:username args) :username (:username args)
:publicKey (:publicKey args) :publicKey (:publicKey args)
:packID (:packID args)}]] :packID (:packID args)}]]
@ -496,9 +458,7 @@
[:wallet :ui :send] [:wallet :ui :send]
#(-> % #(-> %
(assoc :amount amount (assoc :amount amount
:loading-suggested-routes? true :loading-suggested-routes? true)
:sender-network-values sender-network-values
:receiver-network-values receiver-network-values)
(dissoc :network-links :skip-processing-suggested-routes?) (dissoc :network-links :skip-processing-suggested-routes?)
(cond-> token (assoc :token token)))) (cond-> token (assoc :token token))))
:json-rpc/call [{:method "wallet_getSuggestedRoutesAsync" :json-rpc/call [{:method "wallet_getSuggestedRoutesAsync"

View File

@ -158,6 +158,7 @@
{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])
network (rf/sub [:wallet/send-network])
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
@ -288,6 +289,11 @@
(fn [] (fn []
(request-fetch-routes 0)) (request-fetch-routes 0))
[send-from-locked-amounts]) [send-from-locked-amounts])
(rn/use-effect
(fn []
(when active-screen?
(request-fetch-routes 2000)))
[amount-in-crypto valid-input?])
[rn/view [rn/view
{:style style/screen {:style style/screen
:accessibility-label (str "container" :accessibility-label (str "container"
@ -315,7 +321,7 @@
conversion-rate) conversion-rate)
conversion-rate)) conversion-rate))
:hint-component [quo/network-tags :hint-component [quo/network-tags
{:networks (seq from-enabled-networks) {:networks (seq [network])
:title (i18n/label :title (i18n/label
:t/send-limit :t/send-limit
{:limit (if crypto-currency? {:limit (if crypto-currency?
@ -327,17 +333,7 @@
(controlled-input/upper-limit-bn (controlled-input/upper-limit-bn
input-state)))}) input-state)))})
:status (when (controlled-input/input-error input-state) :error)}]}] :status (when (controlled-input/input-error input-state) :error)}]}]
[routes/view (when loading-routes? [quo/text "Loading"])
{:token token-by-symbol
:send-amount-in-crypto amount-in-crypto
:valid-input? valid-input?
:token-not-supported-in-receiver-networks? unsupported-token-in-receiver?
:current-screen-id current-screen-id
:request-fetch-routes request-fetch-routes}]
(when (and (not loading-routes?)
sender-network-values
unsupported-token-in-receiver?)
[token-not-available token-symbol receiver-networks token-networks])
(when not-enough-asset? (when not-enough-asset?
[not-enough-asset]) [not-enough-asset])
(when (or (and (not no-routes-found?) (or loading-routes? route)) (when (or (and (not no-routes-found?) (or loading-routes? route))

View File

@ -15,7 +15,6 @@
balance-in-fiat :fiat} (case source balance-in-fiat :fiat} (case source
:swap :swap
(rf/sub [:wallet/swap-asset-to-pay-network-balance chain-id]) (rf/sub [:wallet/swap-asset-to-pay-network-balance chain-id])
:send
(rf/sub [:wallet/send-token-network-balance chain-id])) (rf/sub [:wallet/send-token-network-balance chain-id]))
mainnet? mainnet?
(= network-name constants/mainnet-network-name)] (= network-name constants/mainnet-network-name)]

View File

@ -54,6 +54,11 @@
:<- [:wallet/wallet-send] :<- [:wallet/wallet-send]
:-> :tx-type) :-> :tx-type)
(rf/reg-sub
:wallet/send-network
:<- [:wallet/wallet-send]
:-> :network)
(rf/reg-sub (rf/reg-sub
:wallet/sending-collectible? :wallet/sending-collectible?
:<- [:wallet/send-tx-type] :<- [:wallet/send-tx-type]