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]]]]
[: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])

View File

@ -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

View File

@ -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]]))

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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]))})
@ -72,12 +74,23 @@
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?
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})]
@ -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]}]

View File

@ -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]}]]

View File

@ -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)))

View File

@ -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

View File

@ -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