mirror of
https://github.com/status-im/status-react.git
synced 2025-02-09 09:34:55 +00:00
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]
|
[status-im.contexts.wallet.send.input-amount.controlled-input-logic :as controlled-input-logic]
|
||||||
[utils.money :as money]
|
[utils.money :as money]
|
||||||
[utils.number :as number]
|
[utils.number :as number]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]
|
||||||
|
[status-im.common.router :as router]))
|
||||||
|
|
||||||
;; notes
|
;; notes
|
||||||
;; token-by-symbol and token looks very similar but they have difference in market values data
|
;; token-by-symbol and token looks very similar but they have difference in market values data
|
||||||
@ -35,13 +36,17 @@
|
|||||||
:<- [:wallet/wallet-send-token]
|
:<- [:wallet/wallet-send-token]
|
||||||
:<- [:profile/currency]
|
:<- [:profile/currency]
|
||||||
:<- [:profile/currency-symbol]
|
:<- [:profile/currency-symbol]
|
||||||
|
:<- [:profile/profile]
|
||||||
(fn [[{token-symbol :symbol
|
(fn [[{token-symbol :symbol
|
||||||
total-balance :total-balance
|
total-balance :total-balance
|
||||||
:as
|
:as
|
||||||
token}
|
token}
|
||||||
currency currency-symbol]]
|
currency
|
||||||
|
currency-symbol
|
||||||
|
{fiat-currency :currency}]]
|
||||||
{:usd-conversion-rate (utils/token-usd-price token)
|
{:usd-conversion-rate (utils/token-usd-price token)
|
||||||
:currency currency
|
:currency currency
|
||||||
|
:fiat-currency fiat-currency
|
||||||
:currency-symbol currency-symbol
|
:currency-symbol currency-symbol
|
||||||
:token-symbol token-symbol
|
:token-symbol token-symbol
|
||||||
:conversion-rate (-> token
|
:conversion-rate (-> token
|
||||||
@ -55,6 +60,37 @@
|
|||||||
:token token
|
:token token
|
||||||
:total-balance total-balance}))
|
: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
|
(rf/reg-sub :send-input-amount-screen/token-by-symbol
|
||||||
:<- [:wallet/wallet-send-enabled-from-chain-ids]
|
:<- [:wallet/wallet-send-enabled-from-chain-ids]
|
||||||
:<- [:send-input-amount-screen/currency-information]
|
:<- [:send-input-amount-screen/currency-information]
|
||||||
@ -89,6 +125,17 @@
|
|||||||
(.toFixed (/ token-input-value conversion-rate)
|
(.toFixed (/ token-input-value conversion-rate)
|
||||||
token-decimals)))))
|
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
|
(defn- fiat->crypto
|
||||||
[value conversion-rate]
|
[value conversion-rate]
|
||||||
(-> value
|
(-> value
|
||||||
@ -147,33 +194,59 @@
|
|||||||
|
|
||||||
(rf/reg-sub :send-input-amount-screen/data
|
(rf/reg-sub :send-input-amount-screen/data
|
||||||
:<- [:send-input-amount-screen/controller]
|
:<- [:send-input-amount-screen/controller]
|
||||||
|
:<- [:send-input-amount-screen/currency-information]
|
||||||
:<- [:send-input-amount-screen/upper-limit]
|
:<- [:send-input-amount-screen/upper-limit]
|
||||||
:<- [:send-input-amount-screen/amount-in-crypto]
|
:<- [:send-input-amount-screen/amount-in-crypto]
|
||||||
:<- [:send-input-amount-screen/token-input-converted-value]
|
:<- [:send-input-amount-screen/token-input-converted-value]
|
||||||
:<- [:send-input-amount-screen/token-input-converted-value-prettified]
|
:<- [:send-input-amount-screen/token-input-converted-value-prettified]
|
||||||
:<- [:send-input-amount-screen/value-out-of-limits?]
|
:<- [:send-input-amount-screen/value-out-of-limits?]
|
||||||
:<- [:send-input-amount-screen/upper-limit-prettified]
|
:<- [:send-input-amount-screen/upper-limit-prettified]
|
||||||
(fn [[{:keys [crypto-currency? token-input-value] :as controller}
|
:<- [:send-input-amount-screen/routes-information]
|
||||||
upper-limit
|
:<- [:send-input-amount-screen/token-not-supported-in-receiver-networks?]
|
||||||
amount-in-crypto
|
:<- [:send-input-amount-screen/networks-information]
|
||||||
token-input-converted-value
|
(fn
|
||||||
token-input-converted-value-prettified
|
[[{:keys [crypto-currency? token-input-value] :as controller}
|
||||||
value-out-of-limits?
|
{:keys [fiat-currency token-symbol token] :as currency-information}
|
||||||
upper-limit-prettified]]
|
upper-limit
|
||||||
{:crypto-currency? crypto-currency?
|
amount-in-crypto
|
||||||
:upper-limit upper-limit
|
token-input-converted-value
|
||||||
:upper-limit-prettified upper-limit-prettified
|
token-input-converted-value-prettified
|
||||||
:input-value token-input-value
|
value-out-of-limits?
|
||||||
:value-out-of-limits? value-out-of-limits?
|
upper-limit-prettified
|
||||||
:valid-input? (not (or (controlled-input-logic/empty-value?
|
{:keys [route
|
||||||
token-input-value)
|
routes
|
||||||
value-out-of-limits?))
|
sender-network-values
|
||||||
:upper-limit-exceeded? (controlled-input-logic/upper-limit-exceeded?
|
loading-routes?]
|
||||||
token-input-value
|
:as routes-information}
|
||||||
upper-limit)
|
token-not-supported-in-receiver-networks?
|
||||||
:amount-in-crypto amount-in-crypto
|
{:keys [token-networks
|
||||||
:token-input-converted-value token-input-converted-value
|
receiver-networks
|
||||||
:token-input-converted-value-prettified token-input-converted-value-prettified}))
|
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?
|
upper-limit-exceeded?
|
||||||
amount-in-crypto
|
amount-in-crypto
|
||||||
token-input-converted-value
|
token-input-converted-value
|
||||||
token-input-converted-value-prettified]
|
token-input-converted-value-prettified
|
||||||
:as state} (rf/sub [:send-input-amount-screen/data])
|
route
|
||||||
view-id (rf/sub [:view-id])
|
routes
|
||||||
active-screen? (= view-id current-screen-id)
|
sender-network-values
|
||||||
bottom (safe-area/get-bottom)
|
loading-routes?
|
||||||
on-navigate-back on-navigate-back
|
token-not-supported-in-receiver-networks?
|
||||||
handle-on-confirm (fn [amount]
|
fiat-currency
|
||||||
(rf/dispatch [:wallet/set-token-amount-to-send
|
token-networks
|
||||||
{:amount amount
|
receiver-networks
|
||||||
:stack-id current-screen-id}]))
|
receiver-preferred-networks
|
||||||
{fiat-currency :currency} (rf/sub [:profile/profile])
|
token
|
||||||
{token-symbol :symbol
|
token-symbol]
|
||||||
token-networks :networks
|
:as state} (rf/sub [:send-input-amount-screen/data])
|
||||||
:as
|
view-id (rf/sub [:view-id])
|
||||||
token} (rf/sub [:wallet/wallet-send-token])
|
active-screen? (= view-id current-screen-id)
|
||||||
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
|
bottom (safe-area/get-bottom)
|
||||||
token-by-symbol (rf/sub [:wallet/token-by-symbol
|
on-navigate-back on-navigate-back
|
||||||
(str token-symbol)
|
handle-on-confirm (fn [amount]
|
||||||
enabled-from-chain-ids])
|
(rf/dispatch [:wallet/set-token-amount-to-send
|
||||||
token-decimals (-> token
|
{:amount amount
|
||||||
utils/token-usd-price
|
:stack-id current-screen-id}]))
|
||||||
utils/one-cent-value
|
on-confirm (or default-on-confirm handle-on-confirm)
|
||||||
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)
|
|
||||||
|
|
||||||
confirm-disabled? (or (nil? route)
|
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
|
||||||
(empty? route)
|
token-by-symbol (rf/sub [:wallet/token-by-symbol
|
||||||
(not valid-input?))
|
(str token-symbol)
|
||||||
total-amount-receiver (rf/sub [:wallet/total-amount true])
|
enabled-from-chain-ids])
|
||||||
amount-text (str (number/remove-trailing-zeroes
|
token-decimals (-> token
|
||||||
(.toFixed total-amount-receiver
|
utils/token-usd-price
|
||||||
(min token-decimals 6)))
|
utils/one-cent-value
|
||||||
" "
|
utils/calc-max-crypto-decimals)
|
||||||
token-symbol)
|
clear-input! #(rf/dispatch
|
||||||
first-route (first route)
|
[:send-input-amount-screen/token-input-delete-all])
|
||||||
native-currency-symbol (when-not confirm-disabled?
|
|
||||||
(get-in first-route
|
confirm-disabled? (or (nil? route)
|
||||||
[:from :native-currency-symbol]))
|
(empty? route)
|
||||||
fee-formatted (when native-currency-symbol
|
(not valid-input?))
|
||||||
(rf/sub [:wallet/wallet-send-fee-fiat-formatted
|
total-amount-receiver (rf/sub [:wallet/total-amount true])
|
||||||
native-currency-symbol]))
|
amount-text (str (number/remove-trailing-zeroes
|
||||||
show-select-asset-sheet #(rf/dispatch
|
(.toFixed total-amount-receiver
|
||||||
[:show-bottom-sheet
|
(min token-decimals 6)))
|
||||||
{:content (fn []
|
" "
|
||||||
[select-asset-bottom-sheet
|
token-symbol)
|
||||||
clear-input!])}])
|
native-currency-symbol (when-not confirm-disabled?
|
||||||
sender-network-values (rf/sub
|
(get-in (first route)
|
||||||
[:wallet/wallet-send-sender-network-values])
|
[:from :native-currency-symbol]))
|
||||||
receiver-network-values (rf/sub
|
fee-formatted (when native-currency-symbol
|
||||||
[:wallet/wallet-send-receiver-network-values])
|
(rf/sub [:wallet/wallet-send-fee-fiat-formatted
|
||||||
tx-type (rf/sub [:wallet/wallet-send-tx-type])
|
native-currency-symbol]))
|
||||||
token-not-supported-in-receiver-networks? (and (not= tx-type :tx/bridge)
|
show-select-asset-sheet #(rf/dispatch
|
||||||
(->> receiver-network-values
|
[:show-bottom-sheet
|
||||||
(remove #(= (:type %) :add))
|
{:content (fn []
|
||||||
(every? #(= (:type %) :not-available))))
|
[select-asset-bottom-sheet
|
||||||
suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes])
|
clear-input!])}])
|
||||||
routes (when suggested-routes
|
no-routes-found? (and
|
||||||
(or (:best suggested-routes) []))
|
(every-network-value-is-zero?
|
||||||
no-routes-found? (and
|
sender-network-values)
|
||||||
(every-network-value-is-zero?
|
(not (nil? routes))
|
||||||
sender-network-values)
|
(not loading-routes?)
|
||||||
(not (nil? routes))
|
(not token-not-supported-in-receiver-networks?))
|
||||||
(not loading-routes?)
|
sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network]
|
||||||
(not token-not-supported-in-receiver-networks?))
|
(contains?
|
||||||
receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks])
|
(set receiver-preferred-networks)
|
||||||
receiver-preferred-networks (rf/sub
|
receiver-selected-network))
|
||||||
[:wallet/wallet-send-receiver-preferred-networks])
|
receiver-networks))
|
||||||
receiver-preferred-networks-set (set receiver-preferred-networks)
|
should-try-again? (and (not upper-limit-exceeded?) no-routes-found?)
|
||||||
sending-to-unpreferred-networks? (not (every? (fn [receiver-selected-network]
|
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||||
(contains?
|
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||||
receiver-preferred-networks-set
|
(string/upper-case
|
||||||
receiver-selected-network))
|
constants/mainnet-short-name)
|
||||||
receiver-networks))
|
enabled-from-chain-ids])
|
||||||
should-try-again? (and (not upper-limit-exceeded?) no-routes-found?)
|
not-enough-asset? (and
|
||||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
(or no-routes-found? upper-limit-exceeded?)
|
||||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
(not-empty sender-network-values)
|
||||||
(string/upper-case
|
(if (= token-symbol
|
||||||
constants/mainnet-short-name)
|
(string/upper-case
|
||||||
enabled-from-chain-ids])
|
constants/mainnet-short-name))
|
||||||
not-enough-asset? (and
|
(money/equal-to
|
||||||
(or no-routes-found? upper-limit-exceeded?)
|
(money/bignumber input-value)
|
||||||
(not-empty sender-network-values)
|
(money/bignumber upper-limit))
|
||||||
(if (= token-symbol
|
(money/equal-to (:total-balance
|
||||||
(string/upper-case
|
owned-eth-token)
|
||||||
constants/mainnet-short-name))
|
0)))
|
||||||
(money/equal-to
|
show-no-routes? (and
|
||||||
(money/bignumber input-value)
|
(or no-routes-found? upper-limit-exceeded?)
|
||||||
(money/bignumber upper-limit))
|
(not-empty sender-network-values)
|
||||||
(money/equal-to (:total-balance
|
(not not-enough-asset?))
|
||||||
owned-eth-token)
|
request-fetch-routes (fn [bounce-duration-ms]
|
||||||
0)))
|
(fetch-routes
|
||||||
show-no-routes? (and
|
{:amount amount-in-crypto
|
||||||
(or no-routes-found? upper-limit-exceeded?)
|
:valid-input? valid-input?
|
||||||
(not-empty sender-network-values)
|
:bounce-duration-ms bounce-duration-ms
|
||||||
(not not-enough-asset?))
|
:token token
|
||||||
request-fetch-routes (fn [bounce-duration-ms]
|
:reset-amounts-to-zero? (and upper-limit-exceeded?
|
||||||
(fetch-routes
|
(some? 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
|
(rn/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
(when active-screen?
|
(when active-screen?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user