fix(wallet)_: Stop route calculation (#21306)
This commit - Stops route calculation when the user - changes FROM account - changes the send (input) amount - goes back from the routes calculation page - after the transaction is successfully submitted - goes back from tx confirmation page for collectibles - Prevents the keyboard being dismissed while entering the password on the transaction confirmation page - Fixes multiple edit tiles/boxes added to receiver routes Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
parent
fdc814cdb0
commit
e0c9800751
|
@ -3,13 +3,11 @@
|
||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[status-im.contexts.wallet.bridge.input-amount.style :as style]
|
[status-im.contexts.wallet.bridge.input-amount.style :as style]
|
||||||
[status-im.contexts.wallet.send.input-amount.view :as input-amount]
|
[status-im.contexts.wallet.send.input-amount.view :as input-amount]
|
||||||
[status-im.setup.hot-reload :as hot-reload]
|
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
[]
|
[]
|
||||||
(hot-reload/use-safe-unmount #(rf/dispatch [:wallet/stop-get-suggested-routes]))
|
|
||||||
[rn/view {:style style/bridge-send-wrapper}
|
[rn/view {:style style/bridge-send-wrapper}
|
||||||
[input-amount/view
|
[input-amount/view
|
||||||
{:current-screen-id :screen/wallet.bridge-input-amount
|
{:current-screen-id :screen/wallet.bridge-input-amount
|
||||||
|
@ -23,5 +21,6 @@
|
||||||
{:amount amount
|
{:amount amount
|
||||||
:stack-id :screen/wallet.bridge-input-amount}]))
|
:stack-id :screen/wallet.bridge-input-amount}]))
|
||||||
:on-navigate-back (fn []
|
:on-navigate-back (fn []
|
||||||
|
(rf/dispatch-sync [:wallet/stop-and-clean-suggested-routes])
|
||||||
(rf/dispatch [:wallet/clean-disabled-from-networks])
|
(rf/dispatch [:wallet/clean-disabled-from-networks])
|
||||||
(rf/dispatch [:wallet/clean-send-amount]))}]])
|
(rf/dispatch [:wallet/clean-send-amount]))}]])
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
(fn [{:keys [db]} [tab]]
|
(fn [{:keys [db]} [tab]]
|
||||||
{:db (assoc-in db [:wallet :ui :send :select-address-tab] tab)}))
|
{:db (assoc-in db [:wallet :ui :send :select-address-tab] tab)}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx :wallet/stop-and-clean-suggested-routes
|
||||||
|
(fn []
|
||||||
|
{:fx [[:dispatch [:wallet/stop-get-suggested-routes]]
|
||||||
|
[:dispatch [:wallet/clean-suggested-routes]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/suggested-routes-success
|
(rf/reg-event-fx :wallet/suggested-routes-success
|
||||||
(fn [{:keys [db]} [suggested-routes-data]]
|
(fn [{:keys [db]} [suggested-routes-data]]
|
||||||
(let [chosen-route (:best suggested-routes-data)
|
(let [chosen-route (:best suggested-routes-data)
|
||||||
|
@ -77,7 +82,8 @@
|
||||||
(send-utils/reset-loading-network-amounts-to-zero
|
(send-utils/reset-loading-network-amounts-to-zero
|
||||||
receiver-network-values)
|
receiver-network-values)
|
||||||
|
|
||||||
(not= tx-type :tx/bridge) (conj {:type :edit})))
|
(not= tx-type :tx/bridge)
|
||||||
|
send-utils/safe-add-type-edit))
|
||||||
network-links (when routes-available?
|
network-links (when routes-available?
|
||||||
(send-utils/network-links chosen-route
|
(send-utils/network-links chosen-route
|
||||||
sender-network-values
|
sender-network-values
|
||||||
|
@ -112,21 +118,6 @@
|
||||||
:type :negative
|
:type :negative
|
||||||
:text error-message}]]]})))
|
:text error-message}]]]})))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/clean-suggested-routes
|
|
||||||
(fn [{:keys [db]}]
|
|
||||||
{:db (update-in db
|
|
||||||
[:wallet :ui :send]
|
|
||||||
dissoc
|
|
||||||
:suggested-routes
|
|
||||||
:route
|
|
||||||
:amount
|
|
||||||
:from-values-by-chain
|
|
||||||
:to-values-by-chain
|
|
||||||
:sender-network-values
|
|
||||||
:receiver-network-values
|
|
||||||
:network-links
|
|
||||||
:loading-suggested-routes?)}))
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/clean-send-address
|
(rf/reg-event-fx :wallet/clean-send-address
|
||||||
(fn [{:keys [db]}]
|
(fn [{:keys [db]}]
|
||||||
{:db (update-in db [:wallet :ui :send] dissoc :recipient :to-address)}))
|
{:db (update-in db [:wallet :ui :send] dissoc :recipient :to-address)}))
|
||||||
|
@ -211,7 +202,7 @@
|
||||||
:token-display-name (:symbol token-data)))
|
:token-display-name (:symbol token-data)))
|
||||||
unique-owner (assoc-in [:wallet :current-viewing-account-address] unique-owner)
|
unique-owner (assoc-in [:wallet :current-viewing-account-address] unique-owner)
|
||||||
entry-point (assoc-in [:wallet :ui :send :entry-point] entry-point))
|
entry-point (assoc-in [:wallet :ui :send :entry-point] entry-point))
|
||||||
:fx [[:dispatch [:wallet/clean-suggested-routes]]
|
:fx [[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||||
[:dispatch
|
[:dispatch
|
||||||
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
;; ^:flush-dom allows us to make sure the re-frame DB state is always synced
|
||||||
;; before the navigation occurs, so the new screen is always rendered with
|
;; before the navigation occurs, so the new screen is always rendered with
|
||||||
|
@ -238,7 +229,7 @@
|
||||||
(assoc-in [:wallet :ui :send :token-not-supported-in-receiver-networks?]
|
(assoc-in [:wallet :ui :send :token-not-supported-in-receiver-networks?]
|
||||||
token-not-supported-in-receiver-networks?))
|
token-not-supported-in-receiver-networks?))
|
||||||
:fx [[:dispatch [:hide-bottom-sheet]]
|
:fx [[:dispatch [:hide-bottom-sheet]]
|
||||||
[:dispatch [:wallet/clean-suggested-routes]]
|
[:dispatch [:wallet/stop-and-clean-suggested-routes]]
|
||||||
[:dispatch [:wallet/clean-from-locked-amounts]]]})))
|
[:dispatch [:wallet/clean-from-locked-amounts]]]})))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/clean-selected-token
|
(rf/reg-event-fx :wallet/clean-selected-token
|
||||||
|
@ -340,11 +331,11 @@
|
||||||
{:db (update-in db [:wallet :ui :send] dissoc :bridge-to-chain-id)}))
|
{:db (update-in db [:wallet :ui :send] dissoc :bridge-to-chain-id)}))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/clean-routes-calculation
|
:wallet/clean-suggested-routes
|
||||||
(fn [{:keys [db]}]
|
(fn [{:keys [db]}]
|
||||||
(let [keys-to-remove [:to-values-by-chain :network-links :sender-network-values :route
|
(let [keys-to-remove [:to-values-by-chain :network-links :sender-network-values :route
|
||||||
:receiver-network-values :suggested-routes :from-values-by-chain
|
:receiver-network-values :suggested-routes :from-values-by-chain
|
||||||
:loading-suggested-routes?]]
|
:loading-suggested-routes? :amount]]
|
||||||
{:db (update-in db [:wallet :ui :send] #(apply dissoc % keys-to-remove))})))
|
{:db (update-in db [:wallet :ui :send] #(apply dissoc % keys-to-remove))})))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/disable-from-networks
|
(rf/reg-event-fx :wallet/disable-from-networks
|
||||||
|
@ -472,7 +463,7 @@
|
||||||
:loading-suggested-routes? true
|
:loading-suggested-routes? true
|
||||||
:sender-network-values sender-network-values
|
:sender-network-values sender-network-values
|
||||||
:receiver-network-values receiver-network-values)
|
:receiver-network-values receiver-network-values)
|
||||||
(dissoc :network-links)
|
(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"
|
||||||
:params params
|
:params params
|
||||||
|
@ -484,14 +475,17 @@
|
||||||
:params params}))}]}))))
|
:params params}))}]}))))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/stop-get-suggested-routes
|
(rf/reg-event-fx :wallet/stop-get-suggested-routes
|
||||||
(fn []
|
(fn [{:keys [db]}]
|
||||||
{:fx [[:dispatch [:wallet/clean-routes-calculation]]]
|
;; Adding a key to prevent processing route signals in the client until the routes generation is
|
||||||
:json-rpc/call [{:method "wallet_stopSuggestedRoutesAsyncCalculation"
|
;; stopped. This is to ensure no route signals are processed when we make the RPC call
|
||||||
:params []
|
{:db (assoc-in db [:wallet :ui :send :skip-processing-suggested-routes?] true)
|
||||||
:on-error (fn [error]
|
:fx [[:json-rpc/call
|
||||||
(log/error "failed to stop suggested routes calculation"
|
[{:method "wallet_stopSuggestedRoutesAsyncCalculation"
|
||||||
{:event :wallet/stop-get-suggested-routes
|
:params []
|
||||||
:error error}))}]}))
|
:on-error (fn [error]
|
||||||
|
(log/error "failed to stop suggested routes calculation"
|
||||||
|
{:event :wallet/stop-get-suggested-routes
|
||||||
|
:error error}))}]]]}))
|
||||||
|
|
||||||
(defn- bridge-amount-greater-than-bonder-fees?
|
(defn- bridge-amount-greater-than-bonder-fees?
|
||||||
[{{token-decimals :decimals} :from-token
|
[{{token-decimals :decimals} :from-token
|
||||||
|
@ -519,14 +513,21 @@
|
||||||
:wallet/handle-suggested-routes
|
:wallet/handle-suggested-routes
|
||||||
(fn [{:keys [db]} [data]]
|
(fn [{:keys [db]} [data]]
|
||||||
(let [swap? (get-in db [:wallet :ui :swap])
|
(let [swap? (get-in db [:wallet :ui :swap])
|
||||||
{:keys [code details] :as error-response} (-> data :ErrorResponse)]
|
{:keys [code details] :as error-response} (-> data :ErrorResponse)
|
||||||
|
skip-processing-suggested-routes? (get-in db
|
||||||
|
[:wallet :ui :send
|
||||||
|
:skip-processing-suggested-routes?])
|
||||||
|
process-response? (and (not swap?)
|
||||||
|
(not skip-processing-suggested-routes?))]
|
||||||
(if (and (not swap?) error-response)
|
(if (and (not swap?) error-response)
|
||||||
(let [error-message (if (= code "0") "An error occurred" details)]
|
(let [error-message (if (= code "0") "An error occurred" details)]
|
||||||
(log/error "failed to get suggested routes (async)"
|
(log/error "failed to get suggested routes (async)"
|
||||||
{:event :wallet/handle-suggested-routes
|
{:event :wallet/handle-suggested-routes
|
||||||
:error error-message})
|
:error error-message})
|
||||||
{:fx [(if swap?
|
{:fx [(cond
|
||||||
|
swap?
|
||||||
[:dispatch [:wallet/swap-proposal-error error-message]]
|
[:dispatch [:wallet/swap-proposal-error error-message]]
|
||||||
|
process-response?
|
||||||
[:dispatch [:wallet/suggested-routes-error error-message]])]})
|
[:dispatch [:wallet/suggested-routes-error error-message]])]})
|
||||||
(let [best-routes-fix (comp ->old-route-paths
|
(let [best-routes-fix (comp ->old-route-paths
|
||||||
remove-invalid-bonder-fees-routes
|
remove-invalid-bonder-fees-routes
|
||||||
|
@ -537,8 +538,10 @@
|
||||||
(data-store/rpc->suggested-routes)
|
(data-store/rpc->suggested-routes)
|
||||||
(update :best best-routes-fix)
|
(update :best best-routes-fix)
|
||||||
(update :candidates candidates-fix))]
|
(update :candidates candidates-fix))]
|
||||||
{:fx [(if swap?
|
{:fx [(cond
|
||||||
|
swap?
|
||||||
[:dispatch [:wallet/swap-proposal-success routes]]
|
[:dispatch [:wallet/swap-proposal-success routes]]
|
||||||
|
process-response?
|
||||||
[:dispatch [:wallet/suggested-routes-success routes]])]})))))
|
[:dispatch [:wallet/suggested-routes-success routes]])]})))))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/add-authorized-transaction
|
(rf/reg-event-fx :wallet/add-authorized-transaction
|
||||||
|
@ -552,7 +555,11 @@
|
||||||
(assoc-in [:wallet :ui :send :just-completed-transaction?] true)
|
(assoc-in [:wallet :ui :send :just-completed-transaction?] true)
|
||||||
(assoc-in [:wallet :transactions] transaction-details)
|
(assoc-in [:wallet :transactions] transaction-details)
|
||||||
(assoc-in [:wallet :ui :send :transaction-ids] transaction-ids))
|
(assoc-in [:wallet :ui :send :transaction-ids] transaction-ids))
|
||||||
:fx [[:dispatch
|
:fx [;; Remove wallet/stop-and-clean-suggested-routes event when we move to new transaction
|
||||||
|
;; submission process as the routes as stopped by status-go
|
||||||
|
[:dispatch
|
||||||
|
[:wallet/stop-and-clean-suggested-routes]]
|
||||||
|
[:dispatch
|
||||||
[:wallet/end-transaction-flow]]
|
[:wallet/end-transaction-flow]]
|
||||||
[:dispatch-later
|
[:dispatch-later
|
||||||
[{:ms 2000
|
[{:ms 2000
|
||||||
|
@ -704,17 +711,21 @@
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/transaction-confirmation-navigate-back
|
:wallet/transaction-confirmation-navigate-back
|
||||||
(fn [{db :db} [{:keys []}]]
|
(fn [{db :db}]
|
||||||
(let [tx-type (-> db :wallet :ui :send :tx-type)
|
(let [tx-type (-> db :wallet :ui :send :tx-type)
|
||||||
keep-tx-data? (#{:account-collectible-tab :wallet-stack}
|
keep-tx-data? (#{:account-collectible-tab :wallet-stack}
|
||||||
(-> db :wallet :ui :send :entry-point))]
|
(-> db :wallet :ui :send :entry-point))
|
||||||
|
delete-data-for-erc-721-tx? (and (= tx-type :tx/collectible-erc-721) (not keep-tx-data?))
|
||||||
|
erc-1155-tx? (= tx-type :tx/collectible-erc-1155)]
|
||||||
{:db (cond-> db
|
{:db (cond-> db
|
||||||
(and (= tx-type :tx/collectible-erc-721) (not keep-tx-data?))
|
delete-data-for-erc-721-tx?
|
||||||
(update-in [:wallet :ui :send] dissoc :tx-type :amount :route :suggested-routes)
|
(update-in [:wallet :ui :send] dissoc :tx-type :amount :route :suggested-routes)
|
||||||
|
|
||||||
(= tx-type :tx/collectible-erc-1155)
|
erc-1155-tx?
|
||||||
(update-in [:wallet :ui :send] dissoc :route :suggested-routes))
|
(update-in [:wallet :ui :send] dissoc :route :suggested-routes))
|
||||||
:fx [[:dispatch [:navigate-back]]]})))
|
:fx [(when (or delete-data-for-erc-721-tx? erc-1155-tx?)
|
||||||
|
[:dispatch [:wallet/stop-and-clean-suggested-routes]])
|
||||||
|
[:dispatch [:navigate-back]]]})))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/collectible-amount-navigate-back
|
:wallet/collectible-amount-navigate-back
|
||||||
|
|
|
@ -269,25 +269,6 @@
|
||||||
:amount 10}}}})
|
:amount 10}}}})
|
||||||
(is (match-strict? expected-db (:db (dispatch [event-id]))))))
|
(is (match-strict? expected-db (:db (dispatch [event-id]))))))
|
||||||
|
|
||||||
(h/deftest-event :wallet/clean-suggested-routes
|
|
||||||
[event-id dispatch]
|
|
||||||
(let [expected-db {:wallet {:ui {:send {:other-props :value}}}}]
|
|
||||||
(reset! rf-db/app-db
|
|
||||||
{:wallet {:ui {:send
|
|
||||||
{:other-props :value
|
|
||||||
:suggested-routes ["1" "2"]
|
|
||||||
:route "1"
|
|
||||||
:amount 10
|
|
||||||
:from-values-by-chain [{:chain-id 1} {:chain-id 10} {:chain-id 42161}]
|
|
||||||
:to-values-by-chain [{:chain-id 1} {:chain-id 10} {:chain-id 42161}]
|
|
||||||
:sender-network-values [:eth :arb1]
|
|
||||||
:receiver-network-values [:eth :arb1]
|
|
||||||
:network-links [{:from-chain-id 1
|
|
||||||
:to-chain-id 10
|
|
||||||
:position-diff 1}]
|
|
||||||
:loading-suggested-routes? false}}}})
|
|
||||||
(is (match-strict? expected-db (:db (dispatch [event-id]))))))
|
|
||||||
|
|
||||||
(h/deftest-event :wallet/suggested-routes-error
|
(h/deftest-event :wallet/suggested-routes-error
|
||||||
[event-id dispatch]
|
[event-id dispatch]
|
||||||
(let [sender-network-amounts [{:chain-id 1 :total-amount (money/bignumber "100") :type :loading}
|
(let [sender-network-amounts [{:chain-id 1 :total-amount (money/bignumber "100") :type :loading}
|
||||||
|
@ -545,7 +526,8 @@
|
||||||
(send-utils/reset-loading-network-amounts-to-zero
|
(send-utils/reset-loading-network-amounts-to-zero
|
||||||
receiver-network-values)
|
receiver-network-values)
|
||||||
|
|
||||||
(not= tx-type :tx/bridge) (conj {:type :edit})))
|
(not= tx-type :tx/bridge)
|
||||||
|
send-utils/safe-add-type-edit))
|
||||||
sender-network-values (if routes-available?
|
sender-network-values (if routes-available?
|
||||||
(send-utils/network-amounts
|
(send-utils/network-amounts
|
||||||
{:network-values
|
{:network-values
|
||||||
|
@ -610,7 +592,9 @@
|
||||||
:transactions (send-utils/map-multitransaction-by-ids
|
:transactions (send-utils/map-multitransaction-by-ids
|
||||||
transaction-id
|
transaction-id
|
||||||
hashes)}}
|
hashes)}}
|
||||||
:fx [[:dispatch [:wallet/end-transaction-flow]]
|
:fx [[:dispatch
|
||||||
|
[:wallet/stop-and-clean-suggested-routes]]
|
||||||
|
[:dispatch [:wallet/end-transaction-flow]]
|
||||||
[:dispatch-later
|
[:dispatch-later
|
||||||
[{:ms 2000
|
[{:ms 2000
|
||||||
:dispatch [:wallet/clean-just-completed-transaction]}]]]}]
|
:dispatch [:wallet/clean-just-completed-transaction]}]]]}]
|
||||||
|
|
|
@ -126,14 +126,19 @@
|
||||||
{:content buy-token/view}])}])
|
{:content buy-token/view}])}])
|
||||||
|
|
||||||
(defn- fetch-routes
|
(defn- fetch-routes
|
||||||
[{:keys [amount bounce-duration-ms token valid-input?]}]
|
[{:keys [amount bounce-duration-ms token valid-input? reset-amounts-to-zero?]}]
|
||||||
(if valid-input?
|
(cond
|
||||||
|
valid-input?
|
||||||
(debounce/debounce-and-dispatch
|
(debounce/debounce-and-dispatch
|
||||||
[:wallet/start-get-suggested-routes
|
[:wallet/start-get-suggested-routes
|
||||||
{:amount amount
|
{:amount amount
|
||||||
:updated-token token}]
|
:updated-token token}]
|
||||||
bounce-duration-ms)
|
bounce-duration-ms)
|
||||||
(rf/dispatch [:wallet/clean-suggested-routes])))
|
|
||||||
|
reset-amounts-to-zero?
|
||||||
|
(rf/dispatch [:wallet/reset-network-amounts-to-zero])
|
||||||
|
|
||||||
|
:else (rf/dispatch [:wallet/stop-and-clean-suggested-routes])))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed
|
;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed
|
||||||
|
@ -149,147 +154,152 @@
|
||||||
enabled-from-chain-ids :enabled-from-chain-ids
|
enabled-from-chain-ids :enabled-from-chain-ids
|
||||||
from-enabled-networks :from-enabled-networks
|
from-enabled-networks :from-enabled-networks
|
||||||
:or {initial-crypto-currency? true}}]
|
:or {initial-crypto-currency? true}}]
|
||||||
(let [_ (rn/dismiss-keyboard!)
|
(let [view-id (rf/sub [:view-id])
|
||||||
bottom (safe-area/get-bottom)
|
active-screen? (= view-id current-screen-id)
|
||||||
[crypto-currency? set-crypto-currency] (rn/use-state initial-crypto-currency?)
|
bottom (safe-area/get-bottom)
|
||||||
on-navigate-back on-navigate-back
|
[crypto-currency? set-crypto-currency] (rn/use-state initial-crypto-currency?)
|
||||||
|
on-navigate-back on-navigate-back
|
||||||
[just-toggled-mode? set-just-toggled-mode?] (rn/use-state false)
|
handle-on-confirm (fn [amount]
|
||||||
handle-on-confirm (fn [amount]
|
(rf/dispatch [:wallet/set-token-amount-to-send
|
||||||
(rf/dispatch [:wallet/set-token-amount-to-send
|
{:amount amount
|
||||||
{:amount amount
|
:stack-id current-screen-id}]))
|
||||||
:stack-id current-screen-id}]))
|
{fiat-currency :currency} (rf/sub [:profile/profile])
|
||||||
{fiat-currency :currency} (rf/sub [:profile/profile])
|
|
||||||
{token-symbol :symbol
|
{token-symbol :symbol
|
||||||
token-networks :networks
|
token-networks :networks
|
||||||
:as
|
:as
|
||||||
token} (rf/sub [:wallet/wallet-send-token])
|
token} (rf/sub [:wallet/wallet-send-token])
|
||||||
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
|
||||||
(str token-symbol)
|
(str token-symbol)
|
||||||
enabled-from-chain-ids])
|
enabled-from-chain-ids])
|
||||||
token-balance (or default-limit-crypto total-balance)
|
token-balance (or default-limit-crypto total-balance)
|
||||||
usd-conversion-rate (utils/token-usd-price token)
|
usd-conversion-rate (utils/token-usd-price token)
|
||||||
currency (rf/sub [:profile/currency])
|
currency (rf/sub [:profile/currency])
|
||||||
conversion-rate (-> token
|
conversion-rate (-> token
|
||||||
:market-values-per-currency
|
:market-values-per-currency
|
||||||
currency
|
currency
|
||||||
:price)
|
:price)
|
||||||
token-decimals (-> token
|
token-decimals (-> token
|
||||||
utils/token-usd-price
|
utils/token-usd-price
|
||||||
utils/one-cent-value
|
utils/one-cent-value
|
||||||
utils/calc-max-crypto-decimals)
|
utils/calc-max-crypto-decimals)
|
||||||
[input-state set-input-state] (rn/use-state controlled-input/init-state)
|
[input-state set-input-state] (rn/use-state controlled-input/init-state)
|
||||||
clear-input! #(set-input-state controlled-input/delete-all)
|
clear-input! #(set-input-state controlled-input/delete-all)
|
||||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||||
loading-routes? (rf/sub
|
loading-routes? (rf/sub
|
||||||
[:wallet/wallet-send-loading-suggested-routes?])
|
[:wallet/wallet-send-loading-suggested-routes?])
|
||||||
route (rf/sub [:wallet/wallet-send-route])
|
route (rf/sub [:wallet/wallet-send-route])
|
||||||
on-confirm (or default-on-confirm handle-on-confirm)
|
on-confirm (or default-on-confirm handle-on-confirm)
|
||||||
crypto-decimals (or token-decimals default-crypto-decimals)
|
crypto-decimals (or token-decimals default-crypto-decimals)
|
||||||
max-limit (if crypto-currency?
|
max-limit (if crypto-currency?
|
||||||
(utils/cut-crypto-decimals-to-fit-usd-cents
|
(utils/cut-crypto-decimals-to-fit-usd-cents
|
||||||
token-balance
|
token-balance
|
||||||
usd-conversion-rate)
|
usd-conversion-rate)
|
||||||
(-> (money/crypto->fiat
|
(-> (money/crypto->fiat
|
||||||
token-balance
|
token-balance
|
||||||
conversion-rate)
|
conversion-rate)
|
||||||
utils/cut-fiat-balance-to-two-decimals))
|
utils/cut-fiat-balance-to-two-decimals))
|
||||||
input-value (controlled-input/input-value input-state)
|
input-value (controlled-input/input-value input-state)
|
||||||
valid-input? (not (or (controlled-input/empty-value? input-state)
|
valid-input? (not (or (controlled-input/empty-value? input-state)
|
||||||
(controlled-input/input-error input-state)))
|
(controlled-input/input-error input-state)))
|
||||||
confirm-disabled? (or (nil? route)
|
confirm-disabled? (or (nil? route)
|
||||||
(empty? route)
|
(empty? route)
|
||||||
(not valid-input?))
|
(not valid-input?))
|
||||||
amount-in-crypto (if crypto-currency?
|
amount-in-crypto (if crypto-currency?
|
||||||
input-value
|
input-value
|
||||||
(number/remove-trailing-zeroes
|
(number/remove-trailing-zeroes
|
||||||
(.toFixed (/ input-value conversion-rate)
|
(.toFixed (/ input-value conversion-rate)
|
||||||
crypto-decimals)))
|
crypto-decimals)))
|
||||||
total-amount-receiver (rf/sub [:wallet/total-amount true])
|
total-amount-receiver (rf/sub [:wallet/total-amount true])
|
||||||
amount-text (str (number/remove-trailing-zeroes
|
amount-text (str (number/remove-trailing-zeroes
|
||||||
(.toFixed total-amount-receiver
|
(.toFixed total-amount-receiver
|
||||||
(min token-decimals 6)))
|
(min token-decimals 6)))
|
||||||
" "
|
" "
|
||||||
token-symbol)
|
token-symbol)
|
||||||
first-route (first route)
|
first-route (first route)
|
||||||
native-currency-symbol (when-not confirm-disabled?
|
native-currency-symbol (when-not confirm-disabled?
|
||||||
(get-in first-route
|
(get-in first-route
|
||||||
[:from :native-currency-symbol]))
|
[:from :native-currency-symbol]))
|
||||||
fee-formatted (when native-currency-symbol
|
fee-formatted (when native-currency-symbol
|
||||||
(rf/sub [:wallet/wallet-send-fee-fiat-formatted
|
(rf/sub [:wallet/wallet-send-fee-fiat-formatted
|
||||||
native-currency-symbol]))
|
native-currency-symbol]))
|
||||||
show-select-asset-sheet #(rf/dispatch
|
show-select-asset-sheet #(rf/dispatch
|
||||||
[:show-bottom-sheet
|
[:show-bottom-sheet
|
||||||
{:content (fn []
|
{:content (fn []
|
||||||
[select-asset-bottom-sheet
|
[select-asset-bottom-sheet
|
||||||
clear-input!])}])
|
clear-input!])}])
|
||||||
sender-network-values (rf/sub
|
sender-network-values (rf/sub
|
||||||
[:wallet/wallet-send-sender-network-values])
|
[:wallet/wallet-send-sender-network-values])
|
||||||
receiver-network-values (rf/sub
|
receiver-network-values (rf/sub
|
||||||
[:wallet/wallet-send-receiver-network-values])
|
[:wallet/wallet-send-receiver-network-values])
|
||||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
||||||
token-not-supported-in-receiver-networks? (and (not= tx-type :tx/bridge)
|
token-not-supported-in-receiver-networks? (and (not= tx-type :tx/bridge)
|
||||||
(->> receiver-network-values
|
(->> receiver-network-values
|
||||||
(remove #(= (:type %) :add))
|
(remove #(= (:type %) :add))
|
||||||
(every? #(= (:type %) :not-available))))
|
(every? #(= (:type %) :not-available))))
|
||||||
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
||||||
routes (when suggested-routes
|
routes (when suggested-routes
|
||||||
(or (:best suggested-routes) []))
|
(or (:best suggested-routes) []))
|
||||||
no-routes-found? (and
|
no-routes-found? (and
|
||||||
(every-network-value-is-zero?
|
(every-network-value-is-zero?
|
||||||
sender-network-values)
|
sender-network-values)
|
||||||
(not (nil? routes))
|
(not (nil? routes))
|
||||||
(not loading-routes?)
|
(not loading-routes?)
|
||||||
(not token-not-supported-in-receiver-networks?))
|
(not token-not-supported-in-receiver-networks?))
|
||||||
receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
||||||
receiver-preferred-networks (rf/sub
|
receiver-preferred-networks (rf/sub
|
||||||
[:wallet/wallet-send-receiver-preferred-networks])
|
[:wallet/wallet-send-receiver-preferred-networks])
|
||||||
receiver-preferred-networks-set (set receiver-preferred-networks)
|
receiver-preferred-networks-set (set receiver-preferred-networks)
|
||||||
sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network]
|
sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network]
|
||||||
(contains?
|
(contains?
|
||||||
receiver-preferred-networks-set
|
receiver-preferred-networks-set
|
||||||
receiver-selected-network))
|
receiver-selected-network))
|
||||||
receiver-networks))
|
receiver-networks))
|
||||||
input-error (controlled-input/input-error input-state)
|
input-error (controlled-input/input-error input-state)
|
||||||
limit-insufficient? (controlled-input/upper-limit-exceeded? input-state)
|
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||||
should-try-again? (and (not limit-insufficient?) no-routes-found?)
|
should-try-again? (and (not limit-exceeded?) no-routes-found?)
|
||||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||||
(string/upper-case
|
(string/upper-case
|
||||||
constants/mainnet-short-name)
|
constants/mainnet-short-name)
|
||||||
enabled-from-chain-ids])
|
enabled-from-chain-ids])
|
||||||
not-enough-asset? (and
|
not-enough-asset? (and
|
||||||
(or no-routes-found? limit-insufficient?)
|
(or no-routes-found? limit-exceeded?)
|
||||||
(not-empty sender-network-values)
|
(not-empty sender-network-values)
|
||||||
(if (= token-symbol
|
(if (= token-symbol
|
||||||
(string/upper-case
|
(string/upper-case
|
||||||
constants/mainnet-short-name))
|
constants/mainnet-short-name))
|
||||||
(money/equal-to
|
(money/equal-to
|
||||||
(controlled-input/value-bn input-state)
|
(controlled-input/value-bn input-state)
|
||||||
(controlled-input/upper-limit-bn input-state))
|
(controlled-input/upper-limit-bn input-state))
|
||||||
(money/equal-to (:total-balance
|
(money/equal-to (:total-balance
|
||||||
owned-eth-token)
|
owned-eth-token)
|
||||||
0)))
|
0)))
|
||||||
show-no-routes? (and
|
show-no-routes? (and
|
||||||
(or no-routes-found? limit-insufficient?)
|
(or no-routes-found? limit-exceeded?)
|
||||||
(not-empty sender-network-values)
|
(not-empty sender-network-values)
|
||||||
(not not-enough-asset?))
|
(not not-enough-asset?))
|
||||||
request-fetch-routes (fn [bounce-duration-ms]
|
request-fetch-routes (fn [bounce-duration-ms]
|
||||||
(fetch-routes
|
(fetch-routes
|
||||||
{:amount amount-in-crypto
|
{:amount amount-in-crypto
|
||||||
:valid-input? valid-input?
|
:valid-input? valid-input?
|
||||||
:bounce-duration-ms bounce-duration-ms
|
:bounce-duration-ms bounce-duration-ms
|
||||||
:token token}))
|
:token token
|
||||||
swap-between-fiat-and-crypto (fn []
|
:reset-amounts-to-zero? (and limit-exceeded?
|
||||||
(set-just-toggled-mode? true)
|
(some? routes))}))
|
||||||
(if crypto-currency?
|
swap-between-fiat-and-crypto (fn []
|
||||||
(set-input-state
|
(if crypto-currency?
|
||||||
#(controlled-input/->fiat % conversion-rate))
|
(set-input-state
|
||||||
(set-input-state
|
#(controlled-input/->fiat % conversion-rate))
|
||||||
#(controlled-input/->crypto % conversion-rate)))
|
(set-input-state
|
||||||
(set-crypto-currency (not crypto-currency?)))]
|
#(controlled-input/->crypto % conversion-rate)))
|
||||||
|
(set-crypto-currency (not crypto-currency?)))]
|
||||||
|
(rn/use-effect
|
||||||
|
(fn []
|
||||||
|
(when active-screen?
|
||||||
|
(rn/dismiss-keyboard!)))
|
||||||
|
[active-screen?])
|
||||||
(rn/use-mount
|
(rn/use-mount
|
||||||
(fn []
|
(fn []
|
||||||
(let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!))
|
(let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!))
|
||||||
|
@ -302,13 +312,15 @@
|
||||||
[max-limit])
|
[max-limit])
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
(when input-error (debounce/clear-all))
|
(when input-error
|
||||||
(when (and limit-insufficient? routes) (rf/dispatch [:wallet/reset-network-amounts-to-zero])))
|
(rf/dispatch [:wallet/stop-get-suggested-routes])
|
||||||
|
(debounce/clear-all)))
|
||||||
[input-error])
|
[input-error])
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
(clear-input!)
|
(clear-input!)
|
||||||
(rf/dispatch [:wallet/clean-suggested-routes]))
|
(rf/dispatch [:wallet/stop-and-clean-suggested-routes])
|
||||||
|
(rf/dispatch [:wallet/clean-disabled-from-networks]))
|
||||||
[current-address])
|
[current-address])
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
|
@ -358,7 +370,6 @@
|
||||||
:send-amount-in-crypto amount-in-crypto
|
:send-amount-in-crypto amount-in-crypto
|
||||||
:valid-input? valid-input?
|
:valid-input? valid-input?
|
||||||
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
||||||
:lock-fetch-routes? just-toggled-mode?
|
|
||||||
:current-screen-id current-screen-id
|
:current-screen-id current-screen-id
|
||||||
:request-fetch-routes request-fetch-routes}]
|
:request-fetch-routes request-fetch-routes}]
|
||||||
(when (and (not loading-routes?)
|
(when (and (not loading-routes?)
|
||||||
|
@ -403,16 +414,13 @@
|
||||||
regex (re-pattern regex-pattern)]
|
regex (re-pattern regex-pattern)]
|
||||||
(when (re-matches regex new-text)
|
(when (re-matches regex new-text)
|
||||||
(debounce/clear-all)
|
(debounce/clear-all)
|
||||||
(set-just-toggled-mode? false)
|
|
||||||
(set-input-state #(controlled-input/add-character % c)))))
|
(set-input-state #(controlled-input/add-character % c)))))
|
||||||
:on-delete (fn []
|
:on-delete (fn []
|
||||||
(debounce/clear-all)
|
(debounce/clear-all)
|
||||||
(set-just-toggled-mode? false)
|
|
||||||
(set-input-state controlled-input/delete-last)
|
(set-input-state controlled-input/delete-last)
|
||||||
(rf/dispatch [:wallet/clean-suggested-routes]))
|
(rf/dispatch-sync [:wallet/stop-and-clean-suggested-routes]))
|
||||||
:on-long-press-delete (fn []
|
:on-long-press-delete (fn []
|
||||||
(debounce/clear-all)
|
(debounce/clear-all)
|
||||||
(set-just-toggled-mode? false)
|
|
||||||
(set-input-state controlled-input/delete-all)
|
(set-input-state controlled-input/delete-all)
|
||||||
(rf/dispatch [:wallet/clean-suggested-routes]))}]]))
|
(rf/dispatch-sync [:wallet/stop-and-clean-suggested-routes]))}]]))
|
||||||
|
|
||||||
|
|
|
@ -335,8 +335,7 @@
|
||||||
:text (i18n/label :t/at-least-one-network-must-be-activated)}]))))
|
:text (i18n/label :t/at-least-one-network-must-be-activated)}]))))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
[{:keys [token theme valid-input? request-fetch-routes
|
[{:keys [token theme valid-input? request-fetch-routes on-press-to-network current-screen-id
|
||||||
lock-fetch-routes? on-press-to-network current-screen-id
|
|
||||||
token-not-supported-in-receiver-networks? send-amount-in-crypto]}]
|
token-not-supported-in-receiver-networks? send-amount-in-crypto]}]
|
||||||
(let [token-symbol (:symbol token)
|
(let [token-symbol (:symbol token)
|
||||||
nav-current-screen-id (rf/sub [:view-id])
|
nav-current-screen-id (rf/sub [:view-id])
|
||||||
|
@ -359,8 +358,7 @@
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
(when (and active-screen?
|
(when (and active-screen?
|
||||||
(> (count token-available-networks-for-suggested-routes) 0)
|
(> (count token-available-networks-for-suggested-routes) 0))
|
||||||
(not lock-fetch-routes?))
|
|
||||||
(request-fetch-routes 2000)))
|
(request-fetch-routes 2000)))
|
||||||
[send-amount-in-crypto valid-input?])
|
[send-amount-in-crypto valid-input?])
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
(:require
|
(:require
|
||||||
[quo.theme]
|
[quo.theme]
|
||||||
[status-im.contexts.wallet.send.input-amount.view :as input-amount]
|
[status-im.contexts.wallet.send.input-amount.view :as input-amount]
|
||||||
[status-im.setup.hot-reload :as hot-reload]
|
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
[]
|
[]
|
||||||
(hot-reload/use-safe-unmount #(rf/dispatch [:wallet/stop-get-suggested-routes]))
|
|
||||||
[input-amount/view
|
[input-amount/view
|
||||||
{:current-screen-id :screen/wallet.send-input-amount
|
{:current-screen-id :screen/wallet.send-input-amount
|
||||||
:button-one-label (i18n/label :t/review-send)
|
:button-one-label (i18n/label :t/review-send)
|
||||||
|
@ -16,6 +14,7 @@
|
||||||
[:wallet/wallet-send-enabled-from-chain-ids])
|
[:wallet/wallet-send-enabled-from-chain-ids])
|
||||||
:from-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks])
|
:from-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks])
|
||||||
:on-navigate-back (fn []
|
:on-navigate-back (fn []
|
||||||
|
(rf/dispatch-sync [:wallet/stop-and-clean-suggested-routes])
|
||||||
(rf/dispatch [:wallet/clean-disabled-from-networks])
|
(rf/dispatch [:wallet/clean-disabled-from-networks])
|
||||||
(rf/dispatch [:wallet/clean-from-locked-amounts])
|
(rf/dispatch [:wallet/clean-from-locked-amounts])
|
||||||
(rf/dispatch [:wallet/clean-send-amount]))}])
|
(rf/dispatch [:wallet/clean-send-amount]))}])
|
||||||
|
|
|
@ -94,10 +94,15 @@
|
||||||
:optimism 2
|
:optimism 2
|
||||||
:arbitrum 3})
|
:arbitrum 3})
|
||||||
|
|
||||||
|
(defn safe-add-type-edit
|
||||||
|
[network-values]
|
||||||
|
(if (or (empty? network-values) (some #(= (:type %) :edit) network-values))
|
||||||
|
network-values
|
||||||
|
(conj network-values {:type :edit})))
|
||||||
|
|
||||||
(defn reset-loading-network-amounts-to-zero
|
(defn reset-loading-network-amounts-to-zero
|
||||||
[network-amounts]
|
[network-amounts]
|
||||||
(map
|
(mapv
|
||||||
(fn [network-amount]
|
(fn [network-amount]
|
||||||
(cond-> network-amount
|
(cond-> network-amount
|
||||||
(= (:type network-amount) :loading)
|
(= (:type network-amount) :loading)
|
||||||
|
@ -177,7 +182,7 @@
|
||||||
(and receiver?
|
(and receiver?
|
||||||
routes-found?
|
routes-found?
|
||||||
(not= tx-type :tx/bridge))
|
(not= tx-type :tx/bridge))
|
||||||
(conj {:type :edit}))))
|
safe-add-type-edit)))
|
||||||
|
|
||||||
(defn loading-network-amounts
|
(defn loading-network-amounts
|
||||||
[{:keys [valid-networks disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?]}]
|
[{:keys [valid-networks disabled-chain-ids receiver-networks token-networks-ids tx-type receiver?]}]
|
||||||
|
|
Loading…
Reference in New Issue