networks moved to controller
This commit is contained in:
parent
1636a1d231
commit
4ceb5c890e
|
@ -5,7 +5,8 @@
|
|||
[status-im.contexts.wallet.send.input-amount.controlled-input-logic :as controlled-input-logic]
|
||||
[utils.money :as money]
|
||||
[utils.number :as number]
|
||||
[utils.re-frame :as rf]))
|
||||
[utils.re-frame :as rf]
|
||||
[status-im.common.router :as router]))
|
||||
|
||||
;; notes
|
||||
;; token-by-symbol and token looks very similar but they have difference in market values data
|
||||
|
@ -35,13 +36,17 @@
|
|||
:<- [:wallet/wallet-send-token]
|
||||
:<- [:profile/currency]
|
||||
:<- [:profile/currency-symbol]
|
||||
:<- [:profile/profile]
|
||||
(fn [[{token-symbol :symbol
|
||||
total-balance :total-balance
|
||||
:as
|
||||
token}
|
||||
currency currency-symbol]]
|
||||
currency
|
||||
currency-symbol
|
||||
{fiat-currency :currency}]]
|
||||
{:usd-conversion-rate (utils/token-usd-price token)
|
||||
:currency currency
|
||||
:fiat-currency fiat-currency
|
||||
:currency-symbol currency-symbol
|
||||
:token-symbol token-symbol
|
||||
:conversion-rate (-> token
|
||||
|
@ -55,6 +60,37 @@
|
|||
:token token
|
||||
:total-balance total-balance}))
|
||||
|
||||
(rf/reg-sub :send-input-amount-screen/routes-information
|
||||
:<- [:wallet/wallet-send-route]
|
||||
:<- [:wallet/wallet-send-sender-network-values]
|
||||
:<- [:wallet/wallet-send-receiver-network-values]
|
||||
:<- [:wallet/wallet-send-suggested-routes]
|
||||
:<- [:wallet/wallet-send-loading-suggested-routes?]
|
||||
(fn [[route
|
||||
sender-network-values
|
||||
receiver-network-values
|
||||
suggested-routes
|
||||
loading-routes?]]
|
||||
{:route route
|
||||
:sender-network-values sender-network-values
|
||||
:receiver-network-values receiver-network-values
|
||||
:suggested-routes suggested-routes
|
||||
:loading-routes? loading-routes?
|
||||
:routes (when suggested-routes
|
||||
(or (:best suggested-routes) []))}))
|
||||
|
||||
(rf/reg-sub :send-input-amount-screen/networks-information
|
||||
:<- [:wallet/wallet-send-token]
|
||||
:<- [:wallet/wallet-send-receiver-networks]
|
||||
:<- [:wallet/wallet-send-receiver-preferred-networks]
|
||||
(fn [[{token-networks :networks}
|
||||
receiver-networks
|
||||
receiver-preferred-networks
|
||||
]]
|
||||
{:token-networks token-networks
|
||||
:receiver-networks receiver-networks
|
||||
:receiver-preferred-networks receiver-preferred-networks}))
|
||||
|
||||
(rf/reg-sub :send-input-amount-screen/token-by-symbol
|
||||
:<- [:wallet/wallet-send-enabled-from-chain-ids]
|
||||
:<- [:send-input-amount-screen/currency-information]
|
||||
|
@ -89,6 +125,17 @@
|
|||
(.toFixed (/ token-input-value conversion-rate)
|
||||
token-decimals)))))
|
||||
|
||||
(rf/reg-sub
|
||||
:send-input-amount-screen/token-not-supported-in-receiver-networks?
|
||||
:<- [:wallet/wallet-send-tx-type]
|
||||
:<- [:send-input-amount-screen/routes-information]
|
||||
(fn [[tx-type
|
||||
{:keys [receiver-network-values]}]]
|
||||
(and (not= tx-type :tx/bridge)
|
||||
(->> receiver-network-values
|
||||
(remove #(= (:type %) :add))
|
||||
(every? #(= (:type %) :not-available))))))
|
||||
|
||||
(defn- fiat->crypto
|
||||
[value conversion-rate]
|
||||
(-> value
|
||||
|
@ -147,33 +194,59 @@
|
|||
|
||||
(rf/reg-sub :send-input-amount-screen/data
|
||||
:<- [:send-input-amount-screen/controller]
|
||||
:<- [:send-input-amount-screen/currency-information]
|
||||
:<- [:send-input-amount-screen/upper-limit]
|
||||
:<- [:send-input-amount-screen/amount-in-crypto]
|
||||
:<- [:send-input-amount-screen/token-input-converted-value]
|
||||
:<- [:send-input-amount-screen/token-input-converted-value-prettified]
|
||||
:<- [:send-input-amount-screen/value-out-of-limits?]
|
||||
:<- [:send-input-amount-screen/upper-limit-prettified]
|
||||
(fn [[{:keys [crypto-currency? token-input-value] :as controller}
|
||||
upper-limit
|
||||
amount-in-crypto
|
||||
token-input-converted-value
|
||||
token-input-converted-value-prettified
|
||||
value-out-of-limits?
|
||||
upper-limit-prettified]]
|
||||
{:crypto-currency? crypto-currency?
|
||||
:upper-limit upper-limit
|
||||
:upper-limit-prettified upper-limit-prettified
|
||||
:input-value token-input-value
|
||||
:value-out-of-limits? value-out-of-limits?
|
||||
:valid-input? (not (or (controlled-input-logic/empty-value?
|
||||
token-input-value)
|
||||
value-out-of-limits?))
|
||||
:upper-limit-exceeded? (controlled-input-logic/upper-limit-exceeded?
|
||||
token-input-value
|
||||
upper-limit)
|
||||
:amount-in-crypto amount-in-crypto
|
||||
:token-input-converted-value token-input-converted-value
|
||||
:token-input-converted-value-prettified token-input-converted-value-prettified}))
|
||||
:<- [:send-input-amount-screen/routes-information]
|
||||
:<- [:send-input-amount-screen/token-not-supported-in-receiver-networks?]
|
||||
:<- [:send-input-amount-screen/networks-information]
|
||||
(fn
|
||||
[[{:keys [crypto-currency? token-input-value] :as controller}
|
||||
{:keys [fiat-currency token-symbol token] :as currency-information}
|
||||
upper-limit
|
||||
amount-in-crypto
|
||||
token-input-converted-value
|
||||
token-input-converted-value-prettified
|
||||
value-out-of-limits?
|
||||
upper-limit-prettified
|
||||
{:keys [route
|
||||
routes
|
||||
sender-network-values
|
||||
loading-routes?]
|
||||
:as routes-information}
|
||||
token-not-supported-in-receiver-networks?
|
||||
{:keys [token-networks
|
||||
receiver-networks
|
||||
receiver-preferred-networks]}]]
|
||||
{:crypto-currency? crypto-currency?
|
||||
:fiat-currency fiat-currency
|
||||
:token token
|
||||
:token-symbol token-symbol
|
||||
:upper-limit upper-limit
|
||||
:upper-limit-prettified upper-limit-prettified
|
||||
:input-value token-input-value
|
||||
:value-out-of-limits? value-out-of-limits?
|
||||
:valid-input? (not (or (controlled-input-logic/empty-value?
|
||||
token-input-value)
|
||||
value-out-of-limits?))
|
||||
:upper-limit-exceeded? (controlled-input-logic/upper-limit-exceeded?
|
||||
token-input-value
|
||||
upper-limit)
|
||||
:amount-in-crypto amount-in-crypto
|
||||
:token-input-converted-value token-input-converted-value
|
||||
:token-input-converted-value-prettified token-input-converted-value-prettified
|
||||
:route route
|
||||
:routes routes
|
||||
:sender-network-values sender-network-values
|
||||
:loading-routes? loading-routes?
|
||||
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
||||
:token-networks token-networks
|
||||
:receiver-networks receiver-networks
|
||||
:receiver-preferred-networks receiver-preferred-networks}))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -234,114 +234,101 @@
|
|||
upper-limit-exceeded?
|
||||
amount-in-crypto
|
||||
token-input-converted-value
|
||||
token-input-converted-value-prettified]
|
||||
:as state} (rf/sub [:send-input-amount-screen/data])
|
||||
view-id (rf/sub [:view-id])
|
||||
active-screen? (= view-id current-screen-id)
|
||||
bottom (safe-area/get-bottom)
|
||||
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-by-symbol (rf/sub [:wallet/token-by-symbol
|
||||
(str token-symbol)
|
||||
enabled-from-chain-ids])
|
||||
token-decimals (-> token
|
||||
utils/token-usd-price
|
||||
utils/one-cent-value
|
||||
utils/calc-max-crypto-decimals)
|
||||
clear-input! #(rf/dispatch
|
||||
[:send-input-amount-screen/token-input-delete-all])
|
||||
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)
|
||||
token-input-converted-value-prettified
|
||||
route
|
||||
routes
|
||||
sender-network-values
|
||||
loading-routes?
|
||||
token-not-supported-in-receiver-networks?
|
||||
fiat-currency
|
||||
token-networks
|
||||
receiver-networks
|
||||
receiver-preferred-networks
|
||||
token
|
||||
token-symbol]
|
||||
:as state} (rf/sub [:send-input-amount-screen/data])
|
||||
view-id (rf/sub [:view-id])
|
||||
active-screen? (= view-id current-screen-id)
|
||||
bottom (safe-area/get-bottom)
|
||||
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}]))
|
||||
on-confirm (or default-on-confirm handle-on-confirm)
|
||||
|
||||
confirm-disabled? (or (nil? route)
|
||||
(empty? route)
|
||||
(not valid-input?))
|
||||
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))
|
||||
should-try-again? (and (not upper-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? upper-limit-exceeded?)
|
||||
(not-empty sender-network-values)
|
||||
(if (= token-symbol
|
||||
(string/upper-case
|
||||
constants/mainnet-short-name))
|
||||
(money/equal-to
|
||||
(money/bignumber input-value)
|
||||
(money/bignumber upper-limit))
|
||||
(money/equal-to (:total-balance
|
||||
owned-eth-token)
|
||||
0)))
|
||||
show-no-routes? (and
|
||||
(or no-routes-found? upper-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 upper-limit-exceeded?
|
||||
(some? routes))}))]
|
||||
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
|
||||
token-by-symbol (rf/sub [:wallet/token-by-symbol
|
||||
(str token-symbol)
|
||||
enabled-from-chain-ids])
|
||||
token-decimals (-> token
|
||||
utils/token-usd-price
|
||||
utils/one-cent-value
|
||||
utils/calc-max-crypto-decimals)
|
||||
clear-input! #(rf/dispatch
|
||||
[:send-input-amount-screen/token-input-delete-all])
|
||||
|
||||
confirm-disabled? (or (nil? route)
|
||||
(empty? route)
|
||||
(not valid-input?))
|
||||
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)
|
||||
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!])}])
|
||||
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?))
|
||||
sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network]
|
||||
(contains?
|
||||
(set receiver-preferred-networks)
|
||||
receiver-selected-network))
|
||||
receiver-networks))
|
||||
should-try-again? (and (not upper-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? upper-limit-exceeded?)
|
||||
(not-empty sender-network-values)
|
||||
(if (= token-symbol
|
||||
(string/upper-case
|
||||
constants/mainnet-short-name))
|
||||
(money/equal-to
|
||||
(money/bignumber input-value)
|
||||
(money/bignumber upper-limit))
|
||||
(money/equal-to (:total-balance
|
||||
owned-eth-token)
|
||||
0)))
|
||||
show-no-routes? (and
|
||||
(or no-routes-found? upper-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 upper-limit-exceeded?
|
||||
(some? routes))}))]
|
||||
(rn/use-effect
|
||||
(fn []
|
||||
(when active-screen?
|
||||
|
|
Loading…
Reference in New Issue