remove unnecessary subs and functions
This commit is contained in:
parent
327fa1e47e
commit
39a575e062
|
@ -13,25 +13,13 @@
|
||||||
[status-im.contexts.wallet.common.utils :as utils]
|
[status-im.contexts.wallet.common.utils :as utils]
|
||||||
[status-im.contexts.wallet.send.input-amount.estimated-fees :as estimated-fees]
|
[status-im.contexts.wallet.send.input-amount.estimated-fees :as estimated-fees]
|
||||||
[status-im.contexts.wallet.send.input-amount.style :as style]
|
[status-im.contexts.wallet.send.input-amount.style :as style]
|
||||||
[status-im.contexts.wallet.send.routes.view :as routes]
|
|
||||||
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
|
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
|
||||||
[status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert]
|
|
||||||
[status-im.setup.hot-reload :as hot-reload]
|
[status-im.setup.hot-reload :as hot-reload]
|
||||||
[utils.debounce :as debounce]
|
[utils.debounce :as debounce]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
[utils.money :as money]
|
[utils.money :as money]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn- every-network-value-is-zero?
|
|
||||||
[sender-network-values]
|
|
||||||
(every? (fn [{:keys [total-amount]}]
|
|
||||||
(and
|
|
||||||
total-amount
|
|
||||||
(money/bignumber? total-amount)
|
|
||||||
(money/equal-to total-amount
|
|
||||||
(money/bignumber "0"))))
|
|
||||||
sender-network-values))
|
|
||||||
|
|
||||||
(defn select-asset-bottom-sheet
|
(defn select-asset-bottom-sheet
|
||||||
[clear-input!]
|
[clear-input!]
|
||||||
(let [{preselected-token-symbol :symbol} (rf/sub [:wallet/wallet-send-token])]
|
(let [{preselected-token-symbol :symbol} (rf/sub [:wallet/wallet-send-token])]
|
||||||
|
@ -47,37 +35,6 @@
|
||||||
(rf/dispatch [:wallet/edit-token-to-send token])
|
(rf/dispatch [:wallet/edit-token-to-send token])
|
||||||
(clear-input!))}]]))
|
(clear-input!))}]]))
|
||||||
|
|
||||||
(defn- token-not-available
|
|
||||||
[token-symbol receiver-networks token-networks]
|
|
||||||
(let [theme (quo.theme/use-theme)
|
|
||||||
add-token-networks (fn []
|
|
||||||
(let [chain-ids (concat receiver-networks
|
|
||||||
(mapv #(:chain-id %) token-networks))]
|
|
||||||
(rf/dispatch [:wallet/update-receiver-networks chain-ids])))]
|
|
||||||
[rn/view {:style (style/token-not-available-container theme)}
|
|
||||||
[rn/view
|
|
||||||
[quo/icon :i/alert
|
|
||||||
{:size 16
|
|
||||||
:color (colors/resolve-color :danger theme)}]]
|
|
||||||
[rn/view {:style style/token-not-available-content-container}
|
|
||||||
[quo/text
|
|
||||||
{:style (style/token-not-available-text theme)
|
|
||||||
:size :paragraph-2}
|
|
||||||
(i18n/label :t/token-not-available-on-receiver-networks {:token-symbol token-symbol})]
|
|
||||||
[quo/button
|
|
||||||
{:size 24
|
|
||||||
:customization-color (colors/resolve-color :danger theme)
|
|
||||||
:on-press add-token-networks}
|
|
||||||
(i18n/label :t/add-networks-token-can-be-sent-to {:token-symbol token-symbol})]]]))
|
|
||||||
|
|
||||||
(defn- show-unpreferred-networks-alert
|
|
||||||
[on-confirm]
|
|
||||||
(rf/dispatch
|
|
||||||
[:show-bottom-sheet
|
|
||||||
{:content (fn []
|
|
||||||
[unpreferred-networks-alert/view
|
|
||||||
{:on-confirm on-confirm}])}]))
|
|
||||||
|
|
||||||
(defn- no-routes-found
|
(defn- no-routes-found
|
||||||
[]
|
[]
|
||||||
[rn/view {:style style/no-routes-found-container}
|
[rn/view {:style style/no-routes-found-container}
|
||||||
|
@ -119,7 +76,7 @@
|
||||||
|
|
||||||
(defn- insufficient-asset-amount?
|
(defn- insufficient-asset-amount?
|
||||||
[{:keys [token-symbol owned-eth-token input-state no-routes-found? limit-exceeded?
|
[{:keys [token-symbol owned-eth-token input-state no-routes-found? limit-exceeded?
|
||||||
sender-network-values enough-assets?]}]
|
enough-assets?]}]
|
||||||
(let [eth-selected? (= token-symbol (string/upper-case constants/mainnet-short-name))
|
(let [eth-selected? (= token-symbol (string/upper-case constants/mainnet-short-name))
|
||||||
zero-owned-eth? (money/equal-to (:total-balance owned-eth-token) 0)
|
zero-owned-eth? (money/equal-to (:total-balance owned-eth-token) 0)
|
||||||
input-at-max-owned-amount? (money/equal-to
|
input-at-max-owned-amount? (money/equal-to
|
||||||
|
@ -129,7 +86,6 @@
|
||||||
input-at-max-owned-amount?
|
input-at-max-owned-amount?
|
||||||
zero-owned-eth?)]
|
zero-owned-eth?)]
|
||||||
(and (or no-routes-found? limit-exceeded?)
|
(and (or no-routes-found? limit-exceeded?)
|
||||||
(seq sender-network-values)
|
|
||||||
(or exceeded-input? (not enough-assets?)))))
|
(or exceeded-input? (not enough-assets?)))))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
|
@ -142,42 +98,40 @@
|
||||||
button-one-props :button-one-props
|
button-one-props :button-one-props
|
||||||
current-screen-id :current-screen-id
|
current-screen-id :current-screen-id
|
||||||
initial-crypto-currency? :initial-crypto-currency?
|
initial-crypto-currency? :initial-crypto-currency?
|
||||||
enabled-from-chain-ids :enabled-from-chain-ids
|
|
||||||
from-enabled-networks :from-enabled-networks
|
|
||||||
:or {initial-crypto-currency? true}}]
|
:or {initial-crypto-currency? true}}]
|
||||||
(let [view-id (rf/sub [:view-id])
|
(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?)
|
|
||||||
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])
|
{fiat-currency :currency} (rf/sub [:profile/profile])
|
||||||
|
currency (rf/sub [:profile/currency])
|
||||||
{token-symbol :symbol
|
{token-symbol :symbol
|
||||||
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])
|
network (rf/sub [:wallet/send-network])
|
||||||
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])
|
(:chain-id network)])
|
||||||
|
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||||
|
loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?])
|
||||||
|
route (rf/sub [:wallet/wallet-send-route])
|
||||||
|
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||||
|
current-color (rf/sub [:wallet/current-viewing-account-color])
|
||||||
|
enough-assets? (rf/sub [:wallet/wallet-send-enough-assets?])
|
||||||
|
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||||
|
(string/upper-case constants/mainnet-short-name)
|
||||||
|
(:chain-id network)])
|
||||||
|
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
||||||
|
[crypto-currency?
|
||||||
|
set-crypto-currency] (rn/use-state initial-crypto-currency?)
|
||||||
|
[input-state set-input-state] (rn/use-state controlled-input/init-state)
|
||||||
|
active-screen? (= view-id current-screen-id)
|
||||||
|
bottom (safe-area/get-bottom)
|
||||||
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])
|
|
||||||
conversion-rate (-> token
|
conversion-rate (-> token
|
||||||
:market-values-per-currency
|
:market-values-per-currency
|
||||||
currency
|
currency
|
||||||
:price)
|
:price)
|
||||||
token-decimals (rf/sub [:wallet/send-display-token-decimals])
|
token-decimals (rf/sub [:wallet/send-display-token-decimals])
|
||||||
[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])
|
|
||||||
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)
|
|
||||||
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
|
||||||
|
@ -191,58 +145,40 @@
|
||||||
input-value
|
input-value
|
||||||
(rf/sub [:wallet/send-amount-fixed
|
(rf/sub [:wallet/send-amount-fixed
|
||||||
(/ input-value conversion-rate)]))
|
(/ input-value conversion-rate)]))
|
||||||
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])
|
|
||||||
unsupported-token-in-receiver? (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
|
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? sender-network-values)
|
|
||||||
(some? routes)
|
(some? routes)
|
||||||
(not loading-routes?)
|
(not loading-routes?))
|
||||||
(not unsupported-token-in-receiver?))
|
|
||||||
receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
|
||||||
receiver-preferred-networks (rf/sub [:wallet/wallet-send-receiver-preferred-networks])
|
|
||||||
receiver-preferred-network? (set receiver-preferred-networks)
|
|
||||||
sending-to-unpreferred-networks? (some (comp not receiver-preferred-network?)
|
|
||||||
receiver-networks)
|
|
||||||
input-error (controlled-input/input-error input-state)
|
input-error (controlled-input/input-error input-state)
|
||||||
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
|
||||||
current-color (rf/sub [:wallet/current-viewing-account-color])
|
|
||||||
enough-assets? (rf/sub [:wallet/wallet-send-enough-assets?])
|
|
||||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
|
||||||
(string/upper-case constants/mainnet-short-name)
|
|
||||||
enabled-from-chain-ids])
|
|
||||||
not-enough-asset? (insufficient-asset-amount?
|
not-enough-asset? (insufficient-asset-amount?
|
||||||
{:enough-assets? enough-assets?
|
{:enough-assets? enough-assets?
|
||||||
:token-symbol token-symbol
|
:token-symbol token-symbol
|
||||||
:owned-eth-token owned-eth-token
|
:owned-eth-token owned-eth-token
|
||||||
:input-state input-state
|
:input-state input-state
|
||||||
:no-routes-found? no-routes-found?
|
:no-routes-found? no-routes-found?
|
||||||
:limit-exceeded? limit-exceeded?
|
:limit-exceeded? limit-exceeded?})
|
||||||
:sender-network-values sender-network-values})
|
|
||||||
should-try-again? (and (not limit-exceeded?)
|
should-try-again? (and (not limit-exceeded?)
|
||||||
no-routes-found?
|
no-routes-found?
|
||||||
(not not-enough-asset?))
|
(not not-enough-asset?))
|
||||||
show-no-routes? (and (or no-routes-found? limit-exceeded?)
|
show-no-routes? (and (or no-routes-found? limit-exceeded?)
|
||||||
(not-empty sender-network-values)
|
|
||||||
(not not-enough-asset?))
|
(not not-enough-asset?))
|
||||||
confirm-disabled? (or (nil? route)
|
confirm-disabled? (or (nil? route)
|
||||||
(empty? route)
|
(empty? route)
|
||||||
(not valid-input?))
|
(not valid-input?))
|
||||||
fee-formatted (when (or (not confirm-disabled?) not-enough-asset?)
|
fee-formatted (when (or (not confirm-disabled?) not-enough-asset?)
|
||||||
(get-fee-formatted route))
|
(get-fee-formatted route))
|
||||||
|
handle-on-confirm (fn [amount]
|
||||||
|
(rf/dispatch [:wallet/set-token-amount-to-send
|
||||||
|
{:amount amount
|
||||||
|
:stack-id current-screen-id}]))
|
||||||
|
on-confirm (or default-on-confirm handle-on-confirm)
|
||||||
|
show-select-asset-sheet #(rf/dispatch
|
||||||
|
[:show-bottom-sheet
|
||||||
|
{:content (fn []
|
||||||
|
[select-asset-bottom-sheet
|
||||||
|
clear-input!])}])
|
||||||
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
|
||||||
|
@ -285,10 +221,6 @@
|
||||||
(rf/dispatch [:wallet/stop-and-clean-suggested-routes])
|
(rf/dispatch [:wallet/stop-and-clean-suggested-routes])
|
||||||
(rf/dispatch [:wallet/clean-disabled-from-networks]))
|
(rf/dispatch [:wallet/clean-disabled-from-networks]))
|
||||||
[current-address])
|
[current-address])
|
||||||
(rn/use-effect
|
|
||||||
(fn []
|
|
||||||
(request-fetch-routes 0))
|
|
||||||
[send-from-locked-amounts])
|
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
(when active-screen?
|
(when active-screen?
|
||||||
|
@ -354,14 +286,10 @@
|
||||||
loading-routes?
|
loading-routes?
|
||||||
(and (not should-try-again?)
|
(and (not should-try-again?)
|
||||||
confirm-disabled?))
|
confirm-disabled?))
|
||||||
:on-press (cond
|
:on-press (if should-try-again?
|
||||||
should-try-again?
|
|
||||||
#(rf/dispatch [:wallet/start-get-suggested-routes
|
#(rf/dispatch [:wallet/start-get-suggested-routes
|
||||||
{:amount amount-in-crypto
|
{:amount amount-in-crypto
|
||||||
:updated-token token-by-symbol}])
|
:updated-token token-by-symbol}])
|
||||||
sending-to-unpreferred-networks?
|
|
||||||
#(show-unpreferred-networks-alert on-confirm)
|
|
||||||
:else
|
|
||||||
#(on-confirm amount-in-crypto))
|
#(on-confirm amount-in-crypto))
|
||||||
:customization-color current-color}
|
:customization-color current-color}
|
||||||
(when should-try-again?
|
(when should-try-again?
|
||||||
|
|
Loading…
Reference in New Issue