networks moved to controller

This commit is contained in:
Volodymyr Kozieiev 2024-10-22 19:01:43 +01:00
parent 1636a1d231
commit 4ceb5c890e
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
2 changed files with 190 additions and 130 deletions

View File

@ -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,20 +194,38 @@
(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}
:<- [: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]]
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
@ -173,7 +238,15 @@
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}))
: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}))

View File

@ -234,7 +234,18 @@
upper-limit-exceeded?
amount-in-crypto
token-input-converted-value
token-input-converted-value-prettified]
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)
@ -244,11 +255,8 @@
(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])
on-confirm (or default-on-confirm handle-on-confirm)
send-from-locked-amounts (rf/sub [:wallet/wallet-send-from-locked-amounts])
token-by-symbol (rf/sub [:wallet/token-by-symbol
(str token-symbol)
@ -259,10 +267,6 @@
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)
(empty? route)
@ -273,9 +277,8 @@
(min token-decimals 6)))
" "
token-symbol)
first-route (first route)
native-currency-symbol (when-not confirm-disabled?
(get-in first-route
(get-in (first route)
[:from :native-currency-symbol]))
fee-formatted (when native-currency-symbol
(rf/sub [:wallet/wallet-send-fee-fiat-formatted
@ -285,31 +288,15 @@
{: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
(set receiver-preferred-networks)
receiver-selected-network))
receiver-networks))
should-try-again? (and (not upper-limit-exceeded?) no-routes-found?)