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 35df38480f..0f1073a9a0 100644 --- a/src/status_im/contexts/wallet/send/input_amount/controller.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/controller.cljs @@ -260,8 +260,7 @@ (rf/reg-sub :send-input-amount-screen/owned-eth-balance-is-zero? :<- [:send-input-amount-screen/enabled-from-chain-ids] - (fn [enabled-from-chain-ids - ] + (fn [enabled-from-chain-ids] (let [owned-eth-token (rf/sub [:wallet/token-by-symbol (string/upper-case constants/mainnet-short-name) @@ -276,6 +275,61 @@ [:from :native-currency-symbol]))] (rf/sub [:wallet/wallet-send-fee-fiat-formatted native-currency-symbol])))) +(rf/reg-sub :send-input-amount-screen/upper-limit-exceeded? + :<- [:send-input-amount-screen/controller] + :<- [:send-input-amount-screen/upper-limit] + (fn [[{:keys [token-input-value]} + upper-limit]] + (controlled-input-logic/upper-limit-exceeded? + token-input-value + upper-limit))) + +(rf/reg-sub :send-input-amount-screen/upper-limit-equals-input-value? + :<- [:send-input-amount-screen/controller] + :<- [:send-input-amount-screen/upper-limit] + (fn [[{:keys [token-input-value]} + upper-limit]] + (money/equal-to + (money/bignumber token-input-value) + (money/bignumber upper-limit)))) + +(rf/reg-sub :send-input-amount-screen/should-try-again? + :<- [:send-input-amount-screen/upper-limit-exceeded?] + :<- [:send-input-amount-screen/routes-information] + (fn [[upper-limit-exceeded? + {:keys [no-routes-found?]}]] + (and (not upper-limit-exceeded?) no-routes-found?))) + +(rf/reg-sub :send-input-amount-screen/not-enough-asset? + :<- [:send-input-amount-screen/upper-limit-exceeded?] + :<- [:send-input-amount-screen/upper-limit-equals-input-value?] + :<- [:send-input-amount-screen/routes-information] + :<- [:send-input-amount-screen/currency-information] + :<- [:send-input-amount-screen/routes-information] + :<- [:send-input-amount-screen/owned-eth-balance-is-zero?] + (fn [[upper-limit-exceeded? + upper-limit-equals-input-value? + {:keys [no-routes-found?]} + {:keys [sender-network-values]} + {:keys [token-symbol]} + owned-eth-balance-is-zero?]] + (and + (or no-routes-found? upper-limit-exceeded?) + (not-empty sender-network-values) + (if (= token-symbol + (string/upper-case + constants/mainnet-short-name)) + upper-limit-equals-input-value? + owned-eth-balance-is-zero?)))) + +(comment + (rf/sub [:send-input-amount-screen/not-enough-asset?]) + (rf/sub [:send-input-amount-screen/upper-limit-equals-input-value?]) + (:no-routes-found? (rf/sub [:send-input-amount-screen/routes-information])) + (:sender-network-values (rf/sub [:send-input-amount-screen/currency-information])) + (rf/sub [:send-input-amount-screen/not-enough-asset?])) + + (rf/reg-sub :send-input-amount-screen/data :<- [:send-input-amount-screen/controller] :<- [:send-input-amount-screen/currency-information] @@ -292,7 +346,10 @@ :<- [:send-input-amount-screen/max-decimals] :<- [:send-input-amount-screen/fee-formatted] :<- [:send-input-amount-screen/from-enabled-networks] - :<- [:send-input-amount-screen/owned-eth-balance-is-zero?] + :<- [: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?] (fn [[{:keys [crypto-currency? token-input-value] :as controller} {:keys [fiat-currency token-symbol token] :as currency-information} @@ -317,7 +374,10 @@ max-decimals fee-formatted from-enabled-networks - owned-eth-balance-is-zero?]] + upper-limit-exceeded? + should-try-again? + current-address + not-enough-asset?]] {:crypto-currency? crypto-currency? :fiat-currency fiat-currency :token token @@ -329,9 +389,7 @@ :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) + :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 @@ -349,7 +407,9 @@ :sending-to-unpreferred-networks? sending-to-unpreferred-networks? :no-routes-found? no-routes-found? :from-enabled-networks from-enabled-networks - :owned-eth-balance-is-zero? owned-eth-balance-is-zero?})) + :should-try-again? should-try-again? + :current-address current-address + :not-enough-asset? not-enough-asset?})) 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 bd444f801a..89edf324e9 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -21,81 +21,6 @@ [utils.money :as money] [utils.re-frame :as rf])) -#_{:navigation-system [view-id - active-screen?] - - :current-screen-ui-and-state [bottom - handle-on-confirm - on-navigate-back - [crypto-currency? set-crypto-currency] - [input-state set-input-state] - send-from-locked-amounts - clear-input! - on-confirm - input-value - valid-input? - confirm-disabled? - swap-between-fiat-and-crypto - show-select-asset-sheet - input-error - limit-exceeded? - show-no-routes?] - - :currency-and-tokens [usd-conversion-rate - conversion-rate - token-decimals - {token-symbol :symbol - token-networks :networks - :as - token} - currency-symbol - crypto-decimals - amount-in-crypto - fee-formatted] - - :user-profie [{fiat-currency :currency} - currency] - - :accounts [token-balance - {:keys [total-balance] - :as token-by-symbol} - max-limit - current-address] - - :backend-data [loading-routes? - route - first-route - routes - suggested-routes - no-routes-found? - request-fetch-routes - sender-network-values - receiver-network-values - total-amount-receiver - native-currency-symbol - tx-type - token-not-supported-in-receiver-networks? - receiver-networks - receiver-preferred-networks - receiver-preferred-networks-set - sending-to-unpreferred-networks? - should-try-again? - owned-eth-token - not-enough-asset?] - } - -#_[ui - business-logic - - status-go-backend - ] - -#_[] - - - - - (defn- estimated-fees [{:keys [loading-routes? fees recipient-gets-amount]}] [rn/view {:style style/estimated-fees-container} @@ -241,7 +166,9 @@ sending-to-unpreferred-networks? no-routes-found? from-enabled-networks - owned-eth-balance-is-zero?] + should-try-again? + current-address + not-enough-asset?] :as state} (rf/sub [:send-input-amount-screen/data]) ;; from-enabled-networks (rf/sub [:wallet/wallet-send-enabled-networks]) view-id (rf/sub [:view-id]) @@ -251,18 +178,6 @@ show-select-asset-sheet #(rf/dispatch [:show-bottom-sheet {:content (fn [] [select-asset-bottom-sheet])}]) - should-try-again? (and (not upper-limit-exceeded?) no-routes-found?) - current-address (rf/sub [:wallet/current-viewing-account-address]) - 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)) - owned-eth-balance-is-zero?)) show-no-routes? (and (or no-routes-found? upper-limit-exceeded?) (not-empty sender-network-values)