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