diff --git a/src/quo/components/list_items/token_network/schema.cljs b/src/quo/components/list_items/token_network/schema.cljs index 619696ac00..095a78ac10 100644 --- a/src/quo/components/list_items/token_network/schema.cljs +++ b/src/quo/components/list_items/token_network/schema.cljs @@ -11,5 +11,5 @@ [:networks [:* [:map [:source :schema.common/image-source]]]] [:on-press {:optional true} [:maybe fn?]] [:customization-color {:optional true} [:maybe :schema.common/customization-color]] - [:state {:optional true} [:maybe [:enum :default :active :selected]]]]] + [:state {:optional true} [:maybe [:enum :default :active :selected :disabled]]]]] :any]) diff --git a/src/quo/components/list_items/token_network/style.cljs b/src/quo/components/list_items/token_network/style.cljs index 0ce4ec51f6..04241d614e 100644 --- a/src/quo/components/list_items/token_network/style.cljs +++ b/src/quo/components/list_items/token_network/style.cljs @@ -18,6 +18,7 @@ :padding-vertical 8 :border-radius 12 :height 56 + :opacity (when (= state :disabled) 0.3) :background-color (background-color state customization-color theme)}) (defn check-color diff --git a/src/quo/components/list_items/token_network/view.cljs b/src/quo/components/list_items/token_network/view.cljs index b596cfe7e1..bd09ea829c 100644 --- a/src/quo/components/list_items/token_network/view.cljs +++ b/src/quo/components/list_items/token_network/view.cljs @@ -62,6 +62,7 @@ :on-press-in on-press-in :on-press-out on-press-out :on-press on-press + :disabled (= state :disabled) :accessibility-label :token-network} [info props] [values props]])) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 379f8d17ff..e1d7bbe504 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -559,6 +559,8 @@ (def ^:const bridge-name-erc-1155-transfer "ERC1155Transfer") (def ^:const bridge-name-hop "Hop") +(def ^:const bridge-assets #{"ETH" "USDT" "USDC" "DAI"}) + (def ^:const wallet-contract-type-uknown 0) (def ^:const wallet-contract-type-erc-20 1) (def ^:const wallet-contract-type-erc-721 2) diff --git a/src/status_im/contexts/wallet/account/view.cljs b/src/status_im/contexts/wallet/account/view.cljs index 9448fb9aac..2e990cceb7 100644 --- a/src/status_im/contexts/wallet/account/view.cljs +++ b/src/status_im/contexts/wallet/account/view.cljs @@ -58,9 +58,7 @@ {:content buy-token/view}]) :bridge-action (fn [] (rf/dispatch [:wallet/clean-send-data]) - (rf/dispatch [:wallet/wizard-navigate-forward - {:start-flow? true - :flow-id :wallet-bridge-flow}])) + (rf/dispatch [:wallet/start-bridge])) :swap-action (when (ff/enabled? ::ff/wallet.swap) #(rf/dispatch [:wallet.swap/start]))}]) [quo/tabs diff --git a/src/status_im/contexts/wallet/common/asset_list/view.cljs b/src/status_im/contexts/wallet/common/asset_list/view.cljs index 89284c2760..072bc185d5 100644 --- a/src/status_im/contexts/wallet/common/asset_list/view.cljs +++ b/src/status_im/contexts/wallet/common/asset_list/view.cljs @@ -9,6 +9,7 @@ [{token-symbol :symbol token-name :name total-balance :total-balance + disabled? :bridge-disabled? :as token} _ _ {:keys [currency currency-symbol on-token-press preselected-token-symbol]}] @@ -25,7 +26,9 @@ :fiat-value fiat-formatted :networks (seq (:networks token)) :on-press #(on-token-press token) - :state (when (= preselected-token-symbol token-symbol) + :state (cond + disabled? :disabled + (= preselected-token-symbol token-symbol) :selected)}])) (defn view diff --git a/src/status_im/contexts/wallet/common/token_value/view.cljs b/src/status_im/contexts/wallet/common/token_value/view.cljs index 0dffb3dc94..7f0f27e5f6 100644 --- a/src/status_im/contexts/wallet/common/token_value/view.cljs +++ b/src/status_im/contexts/wallet/common/token_value/view.cljs @@ -1,6 +1,7 @@ (ns status-im.contexts.wallet.common.token-value.view (:require [quo.core :as quo] [status-im.common.not-implemented :as not-implemented] + [status-im.contexts.wallet.send.utils :as send-utils] [status-im.contexts.wallet.sheets.buy-token.view :as buy-token] [status-im.feature-flags :as ff] [utils.i18n :as i18n] @@ -39,6 +40,7 @@ {:icon :i/bridge :accessibility-label :bridge :label (i18n/label :t/bridge) + :disabled? (:bridge-disabled? bridge-params) :on-press (fn [] (rf/dispatch [:hide-bottom-sheet]) (rf/dispatch [:wallet/bridge-select-token bridge-params]))}) @@ -67,20 +69,31 @@ (defn token-value-drawer [token watch-only? entry-point] - (let [token-symbol (:token token) - token-data (first (rf/sub [:wallet/current-viewing-account-tokens-filtered - token-symbol])) - selected-account? (rf/sub [:wallet/current-viewing-account-address]) - token-owners (rf/sub [:wallet/operable-addresses-with-token-symbol token-symbol]) - send-or-bridge-params (if selected-account? - {:token token-data - :stack-id :screen/wallet.accounts - :start-flow? true - :owners token-owners} - {:token-symbol token-symbol - :stack-id :wallet-stack - :start-flow? true - :owners token-owners})] + (let [token-symbol (:token token) + token-data (first (rf/sub [:wallet/current-viewing-account-tokens-filtered + token-symbol])) + selected-account? (rf/sub [:wallet/current-viewing-account-address]) + token-owners (rf/sub [:wallet/operable-addresses-with-token-symbol token-symbol]) + send-params (if selected-account? + {:token token-data + :stack-id :screen/wallet.accounts + :start-flow? true + :owners token-owners} + {:token-symbol token-symbol + :stack-id :wallet-stack + :start-flow? true + :owners token-owners}) + bridge-params (if selected-account? + {:token token-data + :bridge-disabled? (send-utils/bridge-disabled? token-symbol) + :stack-id :screen/wallet.accounts + :start-flow? true + :owners token-owners} + {:token-symbol token-symbol + :bridge-disabled? (send-utils/bridge-disabled? token-symbol) + :stack-id :wallet-stack + :start-flow? true + :owners token-owners})] [quo/action-drawer [(cond->> [(when (ff/enabled? ::ff/wallet.assets-modal-manage-tokens) (action-manage-tokens watch-only?)) @@ -88,11 +101,11 @@ (action-hide))] (not watch-only?) (concat [(action-buy) (when (seq token-owners) - (action-send send-or-bridge-params entry-point)) + (action-send send-params entry-point)) (action-receive selected-account?) (when (ff/enabled? ::ff/wallet.swap) (action-swap)) (when (seq (seq token-owners)) - (action-bridge send-or-bridge-params))]))]])) + (action-bridge bridge-params))]))]])) (defn view [item _ _ {:keys [watch-only? entry-point]}] diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index ddd0104d1d..ad1e81c7ec 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -291,7 +291,11 @@ (rf/reg-event-fx :wallet/start-bridge (fn [{:keys [db]}] {:db (assoc-in db [:wallet :ui :send :tx-type] :tx/bridge) - :fx [[:dispatch [:open-modal :screen/wallet.bridge-select-asset]]]})) + :fx [[:dispatch + [:wallet/wizard-navigate-forward + {:start-flow? true + :flow-id :wallet-bridge-flow}]]]})) + (rf/reg-event-fx :wallet/select-bridge-network (fn [{:keys [db]} [{:keys [network-chain-id stack-id]}]] diff --git a/src/status_im/contexts/wallet/send/utils.cljs b/src/status_im/contexts/wallet/send/utils.cljs index d7695c6e18..29b3c655c3 100644 --- a/src/status_im/contexts/wallet/send/utils.cljs +++ b/src/status_im/contexts/wallet/send/utils.cljs @@ -1,6 +1,7 @@ (ns status-im.contexts.wallet.send.utils (:require [native-module.core :as native-module] + [status-im.constants :as constants] [status-im.contexts.wallet.common.utils.networks :as network-utils] [utils.hex :as utils.hex] [utils.money :as money])) @@ -249,3 +250,7 @@ money/wei->gwei (money/with-precision precision) (str))) + +(defn bridge-disabled? + [token-symbol] + (not (constants/bridge-assets token-symbol))) diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index 52ad2ff29b..83e68bed49 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -416,9 +416,15 @@ :wallet/current-viewing-account-tokens-filtered :<- [:wallet/current-viewing-account] :<- [:wallet/network-details] - (fn [[account networks] [_ query chain-ids]] - (let [tokens (map (fn [token] + :<- [:wallet/wallet-send] + (fn [[account networks send-data] [_ query chain-ids]] + (prn send-data) + (let [tx-type (:tx-type send-data) + tokens (map (fn [token] (assoc token + :bridge-disabled? (and (= tx-type :tx/bridge) + (send-utils/bridge-disabled? (:symbol + token))) :networks (network-utils/network-list token networks) :available-balance (utils/calculate-total-token-balance token) :total-balance (utils/calculate-total-token-balance token diff --git a/src/test_helpers/unit.cljs b/src/test_helpers/unit.cljs index d90fb649bc..821e121d9b 100644 --- a/src/test_helpers/unit.cljs +++ b/src/test_helpers/unit.cljs @@ -12,9 +12,8 @@ [re-frame.events :as rf-events] [re-frame.registrar :as rf-registrar] [re-frame.subs :as rf-subs] - [taoensso.timbre :as log] - - ;; We must require this namespace to register the custom cljs.test directive `match-strict?`. + [taoensso.timbre :as log] ;; We must require this namespace to register the custom cljs.test + ;; directive `match-strict?`. test-helpers.matchers)) (defn db