diff --git a/src/status_im/contexts/wallet/send/input_amount/controller.cljs b/src/status_im/contexts/wallet/send/input_amount/controller.cljs index 0194a30156..c3ef9ca50a 100644 --- a/src/status_im/contexts/wallet/send/input_amount/controller.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/controller.cljs @@ -423,91 +423,60 @@ :current-address current-address :not-enough-asset? not-enough-asset? :show-no-routes? show-no-routes?})) - (rf/reg-sub :send-input-amount-screen/token-input-subs :<- [: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] - :<- [: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/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 [[{:keys [crypto-currency? token-input-value] :as controller} - {:keys [fiat-currency token-symbol token] :as currency-information} - upper-limit - amount-in-crypto + {:keys [fiat-currency token-symbol] :as currency-information} token-input-converted-value token-input-converted-value-prettified value-out-of-limits? upper-limit-prettified - {:keys [route - routes - sender-network-values - loading-routes? - token-not-supported-in-receiver-networks? - no-routes-found?] + from-enabled-networks]] + {:crypto-currency? crypto-currency? + :fiat-currency fiat-currency + :token-symbol token-symbol + :upper-limit-prettified upper-limit-prettified + :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} - {:keys [token-networks - receiver-networks - sending-to-unpreferred-networks?]} token-by-symbol - recipient-gets-amount - max-decimals - 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? + upper-limit-exceeded?]] + {:token token :valid-input? (not (or (controlled-input-logic/empty-value? token-input-value) value-out-of-limits?)) :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 - :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 - :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?})) - + :token-by-symbol token-by-symbol})) ;; events diff --git a/src/status_im/contexts/wallet/send/input_amount/view.cljs b/src/status_im/contexts/wallet/send/input_amount/view.cljs index 771a306085..ef49822f9b 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -134,40 +134,17 @@ (defn token-input [] (let [{:keys [crypto-currency? - upper-limit upper-limit-prettified input-value value-out-of-limits? - valid-input? - upper-limit-exceeded? - amount-in-crypto token-input-converted-value token-input-converted-value-prettified - route - routes - sender-network-values - loading-routes? - token-not-supported-in-receiver-networks? fiat-currency - token-networks - receiver-networks - token token-symbol - token-by-symbol - recipient-gets-amount - max-decimals - fee-formatted - 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])}])] + from-enabled-networks]} (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 {:container-style style/input-container :token-symbol token-symbol @@ -184,6 +161,31 @@ :t/send-limit {:limit upper-limit-prettified}) :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 ;; crypto-decimals, limit-crypto and initial-crypto-currency? args are needed @@ -224,20 +226,12 @@ current-address not-enough-asset? 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]) - view-id (rf/sub [:view-id]) - active-screen? (= view-id current-screen-id) - bottom (safe-area/get-bottom) - 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))}))] + view-id (rf/sub [:view-id]) + active-screen? (= view-id current-screen-id) + bottom (safe-area/get-bottom) + on-navigate-back on-navigate-back] (rn/use-effect (fn [] (when active-screen? @@ -261,7 +255,6 @@ (rf/dispatch [:wallet/stop-and-clean-suggested-routes]) (rf/dispatch [:wallet/clean-disabled-from-networks])) [current-address]) - [rn/view {:style style/screen :accessibility-label (str "container" @@ -271,14 +264,7 @@ :on-press #(rf/dispatch [:navigate-back]) :switcher-type :select-account}] [token-input] - - [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}] + [routes-component current-screen-id] (when (and (not loading-routes?) sender-network-values token-not-supported-in-receiver-networks?)