diff --git a/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs b/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs index 91b0cc6b88..47c2a03328 100644 --- a/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs +++ b/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs @@ -53,8 +53,7 @@ (assoc account-token :networks (:networks token) :supported-networks (:supported-networks token))) - bridge-to-title (i18n/label :t/bridge-to - {:name (string/upper-case (str token-symbol))})] + bridge-to-title (i18n/label :t/select-network-to-receive)] (hot-reload/use-safe-unmount #(rf/dispatch [:wallet/clean-bridge-to-selection])) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 197e119c0d..5a963fe018 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -25,7 +25,8 @@ [utils.number] [utils.re-frame :as rf] [utils.security.core :as security] - [utils.transforms :as transforms])) + [utils.transforms :as transforms] + [status-im.contexts.wallet.sheets.network-selection.view :as network-selection])) (rf/reg-event-fx :wallet/show-account-created-toast (fn [{:keys [db]} [address]] @@ -327,19 +328,33 @@ (rf/reg-event-fx :wallet/get-keypairs get-keypairs) (rf/reg-event-fx :wallet/bridge-select-token - (fn [{:keys [db]} [{:keys [token token-symbol stack-id start-flow?]}]] + (fn [{:keys [db]} [{:keys [token token-symbol stack-id network start-flow?] :as params}]] (let [missing-recipient? (-> db :wallet :ui :send :to-address nil?) to-address (-> db :wallet :current-viewing-account-address)] {:db (cond-> db :always (assoc-in [:wallet :ui :send :tx-type] :tx/bridge) token (assoc-in [:wallet :ui :send :token] token) token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol) + network (assoc-in [:wallet :ui :send :network] network) missing-recipient? (assoc-in [:wallet :ui :send :to-address] to-address)) - :fx [[:dispatch - [:wallet/wizard-navigate-forward - {:current-screen stack-id - :start-flow? start-flow? - :flow-id :wallet-bridge-flow}]]]}))) + :fx (if (some? network) + [[:dispatch + [:wallet/wizard-navigate-forward + {:current-screen stack-id + :start-flow? start-flow? + :flow-id :wallet-bridge-flow}]]] + [[:dispatch [:wallet/switch-current-viewing-account to-address]] + [:dispatch + [:show-bottom-sheet + {:content (fn [] + [network-selection/view + {:token-symbol (or token-symbol (:symbol token)) + :source :send + :on-select-network (fn [network] + (rf/dispatch [:hide-bottom-sheet]) + (rf/dispatch + [:wallet/select-from-account + (assoc params :network network)]))}])}]]])}))) (rf/reg-event-fx :wallet/start-bridge (fn [{:keys [db]}] 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 38be7b50b8..f3f753cb84 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -2,7 +2,6 @@ (:require [clojure.string :as string] [quo.core :as quo] - [quo.foundations.colors :as colors] [quo.theme] [react-native.core :as rn] [react-native.safe-area :as safe-area] @@ -13,6 +12,7 @@ [status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.send.input-amount.estimated-fees :as estimated-fees] [status-im.contexts.wallet.send.input-amount.style :as style] + [status-im.contexts.wallet.send.routes.view :as routes] [status-im.contexts.wallet.sheets.buy-token.view :as buy-token] [status-im.setup.hot-reload :as hot-reload] [utils.debounce :as debounce] @@ -119,6 +119,7 @@ (string/upper-case constants/mainnet-short-name) [(:chain-id network)]]) suggested-routes (rf/sub [:wallet/wallet-send-suggested-routes]) + tx-type (rf/sub [:wallet/wallet-send-tx-type]) [crypto-currency? set-crypto-currency] (rn/use-state initial-crypto-currency?) [input-state set-input-state] (rn/use-state controlled-input/init-state) @@ -266,7 +267,10 @@ (controlled-input/upper-limit-bn input-state)))}) :status (when (controlled-input/input-error input-state) :error)}]}] - [rn/view {:style {:flex 1}}] + (if (= tx-type :tx/bridge) + [routes/view + {:token token-by-symbol}] + [rn/view {:style {:flex 1}}]) (when not-enough-asset? [not-enough-asset]) (when (or (and (not no-routes-found?) (or loading-routes? route)) diff --git a/src/status_im/contexts/wallet/send/routes/style.cljs b/src/status_im/contexts/wallet/send/routes/style.cljs index c5d46f6a68..56bd62b458 100644 --- a/src/status_im/contexts/wallet/send/routes/style.cljs +++ b/src/status_im/contexts/wallet/send/routes/style.cljs @@ -34,19 +34,3 @@ :top margin-top} inverted? (assoc :transform [{:scaleY -1}]))) - -(def disclaimer - {:margin-horizontal 20 - :margin-top 20 - :margin-bottom 8}) - -(def input-container - {:margin-top 8 - :margin-bottom 12}) - -(defn keyboard-container - [bottom] - {:padding-bottom bottom}) - -(def error-box - {:margin-horizontal 20}) diff --git a/src/status_im/contexts/wallet/send/routes/view.cljs b/src/status_im/contexts/wallet/send/routes/view.cljs index 3994d3cba1..afa338aeed 100644 --- a/src/status_im/contexts/wallet/send/routes/view.cljs +++ b/src/status_im/contexts/wallet/send/routes/view.cljs @@ -1,246 +1,21 @@ (ns status-im.contexts.wallet.send.routes.view (:require [quo.core :as quo] + [quo.theme] [react-native.core :as rn] [status-im.contexts.wallet.common.utils.networks :as network-utils] [status-im.contexts.wallet.send.routes.style :as style] - [status-im.contexts.wallet.send.utils :as send-utils] - [status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences] [utils.i18n :as i18n] [utils.re-frame :as rf])) - (def row-height 44) (def space-between-rows 11) (def network-link-linear-height 10) (def network-link-1x-height 56) (def network-link-2x-height 111) - -(defn- open-preferences - [] - (rf/dispatch - [:show-bottom-sheet - {:content - (fn [] - (let [receiver-networks (rf/sub [:wallet/wallet-send-receiver-networks]) - receiver-preferred-networks (rf/sub - [:wallet/wallet-send-receiver-preferred-networks]) - {token-symbol :symbol - token-networks :supported-networks} (rf/sub [:wallet/wallet-send-token]) - token-chain-ids-set (set (mapv #(:chain-id %) token-networks)) - [selected-receiver-networks - set-selected-receiver-networks] (rn/use-state receiver-networks) - receiver-preferred-networks-set (set receiver-preferred-networks) - receiver-selected-preferred-networks (filter #(contains? - receiver-preferred-networks-set - %) - selected-receiver-networks) - receiver-selected-non-preferred-networks (filter #(not (contains? - receiver-preferred-networks-set - %)) - selected-receiver-networks) - not-available-preferred-networks (filter (fn [preferred-chain-id] - (not (contains? token-chain-ids-set - preferred-chain-id))) - receiver-selected-preferred-networks) - not-available-non-preferred-networks (filter (fn [preferred-chain-id] - (not (contains? - token-chain-ids-set - preferred-chain-id))) - receiver-selected-non-preferred-networks) - first-section-warning-label (when (not-empty not-available-preferred-networks) - (i18n/label - :t/token-not-available-on-networks - {:token-symbol token-symbol - :networks - (network-utils/network-ids->formatted-text - not-available-preferred-networks)})) - second-section-warning-label (when (not-empty - not-available-non-preferred-networks) - (i18n/label - :t/token-not-available-on-networks - {:token-symbol token-symbol - :networks - (network-utils/network-ids->formatted-text - not-available-non-preferred-networks)}))] - [network-preferences/view - {:title (i18n/label :t/edit-receiver-networks) - :first-section-label (i18n/label :t/preferred-by-receiver) - :second-section-label (i18n/label :t/not-preferred-by-receiver) - :selected-networks (set (map network-utils/id->network - receiver-networks)) - :receiver-preferred-networks receiver-preferred-networks - :button-label (i18n/label :t/apply-changes) - :first-section-warning-label first-section-warning-label - :second-section-warning-label second-section-warning-label - :on-change #(set-selected-receiver-networks %) - :on-save (fn [chain-ids] - (rf/dispatch [:hide-bottom-sheet]) - (rf/dispatch [:wallet/update-receiver-networks - chain-ids]))}]))}])) - -#_(defn- edit-amount - [{:keys [chain-id token-symbol send-amount-in-crypto init-amount]}] - (rf/dispatch - [:show-bottom-sheet - {:content - (fn [] - (let [{:keys [network-name] :as network-details} (rf/sub [:wallet/network-details-by-chain-id - chain-id]) - {fiat-currency :currency} (rf/sub [:profile/profile]) - {token-decimals :decimals - :as - token} (rf/sub [:wallet/wallet-send-token]) - currency (rf/sub [:profile/currency]) - currency-symbol (rf/sub [:profile/currency-symbol]) - send-from-locked-amounts (rf/sub - [:wallet/wallet-send-from-locked-amounts]) - {account-color :color} (rf/sub [:wallet/current-viewing-account]) - locked-amount (get send-from-locked-amounts chain-id) - network-name-str (string/capitalize (name network-name)) - [input-state set-input-state] (rn/use-state - (cond-> controlled-input/init-state - init-amount - (controlled-input/set-input-value - (money/to-string init-amount)) - locked-amount - (controlled-input/set-input-value - locked-amount))) - [crypto-currency? set-crypto-currency] (rn/use-state true) - conversion-rate (-> token - :market-values-per-currency - currency - :price) - {token-balance :total-balance} (rf/sub [:wallet/token-by-symbol - (str token-symbol) - [chain-id]]) - current-crypto-limit (utils/get-standard-crypto-format - token - token-balance) - current-fiat-limit (.toFixed (* token-balance conversion-rate) 2) - current-limit (if crypto-currency? - current-crypto-limit - current-fiat-limit) - crypto-decimals token-decimals - input-amount (controlled-input/input-value input-state) - [is-amount-locked? set-is-amount-locked] (rn/use-state (some? locked-amount)) - bottom (safe-area/get-bottom) - amount-in-crypto (if crypto-currency? - input-amount - (number/remove-trailing-zeroes - (.toFixed (/ input-amount - conversion-rate) - crypto-decimals))) - locked-greater-then-send-amount? (let [amount (money/bignumber - amount-in-crypto) - send-amount (money/bignumber - send-amount-in-crypto)] - (and (money/bignumber? amount) - (money/bignumber? send-amount) - (money/greater-than amount - send-amount))) - swap-between-fiat-and-crypto (fn [swap-to-crypto-currency?] - (set-crypto-currency - swap-to-crypto-currency?) - (set-input-state - (fn [input-state] - (controlled-input/set-input-value - input-state - (let [value (controlled-input/input-value - input-state) - new-value - (if - swap-to-crypto-currency? - (.toFixed - (/ value - conversion-rate) - crypto-decimals) - (.toFixed - (* value - conversion-rate) - 12))] - (number/remove-trailing-zeroes - new-value)))))) - lock-or-unlock-amount (fn [] - (if is-amount-locked? - (rf/dispatch [:wallet/lock-from-amount - chain-id - amount-in-crypto]) - (rf/dispatch [:wallet/unlock-from-amount - chain-id])) - (rf/dispatch [:hide-bottom-sheet]))] - (rn/use-effect - (fn [] - (set-input-state #(controlled-input/set-upper-limit % current-limit))) - [current-limit]) - [:<> - [quo/drawer-top - {:title (i18n/label :t/send-from-network {:network network-name-str}) - :description (i18n/label :t/define-amount-sent-from-network {:network network-name-str})}] - [quo/token-input - {:container-style style/input-container - :token token-symbol - :currency fiat-currency - :currency-symbol currency-symbol - :crypto-decimals (min token-decimals 6) - :error? (controlled-input/input-error input-state) - :networks [network-details] - :title (i18n/label - :t/send-limit - {:limit (if crypto-currency? - (utils/make-limit-label-crypto current-limit token-symbol) - (utils/make-limit-label-fiat current-limit currency-symbol))}) - :conversion conversion-rate - :show-keyboard? false - :value (controlled-input/input-value input-state) - :on-swap swap-between-fiat-and-crypto - :allow-selection? false}] - (when locked-greater-then-send-amount? - [quo/information-box - {:type :error - :icon :i/info - :style style/error-box} - (i18n/label :t/value-higher-than-send-amount)]) - [quo/disclaimer - {:on-change (fn [checked?] - (set-is-amount-locked checked?)) - :checked? is-amount-locked? - :container-style style/disclaimer - :icon (if is-amount-locked? - :i/locked - :i/unlocked) - :customization-color account-color} - (i18n/label :t/dont-auto-recalculate-network {:network network-name-str})] - [quo/bottom-actions - {:actions :one-action - :button-one-label (i18n/label :t/update) - :button-one-props {:on-press lock-or-unlock-amount - :customization-color account-color - :disabled? (or (controlled-input/empty-value? input-state) - (controlled-input/input-error input-state) - locked-greater-then-send-amount?)}}] - [quo/numbered-keyboard - {:container-style (style/keyboard-container bottom) - :left-action :dot - :delete-key? true - :on-press (fn [c] - (let [new-text (str input-amount c) - max-decimals (if crypto-currency? crypto-decimals 2) - regex-pattern (str "^\\d*\\.?\\d{0," max-decimals "}$") - regex (re-pattern regex-pattern)] - (when (re-matches regex new-text) - (set-is-amount-locked true) - (set-input-state #(controlled-input/add-character % c))))) - :on-delete (fn [] - (set-is-amount-locked true) - (set-input-state controlled-input/delete-last)) - :on-long-press-delete (fn [] - (set-is-amount-locked true) - (set-input-state controlled-input/delete-all))}]]))}])) - (defn render-network-values - [{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes? + [{:keys [network-values token-symbol receiver? loading-routes? token-not-supported-in-receiver-networks?]}] [rn/view (map-indexed (fn [index @@ -260,21 +35,11 @@ {:key (str (if receiver? "to" "from") "-" chain-id) :style {:margin-top (if (pos? index) 11 7.5)}} [quo/network-bridge - {:amount (if (= network-value-type :not-available) - (i18n/label :t/not-available) - amount-formatted) - :network (network-utils/id->network chain-id) - :status status - :on-press #(when (not loading-routes?) - (cond - (= network-value-type :edit) - (open-preferences) - on-press (on-press chain-id total-amount))) - :on-long-press #(when (and (not loading-routes?) (not= status :disabled)) - (cond - (= network-value-type :add) - (open-preferences) - on-long-press (on-long-press chain-id total-amount)))}]])) + {:amount (if (= network-value-type :not-available) + (i18n/label :t/not-available) + amount-formatted) + :network (network-utils/id->network chain-id) + :status status}]])) network-values)]) (defn render-network-links @@ -314,59 +79,18 @@ :destination destination}]]])) network-links)]) -(defn disable-chain - [chain-id disabled-from-chain-ids token-available-networks-for-suggested-routes] - (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))] - (if (or re-enabling-chain? - (> (count token-available-networks-for-suggested-routes) 1)) - (rf/dispatch [:wallet/disable-from-networks - disabled-chain-ids]) - (rf/dispatch [:toasts/upsert - {:id :disable-chain-error - :type :negative - :text (i18n/label :t/at-least-one-network-must-be-activated)}])))) - (defn view - [{:keys [token theme valid-input? request-fetch-routes on-press-to-network current-screen-id - token-not-supported-in-receiver-networks? send-amount-in-crypto]}] - (let [token-symbol (:symbol token) - nav-current-screen-id (rf/sub [:view-id]) - active-screen? (= nav-current-screen-id current-screen-id) - loading-routes? (rf/sub - [:wallet/wallet-send-loading-suggested-routes?]) - sender-network-values (rf/sub - [:wallet/wallet-send-sender-network-values]) + [{:keys [token]}] + (let [theme (quo.theme/use-theme) + token-symbol (:symbol token) + loading-routes? (rf/sub + [:wallet/wallet-send-loading-suggested-routes?]) + sender-network-values (rf/sub + [:wallet/wallet-send-sender-network-values]) receiver-network-values (rf/sub [:wallet/wallet-send-receiver-network-values]) - network-links (rf/sub [:wallet/wallet-send-network-links]) - disabled-from-chain-ids (rf/sub - [:wallet/wallet-send-disabled-from-chain-ids]) - {token-balances-per-chain :balances-per-chain} (rf/sub [:wallet/wallet-send-token]) - token-available-networks-for-suggested-routes - (send-utils/token-available-networks-for-suggested-routes - {:balances-per-chain token-balances-per-chain - :disabled-chain-ids disabled-from-chain-ids}) - show-routes? (not-empty sender-network-values)] - (rn/use-effect - (fn [] - (when (and active-screen? - (> (count token-available-networks-for-suggested-routes) 0)) - (request-fetch-routes 2000))) - [send-amount-in-crypto valid-input?]) - (rn/use-effect - #(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0)) - (request-fetch-routes 0)) - [disabled-from-chain-ids]) + network-links (rf/sub [:wallet/wallet-send-network-links]) + show-routes? (not-empty sender-network-values)] [rn/scroll-view {:content-container-style style/routes-container} (when show-routes? [rn/view {:style style/routes-header-container} @@ -378,27 +102,18 @@ :container-style style/section-label-right}]]) [rn/view {:style style/routes-inner-container} [render-network-values - {:token-symbol token-symbol - :network-values sender-network-values - :on-press (fn [chain-id-to-disable] - (disable-chain - chain-id-to-disable - disabled-from-chain-ids - token-available-networks-for-suggested-routes)) - :receiver? false - :theme theme - :loading-routes? loading-routes? - :token-not-supported-in-receiver-networks? false}] + {:token-symbol token-symbol + :network-values sender-network-values + :receiver? false + :theme theme + :loading-routes? loading-routes?}] [render-network-links {:network-links network-links :sender-network-values sender-network-values}] [render-network-values - {:token-symbol token-symbol - :network-values receiver-network-values - :on-press on-press-to-network - :receiver? true - :loading-routes? loading-routes? - :theme theme - :token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks? - :on-save #(request-fetch-routes 0)}]]])) + {:token-symbol token-symbol + :network-values receiver-network-values + :receiver? true + :loading-routes? loading-routes? + :theme theme}]]])) diff --git a/translations/en.json b/translations/en.json index 3736ddbcd1..062b0923ac 100644 --- a/translations/en.json +++ b/translations/en.json @@ -794,7 +794,6 @@ "do-not-cheat": "Don't try to cheat", "do-not-cheat-description": "These 12 words give access to all of your funds so it is important that you write them in the correct order, take it seriously.", "do-not-quit": "Do not quit the application or turn off your device. Doing so will lead to data corruption, loss of your Status profile and the inability to use Status.", - "do-not-share": "Do not share", "done": "Done", "dont-ask": "Don't ask me again", @@ -1205,7 +1204,10 @@ "include": "Include", "incoming": "Incoming", "incoming-transaction": "Incoming transaction", - "incorrect-code": ["str", "Sorry the code was incorrect, please enter it again"], + "incorrect-code": [ + "str", + "Sorry the code was incorrect, please enter it again" + ], "incorrect-private-key": "This is not the private key for this key pair", "increase-gas": "Increase Gas", "information-you-input-and-send": "Information you input and send", @@ -2936,5 +2938,6 @@ "your-recovery-phrase": "Your seed phrase", "your-recovery-phrase-description": "This is your seed phrase. You use it to prove that this is your wallet. You only get to see it once! Write it on paper and keep it in a secure place. You will need it if you lose or reinstall your wallet.", "your-tip-limit": "Your tip limit", - "youre-on-mobile-network": "You’re on mobile network" + "youre-on-mobile-network": "You’re on mobile network", + "select-network-to-receive": "Select network to receive" }