diff --git a/src/quo/components/wallet/network_bridge/view.cljs b/src/quo/components/wallet/network_bridge/view.cljs index f8a751fceb..fa732dc6f6 100644 --- a/src/quo/components/wallet/network_bridge/view.cljs +++ b/src/quo/components/wallet/network_bridge/view.cljs @@ -35,7 +35,7 @@ :accessible true :accessibility-label :container :on-press on-press - :on-long-press on-long-press} + :on-long-press on-long-press} (if (= status :loading) [rn/view {:style (style/loading-skeleton theme) diff --git a/src/status_im/common/controlled_input/utils.cljs b/src/status_im/common/controlled_input/utils.cljs index d175959ef1..f5fddfe4d4 100644 --- a/src/status_im/common/controlled_input/utils.cljs +++ b/src/status_im/common/controlled_input/utils.cljs @@ -1,12 +1,12 @@ (ns status-im.common.controlled-input.utils (:require - [clojure.string :as string] - [reagent.core :as reagent])) + [clojure.string :as string] + [reagent.core :as reagent])) (defn create-input-state [] - (reagent/atom {:value "" - :error? false + (reagent/atom {:value "" + :error? false :upper-limit nil})) (defn input-value @@ -60,7 +60,7 @@ (defn- can-add-character? [state c] (let [max-length 12 - current (input-value state) + current (input-value state) length-overflow? (>= (count current) max-length) extra-dot? (and (= c dot) (string/includes? current dot)) extra-leading-zero? (and (= current "0") (= "0" (str c))) @@ -88,7 +88,7 @@ (defn delete-last [state] - (let [value (input-value state) + (let [value (input-value state) new-value (subs value 0 (dec (count value)))] (set-input-value state new-value))) 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 026dfced06..7e3c6f5a83 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -1,22 +1,21 @@ (ns status-im.contexts.wallet.send.input-amount.view (:require - [clojure.string :as string] - [quo.core :as quo] - [quo.theme :as quo.theme] - [react-native.core :as rn] - [react-native.safe-area :as safe-area] - [reagent.core :as reagent] - [status-im.common.controlled-input.utils :as controlled-input] - [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] - [status-im.contexts.wallet.common.asset-list.view :as asset-list] - [status-im.contexts.wallet.common.utils :as utils] - [status-im.contexts.wallet.common.utils.send :as send-utils] - [status-im.contexts.wallet.send.input-amount.style :as style] - [status-im.contexts.wallet.send.routes.view :as routes] - [utils.address :as address] - - [utils.i18n :as i18n] - [utils.re-frame :as rf])) + [clojure.string :as string] + [quo.core :as quo] + [quo.theme :as quo.theme] + [react-native.core :as rn] + [react-native.safe-area :as safe-area] + [reagent.core :as reagent] + [status-im.common.controlled-input.utils :as controlled-input] + [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] + [status-im.contexts.wallet.common.asset-list.view :as asset-list] + [status-im.contexts.wallet.common.utils :as utils] + [status-im.contexts.wallet.common.utils.send :as send-utils] + [status-im.contexts.wallet.send.input-amount.style :as style] + [status-im.contexts.wallet.send.routes.view :as routes] + [utils.address :as address] + [utils.i18n :as i18n] + [utils.re-frame :as rf])) (defn- make-limit-label [amount currency] @@ -82,16 +81,16 @@ initial-crypto-currency? :initial-crypto-currency? :or {initial-crypto-currency? true}}] (let [_ (rn/dismiss-keyboard!) - input-state (controlled-input/create-input-state) - bottom (safe-area/get-bottom) - clear-input! #(controlled-input/delete-all input-state) - crypto-currency? (reagent/atom initial-crypto-currency?) - on-navigate-back on-navigate-back - - handle-on-confirm (fn [] - (rf/dispatch [:wallet/send-select-amount - {:amount (controlled-input/input-value input-state) - :stack-id current-screen-id}]))] + input-state (controlled-input/create-input-state) + bottom (safe-area/get-bottom) + clear-input! #(controlled-input/delete-all input-state) + crypto-currency? (reagent/atom initial-crypto-currency?) + on-navigate-back on-navigate-back + + handle-on-confirm (fn [] + (rf/dispatch [:wallet/send-select-amount + {:amount (controlled-input/input-value input-state) + :stack-id current-screen-id}]))] (fn [] (let [{fiat-currency :currency} (rf/sub [:profile/profile]) {token-symbol :symbol @@ -99,16 +98,16 @@ {token-balance :total-balance :as token} (rf/sub - [:wallet/current-viewing-account-tokens-filtered - (str token-symbol)]) + [:wallet/current-viewing-account-tokens-filtered + (str token-symbol)]) conversion-rate (-> token :market-values-per-currency :usd :price) loading-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?]) - + route (rf/sub [:wallet/wallet-send-route]) to-address (rf/sub [:wallet/wallet-send-to-address]) - nav-current-screen-id (rf/sub [:view-id]) - + nav-current-screen-id (rf/sub [:view-id]) + on-confirm (or default-on-confirm handle-on-confirm) crypto-decimals (or default-crypto-decimals (utils/get-crypto-decimals-count token)) @@ -121,9 +120,10 @@ routes-can-be-fetched? (and (= nav-current-screen-id current-screen-id) (not (or (empty? (controlled-input/input-value input-state)) (<= (controlled-input/numeric-value input-state) 0) - (> (controlled-input/numeric-value input-state) (current-limit))))) + (> (controlled-input/numeric-value input-state) + (current-limit))))) current-currency (if @crypto-currency? token-symbol fiat-currency) - input-num-value (controlled-input/numeric-value input-state) + input-num-value (controlled-input/numeric-value input-state) confirm-disabled? (or (nil? route) (empty? route) (empty? (controlled-input/input-value input-state)) @@ -162,33 +162,34 @@ (let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!)) app-keyboard-listener (.addEventListener rn/app-state "change" dismiss-keyboard-fn)] #(.remove app-keyboard-listener)))) - + (rn/use-effect #(controlled-input/set-upper-limit input-state (current-limit)) [@crypto-currency?]) [rn/view {:style style/screen - :accessibility-label (str "container" (when (controlled-input/input-error input-state) "-error"))} + :accessibility-label (str "container" + (when (controlled-input/input-error input-state) "-error"))} [account-switcher/view {:icon-name :i/arrow-left :on-press on-navigate-back :switcher-type :select-account}] [quo/token-input - {:container-style style/input-container - :token token-symbol - :currency current-currency - :crypto-decimals crypto-decimals - :error? (controlled-input/input-error input-state) - :networks (seq token-networks) - :title (i18n/label :t/send-limit {:limit (make-limit-label (current-limit) current-currency)}) - :conversion conversion-rate - :show-keyboard? false - :value (controlled-input/input-value input-state) - :on-swap #(reset! crypto-currency? %) - :on-token-press show-select-asset-sheet}] + {:container-style style/input-container + :token token-symbol + :currency current-currency + :crypto-decimals crypto-decimals + :error? (controlled-input/input-error input-state) + :networks (seq token-networks) + :title (i18n/label :t/send-limit + {:limit (make-limit-label (current-limit) current-currency)}) + :conversion conversion-rate + :show-keyboard? false + :value (controlled-input/input-value input-state) + :on-swap #(reset! crypto-currency? %) + :on-token-press show-select-asset-sheet}] [routes/view - { - :token token + {:token token :input-value (controlled-input/input-value input-state) :routes-can-be-fetched? routes-can-be-fetched?}] (when (or loading-routes? (seq route)) @@ -204,15 +205,15 @@ {:disabled? confirm-disabled? :on-press on-confirm})}] [quo/numbered-keyboard - {:container-style (style/keyboard-container bottom) - :left-action :dot - :delete-key? true - :on-press (fn [c] - (when-not loading-routes? - (controlled-input/add-character input-state c))) - :on-delete (fn [] - (when-not loading-routes? - (controlled-input/delete-last input-state))) + {:container-style (style/keyboard-container bottom) + :left-action :dot + :delete-key? true + :on-press (fn [c] + (when-not loading-routes? + (controlled-input/add-character input-state c))) + :on-delete (fn [] + (when-not loading-routes? + (controlled-input/delete-last input-state))) :on-long-press-delete (fn [] (when-not loading-routes? (controlled-input/delete-all input-state)))}]])))) diff --git a/src/status_im/contexts/wallet/send/routes/view.cljs b/src/status_im/contexts/wallet/send/routes/view.cljs index fc73b6626f..5905483c3b 100644 --- a/src/status_im/contexts/wallet/send/routes/view.cljs +++ b/src/status_im/contexts/wallet/send/routes/view.cljs @@ -1,20 +1,20 @@ (ns status-im.contexts.wallet.send.routes.view (:require - [clojure.string :as string] - [quo.core :as quo] - [quo.foundations.colors :as colors] - [quo.foundations.resources :as resources] - [quo.theme :as quo.theme] - [react-native.core :as rn] - [reagent.core :as reagent] - [status-im.constants :as constants] - [status-im.contexts.wallet.common.utils :as utils] - [status-im.contexts.wallet.common.utils.send :as send-utils] - [status-im.contexts.wallet.send.routes.style :as style] - [utils.debounce :as debounce] - [utils.i18n :as i18n] - [utils.re-frame :as rf] - [utils.vector :as vector-utils])) + [clojure.string :as string] + [quo.core :as quo] + [quo.foundations.colors :as colors] + [quo.foundations.resources :as resources] + [quo.theme :as quo.theme] + [react-native.core :as rn] + [reagent.core :as reagent] + [status-im.constants :as constants] + [status-im.contexts.wallet.common.utils :as utils] + [status-im.contexts.wallet.common.utils.send :as send-utils] + [status-im.contexts.wallet.send.routes.style :as style] + [utils.debounce :as debounce] + [utils.i18n :as i18n] + [utils.re-frame :as rf] + [utils.vector :as vector-utils])) (def ^:private network-priority-score {:ethereum 1 @@ -119,75 +119,6 @@ (fetch-routes)) :customization-color color}}]]))) -#_(defn edit-network-amount - [{:keys [ theme amount network] :as props}] - (tap> props) - (let [network-details (rf/sub [:wallet/network-details]) - {:keys [color]} (rf/sub [:wallet/current-viewing-account]) - selected-networks (rf/sub [:wallet/wallet-send-selected-networks]) - prefix (rf/sub [:wallet/wallet-send-address-prefix]) - prefix-seq (string/split prefix #":") - grouped-details (group-by #(contains? (set prefix-seq) (:short-name %)) network-details) - preferred (get grouped-details true []) - not-preferred (get grouped-details false []) - network-preferences (reagent/atom selected-networks) - toggle-network (fn [{:keys [chain-id]}] - (swap! network-preferences - (fn [preferences] - (if (some #(= % chain-id) preferences) - (vec (remove #(= % chain-id) preferences)) - (conj preferences chain-id)))))] - (fn [] - [rn/view - [quo/drawer-top {:title (i18n/label :t/send-from-network {:network network}) - :subtitle (i18n/label :t/define-amount-sent-from-network {:network network})}] - - - - [quo/token-input - { ;; :container-style style/input-container - :token :ETH - ;; :currency current-currency - ;; :crypto-decimals crypto-decimals - ;; :error? @input-error - :networks '(network) - :title (i18n/label :t/send-limit {:limit "12"}) - ;; :conversion conversion-rate - :show-keyboard? false - :value "80" ; @input-value - ;; :selection @input-selection - ;; :on-change-text #(handle-on-change % (current-limit)) - ;; :on-selection-change selection-change - ;; :on-swap #(handle-swap - ;; {:crypto? % - ;; :currency current-currency - ;; :token-symbol token-symbol - ;; :limit-fiat fiat-limit - ;; :limit-crypto crypto-limit}) - ;; :on-token-press show-select-asset-sheet - }] - - - [quo/disclaimer - {:blur? true - :on-change #() - :checked? false} - (i18n/label :t/dont-auto-recalculate-network {:network network})] - [quo/bottom-actions - {:button-one-label (i18n/label :t/apply-changes) - :button-one-props {:disabled? (= selected-networks @network-preferences) - :on-press (fn []) - :customization-color color}}] - [quo/numbered-keyboard - { ;; :container-style (style/keyboard-container bottom) - :left-action :dot - :delete-key? true - ;; :on-press #(handle-keyboard-press % loading-routes? (current-limit)) - ;; :on-delete #(handle-delete loading-routes? (current-limit)) - ;; :on-long-press-delete #(on-long-press-delete loading-routes?) - }]]))) - - (defn route-item [{:keys [first-item? from-amount to-amount token-symbol from-chain-id to-chain-id from-network to-network on-press-from-network on-press-to-network status theme fetch-routes disabled? @@ -206,14 +137,7 @@ :network from-network :status status :on-press #(when (and on-press-from-network (not loading?)) - (on-press-from-network from-chain-id from-amount)) - ;; :on-long-press #(rf/dispatch [:show-bottom-sheet - ;; {:content (fn [] [edit-network-amount - ;; {:amount from-amount - ;; :theme theme - ;; :network from-network - ;; }])}]) - }] + (on-press-from-network from-chain-id from-amount))}] (if (= status :default) [quo/network-link {:shape :linear @@ -289,29 +213,33 @@ (defn- view-internal [{:keys [token theme input-value routes-can-be-fetched? on-press-to-network]}] - - (let [token-symbol (:symbol token) - loading-suggested-routes? (rf/sub [:wallet/wallet-send-loading-suggested-routes?]) - from-values-by-chain (rf/sub [:wallet/wallet-send-from-values-by-chain]) - to-values-by-chain (rf/sub [:wallet/wallet-send-to-values-by-chain]) - suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes]) - selected-networks (rf/sub [:wallet/wallet-send-selected-networks]) - disabled-from-chain-ids (rf/sub - [:wallet/wallet-send-disabled-from-chain-ids]) - routes (when suggested-routes - (or (:best suggested-routes) [])) + + (let [token-symbol (:symbol token) + loading-suggested-routes? (rf/sub + [:wallet/wallet-send-loading-suggested-routes?]) + from-values-by-chain (rf/sub + [:wallet/wallet-send-from-values-by-chain]) + to-values-by-chain (rf/sub [:wallet/wallet-send-to-values-by-chain]) + suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes]) + selected-networks (rf/sub [:wallet/wallet-send-selected-networks]) + disabled-from-chain-ids (rf/sub + [:wallet/wallet-send-disabled-from-chain-ids]) + routes (when suggested-routes + (or (:best suggested-routes) [])) {token-balances-per-chain :balances-per-chain} (rf/sub [:wallet/current-viewing-account-tokens-filtered (str token-symbol)]) - affordable-networks (send-utils/find-affordable-networks - {:balances-per-chain token-balances-per-chain - :input-value input-value - :selected-networks selected-networks - :disabled-chain-ids disabled-from-chain-ids}) - network-links (if loading-suggested-routes? affordable-networks routes) - show-routes? (or (and (not-empty affordable-networks) - loading-suggested-routes?) - (not-empty routes))] + affordable-networks (send-utils/find-affordable-networks + {:balances-per-chain token-balances-per-chain + :input-value input-value + :selected-networks selected-networks + :disabled-chain-ids disabled-from-chain-ids}) + network-links (if loading-suggested-routes? + affordable-networks + routes) + show-routes? (or (and (not-empty affordable-networks) + loading-suggested-routes?) + (not-empty routes))] (rn/use-effect #(when (> (count affordable-networks) 0) @@ -322,13 +250,13 @@ (fetch-routes input-value routes-can-be-fetched? 0)) [disabled-from-chain-ids]) (if show-routes? - (let [initial-network-links-count (count network-links) - disabled-count (count disabled-from-chain-ids) - network-links (if (not-empty disabled-from-chain-ids) - (add-disabled-networks network-links - disabled-from-chain-ids - loading-suggested-routes?) - network-links) + (let [initial-network-links-count (count network-links) + disabled-count (count disabled-from-chain-ids) + network-links (if (not-empty disabled-from-chain-ids) + (add-disabled-networks network-links + disabled-from-chain-ids + loading-suggested-routes?) + network-links) network-links-with-add-button (if (and (< (- (count network-links) disabled-count) constants/default-network-count) (pos? initial-network-links-count)) @@ -339,32 +267,33 @@ :content-container-style style/routes-container :header [rn/view {:style style/routes-header-container} [quo/section-label - {:section (i18n/label :t/from-label) + {:section (i18n/label :t/from-label) :container-style style/section-label-left}] [quo/section-label - {:section (i18n/label :t/to-label) + {:section (i18n/label :t/to-label) :container-style style/section-label-right}]] - :render-data {:from-values-by-chain from-values-by-chain - :to-values-by-chain to-values-by-chain - :theme theme - :fetch-routes #(fetch-routes % routes-can-be-fetched? 2000) - :on-press-from-network (fn [chain-id _] - (let [disabled-chain-ids (if (contains? (set - disabled-from-chain-ids) - chain-id) - (vec (remove #(= % chain-id) - disabled-from-chain-ids)) - (conj disabled-from-chain-ids - chain-id)) - re-enabling-chain? (< (count disabled-chain-ids) - (count disabled-from-chain-ids))] - (when (or re-enabling-chain? - (> (count affordable-networks) 1)) - (rf/dispatch [:wallet/disable-from-networks - disabled-chain-ids])))) - :on-press-to-network on-press-to-network - :token-symbol token-symbol - :loading-suggested-routes? loading-suggested-routes?} + :render-data + {:from-values-by-chain from-values-by-chain + :to-values-by-chain to-values-by-chain + :theme theme + :fetch-routes #(fetch-routes % routes-can-be-fetched? 2000) + :on-press-from-network (fn [chain-id _] + (let [disabled-chain-ids (if (contains? (set + disabled-from-chain-ids) + chain-id) + (vec (remove #(= % chain-id) + disabled-from-chain-ids)) + (conj disabled-from-chain-ids + chain-id)) + re-enabling-chain? (< (count disabled-chain-ids) + (count disabled-from-chain-ids))] + (when (or re-enabling-chain? + (> (count affordable-networks) 1)) + (rf/dispatch [:wallet/disable-from-networks + disabled-chain-ids])))) + :on-press-to-network on-press-to-network + :token-symbol token-symbol + :loading-suggested-routes? loading-suggested-routes?} :render-fn render-network-link}]) [rn/view {:style style/empty-container} (when (and (not (nil? routes)) (not loading-suggested-routes?))