fix bridge loading state

This commit is contained in:
Brian Sztamfater 2024-11-25 18:11:39 -03:00
parent 286743816c
commit 01517645f3
No known key found for this signature in database
GPG Key ID: 59EB921E0706B48F
7 changed files with 55 additions and 56 deletions

View File

@ -436,6 +436,15 @@
:tx/collectible-erc-1155 constants/send-type-erc-1155-transfer
:tx/bridge constants/send-type-bridge
constants/send-type-transfer)
sender-network-values (when (= tx-type :tx/bridge)
(send-utils/loading-network-amounts
{:networks [network-chain-id]
:values {network-chain-id amount}
:receiver? false}))
receiver-network-values (when (= tx-type :tx/bridge)
(send-utils/loading-network-amounts
{:networks [bridge-to-chain-id]
:receiver? true}))
params [{:uuid (str (random-uuid))
:sendType send-type
:addrFrom from-address
@ -456,7 +465,9 @@
[:wallet :ui :send]
#(-> %
(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?)
(cond-> token (assoc :token token))))
:json-rpc/call [{:method "wallet_getSuggestedRoutesAsync"

View File

@ -9,7 +9,7 @@
[utils.i18n :as i18n]))
(defn view
[{:keys [loading-routes? fees]}]
[{:keys [loading-routes? bridge-tx? bridge-to-network bridge-to-value fees]}]
[rn/view {:style style/estimated-fees-container}
(when (ff/enabled? ::ff/wallet.advanced-sending)
[rn/view {:style style/estimated-fees-content-container}
@ -27,4 +27,11 @@
:status (if loading-routes? :loading :default)
:size :small
:title (i18n/label :t/max-fees)
:subtitle fees}]])
:subtitle fees}]
(when bridge-tx?
[quo/data-item
{:container-style style/bridged-to-data-item
:status (if loading-routes? :loading :default)
:size :small
:title (i18n/label :t/bridged-to {:network bridge-to-network})
:subtitle bridge-to-value}])])

View File

@ -29,7 +29,7 @@
:height 40
:background-color :transparent})
(def amount-data-item
(def bridged-to-data-item
{:flex 1
:height 40
:background-color :transparent})

View File

@ -120,6 +120,11 @@
[(:chain-id network)]])
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
tx-type (rf/sub [:wallet/wallet-send-tx-type])
bridge-to-network-details (rf/sub [:wallet/bridge-to-network-details])
receiver-network-values (rf/sub [:wallet/wallet-send-to-values-by-chain])
bridge-to-value (when (and (= tx-type :tx/bridge) receiver-network-values)
(get receiver-network-values
(:chain-id bridge-to-network-details)))
[crypto-currency?
set-crypto-currency] (rn/use-state initial-crypto-currency?)
[input-state set-input-state] (rn/use-state controlled-input/init-state)
@ -268,8 +273,7 @@
input-state)))})
:status (when (controlled-input/input-error input-state) :error)}]}]
(if (= tx-type :tx/bridge)
[routes/view
{:token token-by-symbol}]
[routes/view {:token token-by-symbol}]
[rn/view {:style {:flex 1}}])
(when not-enough-asset?
[not-enough-asset])
@ -277,7 +281,10 @@
not-enough-asset?)
[estimated-fees/view
{:loading-routes? loading-routes?
:fees fee-formatted}])
:fees fee-formatted
:bridge-tx? (= tx-type :tx/bridge)
:bridge-to-network (:full-name bridge-to-network-details)
:bridge-to-value (str bridge-to-value " " token-symbol)}])
(when show-no-routes?
[no-routes-found])
[quo/bottom-actions

View File

@ -3,6 +3,8 @@
[quo.core :as quo]
[quo.theme]
[react-native.core :as rn]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils :as common-utils]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.contexts.wallet.send.routes.style :as style]
[utils.i18n :as i18n]
@ -29,7 +31,9 @@
(= network-value-type :not-available)
:disabled
:else network-value-type)
amount-formatted (-> (rf/sub [:wallet/send-amount-fixed total-amount])
amount-formatted (-> total-amount
(common-utils/sanitized-token-amount-to-display
constants/min-token-decimals-to-display)
(str " " token-symbol))]
[rn/view
{:key (str (if receiver? "to" "from") "-" chain-id)
@ -83,12 +87,9 @@
[{:keys [token]}]
(let [theme (quo.theme/use-theme)
token-symbol (:symbol token)
loading-routes? (rf/sub
[:wallet/wallet-send-loading-suggested-routes?])
sender-network-values (rf/sub
[:wallet/wallet-send-sender-network-values])
receiver-network-values (rf/sub
[:wallet/wallet-send-receiver-network-values])
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
sender-network-values (rf/sub [:wallet/wallet-send-sender-network-values])
receiver-network-values (rf/sub [:wallet/wallet-send-receiver-network-values])
network-links (rf/sub [:wallet/wallet-send-network-links])
show-routes? (not-empty sender-network-values)]
[rn/scroll-view {:content-container-style style/routes-container}

View File

@ -229,44 +229,17 @@
safe-add-type-edit)))
(defn loading-network-amounts
[{:keys [valid-networks disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?]}]
(let [disabled-set (set disabled-chain-ids)
receiver-networks-set (set receiver-networks)
token-networks-ids-set (set token-networks-ids)
valid-networks-set (set valid-networks)
not-available-networks (if receiver?
(filter #(not (token-networks-ids-set %)) receiver-networks)
[])
not-available-networks-set (set not-available-networks)
valid-networks (-> (concat valid-networks
(when (not (and receiver? (= tx-type :tx/bridge)))
disabled-chain-ids)
(when receiver?
(filter #(not (valid-networks-set %))
not-available-networks)))
(distinct))]
(->> valid-networks
[{:keys [networks values receiver?]}]
(->> networks
(map
(fn [chain-id]
(cond->
{:chain-id chain-id
:type (cond
(contains? not-available-networks-set chain-id) :not-available
(or receiver?
(not (contains? disabled-set chain-id))) :loading
(and (not receiver?) (contains? disabled-set chain-id)) :disabled)}
(and (not receiver?) (contains? disabled-set chain-id))
(assoc :total-amount (money/bignumber "0")))))
(filter
(fn [network-amount]
(or (and receiver?
(or (= tx-type :tx/bridge)
(contains? receiver-networks-set (:chain-id network-amount))))
(not receiver?))))
(sort-by (fn [network-amount]
(get network-priority-score
(network-utils/id->network (:chain-id network-amount)))))
(vec))))
(let [network-value (when values (get values chain-id))]
(cond-> {:chain-id chain-id
:type (if network-value :default :loading)}
network-value (assoc :total-amount
(money/bignumber network-value))
(and (not network-value) (not receiver?)) (assoc :total-amount (money/bignumber "0"))))))
(vec)))
(defn network-links
[route from-values-by-chain to-values-by-chain]

View File

@ -56,12 +56,12 @@
(re-frame/reg-sub
:wallet/network-values
:<- [:wallet/wallet-send]
:<- [:wallet/send-display-token-decimals]
(fn [[{:keys [from-values-by-chain to-values-by-chain token-display-name] :as send-data} token-decimals]
(fn [{:keys [from-values-by-chain to-values-by-chain token-display-name token] :as send-data}
[_ to-values?]]
(let [network-values (if to-values? to-values-by-chain from-values-by-chain)
token-symbol (or token-display-name
(-> send-data :token :symbol))]
(-> send-data :token :symbol))
token-decimals (:decimals token)]
(reduce-kv
(fn [acc chain-id amount]
(let [network-name (network-utils/id->network chain-id)