progress on getsuggestedroutes cleanup
This commit is contained in:
parent
47c2c3653f
commit
327fa1e47e
|
@ -409,96 +409,56 @@
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/start-get-suggested-routes
|
(rf/reg-event-fx :wallet/start-get-suggested-routes
|
||||||
(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])
|
||||||
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
network-chain-id (:chain-id network)
|
||||||
networks (get-in db [:wallet :networks (if test-networks-enabled? :test :prod)])
|
test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?])
|
||||||
network-chain-ids (map :chain-id networks)
|
networks (get-in db
|
||||||
token-decimal (when token (:decimals token))
|
[:wallet :networks
|
||||||
token-id (utils/format-token-id token collectible)
|
(if test-networks-enabled? :test :prod)])
|
||||||
to-token-id ""
|
network-chain-ids (map :chain-id networks)
|
||||||
gas-rates constants/gas-rate-medium
|
token-decimal (when token (:decimals token))
|
||||||
to-hex (fn [v] (send-utils/amount-in-hex v (if token token-decimal 0)))
|
token-id (utils/format-token-id token collectible)
|
||||||
amount-in (to-hex amount)
|
to-token-id ""
|
||||||
amount-out (to-hex amount-out)
|
gas-rates constants/gas-rate-medium
|
||||||
from-address wallet-address
|
to-hex (fn [v] (send-utils/amount-in-hex v (if token token-decimal 0)))
|
||||||
disabled-to-chain-ids (if (= tx-type :tx/bridge)
|
amount-in (to-hex amount)
|
||||||
(filter #(not= % bridge-to-chain-id) network-chain-ids)
|
amount-out (to-hex amount-out)
|
||||||
(filter (fn [chain-id]
|
from-address wallet-address
|
||||||
(not (some #(= chain-id %)
|
disabled-from-chain-ids (filter #(not= % network-chain-id) network-chain-ids)
|
||||||
receiver-networks)))
|
disabled-to-chain-ids (filter #(not= %
|
||||||
network-chain-ids))
|
(if (= tx-type :tx/bridge)
|
||||||
from-locked-amount (update-vals from-locked-amounts to-hex)
|
bridge-to-chain-id
|
||||||
send-type (case tx-type
|
network-chain-id))
|
||||||
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
network-chain-ids)
|
||||||
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
send-type (case tx-type
|
||||||
:tx/bridge constants/send-type-bridge
|
:tx/collectible-erc-721 constants/send-type-erc-721-transfer
|
||||||
constants/send-type-transfer)
|
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
|
||||||
balances-per-chain (when token (:balances-per-chain token))
|
:tx/bridge constants/send-type-bridge
|
||||||
sender-token-available-networks-for-suggested-routes
|
constants/send-type-transfer)
|
||||||
(when token
|
params [{:uuid (str (random-uuid))
|
||||||
(send-utils/token-available-networks-for-suggested-routes
|
:sendType send-type
|
||||||
{:balances-per-chain balances-per-chain
|
:addrFrom from-address
|
||||||
:disabled-chain-ids disabled-from-chain-ids
|
:addrTo to-address
|
||||||
:only-with-balance? true}))
|
:amountIn amount-in
|
||||||
receiver-token-available-networks-for-suggested-routes
|
:amountOut amount-out
|
||||||
(when token
|
:tokenID token-id
|
||||||
(send-utils/token-available-networks-for-suggested-routes
|
:toTokenID to-token-id
|
||||||
{:balances-per-chain balances-per-chain
|
:disabledFromChainIDs disabled-from-chain-ids
|
||||||
:disabled-chain-ids disabled-from-chain-ids
|
:disabledToChainIDs disabled-to-chain-ids
|
||||||
:only-with-balance? false}))
|
:gasFeeMode gas-rates
|
||||||
token-networks-ids (when token (map #(:chain-id %) (:supported-networks token)))
|
:fromLockedAmount {}
|
||||||
sender-network-values (when sender-token-available-networks-for-suggested-routes
|
:username (:username args)
|
||||||
(send-utils/loading-network-amounts
|
:publicKey (:publicKey args)
|
||||||
{:valid-networks
|
:packID (:packID args)}]]
|
||||||
(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))
|
|
||||||
:sendType send-type
|
|
||||||
:addrFrom from-address
|
|
||||||
:addrTo to-address
|
|
||||||
:amountIn amount-in
|
|
||||||
:amountOut amount-out
|
|
||||||
:tokenID token-id
|
|
||||||
:toTokenID to-token-id
|
|
||||||
:disabledFromChainIDs disabled-from-chain-ids
|
|
||||||
:disabledToChainIDs disabled-to-chain-ids
|
|
||||||
:gasFeeMode gas-rates
|
|
||||||
:fromLockedAmount from-locked-amount
|
|
||||||
:username (:username args)
|
|
||||||
:publicKey (:publicKey args)
|
|
||||||
:packID (:packID args)}]]
|
|
||||||
(when (and to-address from-address amount-in token-id)
|
(when (and to-address from-address amount-in token-id)
|
||||||
{:db (update-in db
|
{:db (update-in db
|
||||||
[: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"
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -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)]
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue