chore(wallet): disable bridging on unsupported tokens (#20846)

This commit is contained in:
Jamie Caprani 2024-07-29 11:02:10 +01:00 committed by GitHub
parent 4586f8007c
commit 1f5bb579c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 59 additions and 27 deletions

View File

@ -11,5 +11,5 @@
[:networks [:* [:map [:source :schema.common/image-source]]]] [:networks [:* [:map [:source :schema.common/image-source]]]]
[:on-press {:optional true} [:maybe fn?]] [:on-press {:optional true} [:maybe fn?]]
[:customization-color {:optional true} [:maybe :schema.common/customization-color]] [: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]) :any])

View File

@ -18,6 +18,7 @@
:padding-vertical 8 :padding-vertical 8
:border-radius 12 :border-radius 12
:height 56 :height 56
:opacity (when (= state :disabled) 0.3)
:background-color (background-color state customization-color theme)}) :background-color (background-color state customization-color theme)})
(defn check-color (defn check-color

View File

@ -62,6 +62,7 @@
:on-press-in on-press-in :on-press-in on-press-in
:on-press-out on-press-out :on-press-out on-press-out
:on-press on-press :on-press on-press
:disabled (= state :disabled)
:accessibility-label :token-network} :accessibility-label :token-network}
[info props] [info props]
[values props]])) [values props]]))

View File

@ -559,6 +559,8 @@
(def ^:const bridge-name-erc-1155-transfer "ERC1155Transfer") (def ^:const bridge-name-erc-1155-transfer "ERC1155Transfer")
(def ^:const bridge-name-hop "Hop") (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-uknown 0)
(def ^:const wallet-contract-type-erc-20 1) (def ^:const wallet-contract-type-erc-20 1)
(def ^:const wallet-contract-type-erc-721 2) (def ^:const wallet-contract-type-erc-721 2)

View File

@ -58,9 +58,7 @@
{:content buy-token/view}]) {:content buy-token/view}])
:bridge-action (fn [] :bridge-action (fn []
(rf/dispatch [:wallet/clean-send-data]) (rf/dispatch [:wallet/clean-send-data])
(rf/dispatch [:wallet/wizard-navigate-forward (rf/dispatch [:wallet/start-bridge]))
{:start-flow? true
:flow-id :wallet-bridge-flow}]))
:swap-action (when (ff/enabled? ::ff/wallet.swap) :swap-action (when (ff/enabled? ::ff/wallet.swap)
#(rf/dispatch [:wallet.swap/start]))}]) #(rf/dispatch [:wallet.swap/start]))}])
[quo/tabs [quo/tabs

View File

@ -9,6 +9,7 @@
[{token-symbol :symbol [{token-symbol :symbol
token-name :name token-name :name
total-balance :total-balance total-balance :total-balance
disabled? :bridge-disabled?
:as token} :as token}
_ _ _ _
{:keys [currency currency-symbol on-token-press preselected-token-symbol]}] {:keys [currency currency-symbol on-token-press preselected-token-symbol]}]
@ -25,7 +26,9 @@
:fiat-value fiat-formatted :fiat-value fiat-formatted
:networks (seq (:networks token)) :networks (seq (:networks token))
:on-press #(on-token-press token) :on-press #(on-token-press token)
:state (when (= preselected-token-symbol token-symbol) :state (cond
disabled? :disabled
(= preselected-token-symbol token-symbol)
:selected)}])) :selected)}]))
(defn view (defn view

View File

@ -1,6 +1,7 @@
(ns status-im.contexts.wallet.common.token-value.view (ns status-im.contexts.wallet.common.token-value.view
(:require [quo.core :as quo] (:require [quo.core :as quo]
[status-im.common.not-implemented :as not-implemented] [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.contexts.wallet.sheets.buy-token.view :as buy-token]
[status-im.feature-flags :as ff] [status-im.feature-flags :as ff]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -39,6 +40,7 @@
{:icon :i/bridge {:icon :i/bridge
:accessibility-label :bridge :accessibility-label :bridge
:label (i18n/label :t/bridge) :label (i18n/label :t/bridge)
:disabled? (:bridge-disabled? bridge-params)
:on-press (fn [] :on-press (fn []
(rf/dispatch [:hide-bottom-sheet]) (rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:wallet/bridge-select-token bridge-params]))}) (rf/dispatch [:wallet/bridge-select-token bridge-params]))})
@ -67,20 +69,31 @@
(defn token-value-drawer (defn token-value-drawer
[token watch-only? entry-point] [token watch-only? entry-point]
(let [token-symbol (:token token) (let [token-symbol (:token token)
token-data (first (rf/sub [:wallet/current-viewing-account-tokens-filtered token-data (first (rf/sub [:wallet/current-viewing-account-tokens-filtered
token-symbol])) token-symbol]))
selected-account? (rf/sub [:wallet/current-viewing-account-address]) selected-account? (rf/sub [:wallet/current-viewing-account-address])
token-owners (rf/sub [:wallet/operable-addresses-with-token-symbol token-symbol]) token-owners (rf/sub [:wallet/operable-addresses-with-token-symbol token-symbol])
send-or-bridge-params (if selected-account? send-params (if selected-account?
{:token token-data {:token token-data
:stack-id :screen/wallet.accounts :stack-id :screen/wallet.accounts
:start-flow? true :start-flow? true
:owners token-owners} :owners token-owners}
{:token-symbol token-symbol {:token-symbol token-symbol
:stack-id :wallet-stack :stack-id :wallet-stack
:start-flow? true :start-flow? true
:owners token-owners})] :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 [quo/action-drawer
[(cond->> [(when (ff/enabled? ::ff/wallet.assets-modal-manage-tokens) [(cond->> [(when (ff/enabled? ::ff/wallet.assets-modal-manage-tokens)
(action-manage-tokens watch-only?)) (action-manage-tokens watch-only?))
@ -88,11 +101,11 @@
(action-hide))] (action-hide))]
(not watch-only?) (concat [(action-buy) (not watch-only?) (concat [(action-buy)
(when (seq token-owners) (when (seq token-owners)
(action-send send-or-bridge-params entry-point)) (action-send send-params entry-point))
(action-receive selected-account?) (action-receive selected-account?)
(when (ff/enabled? ::ff/wallet.swap) (action-swap)) (when (ff/enabled? ::ff/wallet.swap) (action-swap))
(when (seq (seq token-owners)) (when (seq (seq token-owners))
(action-bridge send-or-bridge-params))]))]])) (action-bridge bridge-params))]))]]))
(defn view (defn view
[item _ _ {:keys [watch-only? entry-point]}] [item _ _ {:keys [watch-only? entry-point]}]

View File

@ -291,7 +291,11 @@
(rf/reg-event-fx :wallet/start-bridge (rf/reg-event-fx :wallet/start-bridge
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (assoc-in db [:wallet :ui :send :tx-type] :tx/bridge) {: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 (rf/reg-event-fx :wallet/select-bridge-network
(fn [{:keys [db]} [{:keys [network-chain-id stack-id]}]] (fn [{:keys [db]} [{:keys [network-chain-id stack-id]}]]

View File

@ -1,6 +1,7 @@
(ns status-im.contexts.wallet.send.utils (ns status-im.contexts.wallet.send.utils
(:require (:require
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils.networks :as network-utils] [status-im.contexts.wallet.common.utils.networks :as network-utils]
[utils.hex :as utils.hex] [utils.hex :as utils.hex]
[utils.money :as money])) [utils.money :as money]))
@ -249,3 +250,7 @@
money/wei->gwei money/wei->gwei
(money/with-precision precision) (money/with-precision precision)
(str))) (str)))
(defn bridge-disabled?
[token-symbol]
(not (constants/bridge-assets token-symbol)))

View File

@ -416,9 +416,15 @@
:wallet/current-viewing-account-tokens-filtered :wallet/current-viewing-account-tokens-filtered
:<- [:wallet/current-viewing-account] :<- [:wallet/current-viewing-account]
:<- [:wallet/network-details] :<- [:wallet/network-details]
(fn [[account networks] [_ query chain-ids]] :<- [:wallet/wallet-send]
(let [tokens (map (fn [token] (fn [[account networks send-data] [_ query chain-ids]]
(prn send-data)
(let [tx-type (:tx-type send-data)
tokens (map (fn [token]
(assoc token (assoc token
:bridge-disabled? (and (= tx-type :tx/bridge)
(send-utils/bridge-disabled? (:symbol
token)))
:networks (network-utils/network-list token networks) :networks (network-utils/network-list token networks)
:available-balance (utils/calculate-total-token-balance token) :available-balance (utils/calculate-total-token-balance token)
:total-balance (utils/calculate-total-token-balance token :total-balance (utils/calculate-total-token-balance token

View File

@ -12,9 +12,8 @@
[re-frame.events :as rf-events] [re-frame.events :as rf-events]
[re-frame.registrar :as rf-registrar] [re-frame.registrar :as rf-registrar]
[re-frame.subs :as rf-subs] [re-frame.subs :as rf-subs]
[taoensso.timbre :as log] [taoensso.timbre :as log] ;; We must require this namespace to register the custom cljs.test
;; directive `match-strict?`.
;; We must require this namespace to register the custom cljs.test directive `match-strict?`.
test-helpers.matchers)) test-helpers.matchers))
(defn db (defn db