Subs for token-input and routes components

This commit is contained in:
Volodymyr Kozieiev 2024-10-24 13:44:11 +01:00
parent 13d40203f1
commit 8ddea30542
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
2 changed files with 66 additions and 111 deletions

View File

@ -423,91 +423,60 @@
:current-address current-address :current-address current-address
:not-enough-asset? not-enough-asset? :not-enough-asset? not-enough-asset?
:show-no-routes? show-no-routes?})) :show-no-routes? show-no-routes?}))
(rf/reg-sub :send-input-amount-screen/token-input-subs (rf/reg-sub :send-input-amount-screen/token-input-subs
:<- [:send-input-amount-screen/controller] :<- [:send-input-amount-screen/controller]
:<- [:send-input-amount-screen/currency-information] :<- [: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]
:<- [: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]
:<- [:send-input-amount-screen/routes-information]
:<- [:send-input-amount-screen/networks-information]
:<- [:send-input-amount-screen/token-by-symbol]
:<- [:send-input-amount-screen/recipient-gets-amount]
:<- [:send-input-amount-screen/max-decimals]
:<- [:send-input-amount-screen/fee-formatted]
:<- [:send-input-amount-screen/from-enabled-networks] :<- [:send-input-amount-screen/from-enabled-networks]
:<- [:send-input-amount-screen/upper-limit-exceeded?]
:<- [:send-input-amount-screen/should-try-again?]
:<- [:wallet/current-viewing-account-address]
:<- [:send-input-amount-screen/not-enough-asset?]
:<- [:send-input-amount-screen/show-no-routes?]
(fn (fn
[[{:keys [crypto-currency? token-input-value] :as controller} [[{:keys [crypto-currency? token-input-value] :as controller}
{:keys [fiat-currency token-symbol token] :as currency-information} {:keys [fiat-currency token-symbol] :as currency-information}
upper-limit
amount-in-crypto
token-input-converted-value token-input-converted-value
token-input-converted-value-prettified token-input-converted-value-prettified
value-out-of-limits? value-out-of-limits?
upper-limit-prettified upper-limit-prettified
{:keys [route from-enabled-networks]]
routes {:crypto-currency? crypto-currency?
sender-network-values :fiat-currency fiat-currency
loading-routes? :token-symbol token-symbol
token-not-supported-in-receiver-networks? :upper-limit-prettified upper-limit-prettified
no-routes-found?] :input-value token-input-value
:value-out-of-limits? value-out-of-limits?
:token-input-converted-value token-input-converted-value
:token-input-converted-value-prettified token-input-converted-value-prettified
:from-enabled-networks from-enabled-networks}))
(rf/reg-sub :send-input-amount-screen/routes-subs
:<- [:send-input-amount-screen/controller]
:<- [:send-input-amount-screen/currency-information]
:<- [:send-input-amount-screen/amount-in-crypto]
:<- [:send-input-amount-screen/value-out-of-limits?]
:<- [:send-input-amount-screen/routes-information]
:<- [:send-input-amount-screen/token-by-symbol]
:<- [:send-input-amount-screen/upper-limit-exceeded?]
(fn
[[{:keys [token-input-value] :as controller}
{:keys [token] :as currency-information}
amount-in-crypto
value-out-of-limits?
{:keys [routes
token-not-supported-in-receiver-networks?]
:as routes-information} :as routes-information}
{:keys [token-networks
receiver-networks
sending-to-unpreferred-networks?]}
token-by-symbol token-by-symbol
recipient-gets-amount upper-limit-exceeded?]]
max-decimals {:token token
fee-formatted
from-enabled-networks
upper-limit-exceeded?
should-try-again?
current-address
not-enough-asset?
show-no-routes?]]
{: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? :valid-input? (not (or (controlled-input-logic/empty-value?
token-input-value) token-input-value)
value-out-of-limits?)) value-out-of-limits?))
:upper-limit-exceeded? upper-limit-exceeded? :upper-limit-exceeded? upper-limit-exceeded?
:amount-in-crypto amount-in-crypto :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 :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-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
:token-networks token-networks :token-by-symbol token-by-symbol}))
:receiver-networks receiver-networks
:token-by-symbol token-by-symbol
:recipient-gets-amount recipient-gets-amount
:max-decimals max-decimals
:fee-formatted fee-formatted
:sending-to-unpreferred-networks? sending-to-unpreferred-networks?
:no-routes-found? no-routes-found?
:from-enabled-networks from-enabled-networks
:should-try-again? should-try-again?
:current-address current-address
:not-enough-asset? not-enough-asset?
:show-no-routes? show-no-routes?}))
;; events ;; events

View File

@ -134,40 +134,17 @@
(defn token-input (defn token-input
[] []
(let [{:keys [crypto-currency? (let [{:keys [crypto-currency?
upper-limit
upper-limit-prettified upper-limit-prettified
input-value input-value
value-out-of-limits? value-out-of-limits?
valid-input?
upper-limit-exceeded?
amount-in-crypto
token-input-converted-value 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 fiat-currency
token-networks
receiver-networks
token
token-symbol token-symbol
token-by-symbol from-enabled-networks]} (rf/sub [:send-input-amount-screen/token-input-subs])
recipient-gets-amount show-select-asset-sheet #(rf/dispatch
max-decimals [:show-bottom-sheet
fee-formatted {:content (fn [] [select-asset-bottom-sheet])}])]
sending-to-unpreferred-networks?
no-routes-found?
from-enabled-networks
should-try-again?
current-address
not-enough-asset?
show-no-routes?]
:as state} (rf/sub [:send-input-amount-screen/token-input-subs])
show-select-asset-sheet #(rf/dispatch
[:show-bottom-sheet
{:content (fn [] [select-asset-bottom-sheet])}])]
[quo/token-input [quo/token-input
{:container-style style/input-container {:container-style style/input-container
:token-symbol token-symbol :token-symbol token-symbol
@ -184,6 +161,31 @@
:t/send-limit :t/send-limit
{:limit upper-limit-prettified}) {:limit upper-limit-prettified})
:status (when value-out-of-limits? :error)}]}])) :status (when value-out-of-limits? :error)}]}]))
(defn routes-component
[current-screen-id]
(let [{:keys [valid-input?
upper-limit-exceeded?
amount-in-crypto
routes
token-not-supported-in-receiver-networks?
token
token-by-symbol]
:as state} (rf/sub [:send-input-amount-screen/routes-subs])
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))}))]
[routes/view
{:token token-by-symbol
:send-amount-in-crypto amount-in-crypto
:valid-input? valid-input?
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
:current-screen-id current-screen-id
:request-fetch-routes request-fetch-routes}]))
(defn view (defn view
;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed ;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed
@ -224,20 +226,12 @@
current-address current-address
not-enough-asset? not-enough-asset?
show-no-routes?] show-no-routes?]
:as state} (rf/sub [:send-input-amount-screen/view-subs]) :as state} (rf/sub [:send-input-amount-screen/view-subs])
;; from-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks]) ;; from-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks])
view-id (rf/sub [:view-id]) view-id (rf/sub [:view-id])
active-screen? (= view-id current-screen-id) active-screen? (= view-id current-screen-id)
bottom (safe-area/get-bottom) bottom (safe-area/get-bottom)
on-navigate-back on-navigate-back on-navigate-back on-navigate-back]
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 (rn/use-effect
(fn [] (fn []
(when active-screen? (when active-screen?
@ -261,7 +255,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/view [rn/view
{:style style/screen {:style style/screen
:accessibility-label (str "container" :accessibility-label (str "container"
@ -271,14 +264,7 @@
:on-press #(rf/dispatch [:navigate-back]) :on-press #(rf/dispatch [:navigate-back])
:switcher-type :select-account}] :switcher-type :select-account}]
[token-input] [token-input]
[routes-component current-screen-id]
[routes/view
{:token token-by-symbol
:send-amount-in-crypto amount-in-crypto
:valid-input? valid-input?
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
:current-screen-id current-screen-id
:request-fetch-routes request-fetch-routes}]
(when (and (not loading-routes?) (when (and (not loading-routes?)
sender-network-values sender-network-values
token-not-supported-in-receiver-networks?) token-not-supported-in-receiver-networks?)