From c9e9fe8ca6edb2cc82e9d73ddbc7b33273befd0f Mon Sep 17 00:00:00 2001 From: Mati Dastugue Date: Fri, 23 Oct 2020 08:30:09 -0300 Subject: [PATCH] Enable/Disable wallets by configuration flag (#1504) * Add disableWallets key to config * Fix merge issues --- src/config/index.ts | 6 ++- src/config/networks/network.d.ts | 22 +++++++++++ src/config/networks/xdai.ts | 8 +++- src/logic/wallets/utils/walletList.ts | 39 ++++++++++--------- .../TxsTable/ExpandedTx/index.tsx | 1 - 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/config/index.ts b/src/config/index.ts index b0657161..92858af0 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,5 +1,5 @@ import networks from 'src/config/networks' -import { EnvironmentSettings, ETHEREUM_NETWORK, NetworkSettings, SafeFeatures } from 'src/config/networks/network.d' +import { EnvironmentSettings, ETHEREUM_NETWORK, NetworkSettings, SafeFeatures, Wallets } from 'src/config/networks/network.d' import { APP_ENV, ETHERSCAN_API_KEY, GOOGLE_ANALYTICS_ID, INFURA_TOKEN, NETWORK, NODE_ENV } from 'src/utils/constants' import { ensureOnce } from 'src/utils/singleton' import memoize from 'lodash.memoize' @@ -25,6 +25,7 @@ const getCurrentEnvironment = (): string => { type NetworkSpecificConfiguration = EnvironmentSettings & { network: NetworkSettings, disabledFeatures?: SafeFeatures, + disabledWallets?: Wallets, } const configuration = (): NetworkSpecificConfiguration => { @@ -50,6 +51,7 @@ const configuration = (): NetworkSpecificConfiguration => { ...networkBaseConfig, network: configFile.network, disabledFeatures: configFile.disabledFeatures, + disabledWallets: configFile.disabledWallets } } @@ -79,6 +81,8 @@ export const getNetworkExplorerInfo = (): { name: string; url: string; apiUrl: s export const getNetworkConfigDisabledFeatures = (): SafeFeatures => getConfig()?.disabledFeatures || [] +export const getNetworkConfigDisabledWallets = (): Wallets => getConfig()?.disabledWallets || [] + export const getNetworkInfo = (): NetworkSettings => getConfig()?.network export const getTxServiceUriFrom = (safeAddress: string) => `/safes/${safeAddress}/transactions/` diff --git a/src/config/networks/network.d.ts b/src/config/networks/network.d.ts index c42b6ef8..c3b0c898 100644 --- a/src/config/networks/network.d.ts +++ b/src/config/networks/network.d.ts @@ -1,5 +1,23 @@ // matches src/logic/tokens/store/model/token.ts `TokenProps` type +export enum WALLETS { + METAMASK = 'metamask', + WALLET_CONNECT = 'walletConnect', + TREZOR = 'trezor', + LEDGER = 'ledger', + TRUST = 'trust', + DAPPER = 'dapper', + FORTMATIC = 'fortmatic', + PORTIS = 'portis', + AUTHEREUM = 'authereum', + TORUS = 'torus', + UNILOGIN = 'unilogin', + COINBASE = 'coinbase', + WALLET_LINK = 'walletLink', + OPERA = 'opera', + OPERA_TOUCH = 'operaTouch' +} + export enum FEATURES { ERC721 = 'ERC721', ERC1155 = 'ERC1155', @@ -44,6 +62,9 @@ export type NetworkSettings = { // If non is present, all the sections are available. export type SafeFeatures = FEATURES[] +export type Wallets = WALLETS[] + + type GasPrice = { gasPrice: number gasPriceOracleUrl?: string @@ -73,5 +94,6 @@ type SafeEnvironments = { export interface NetworkConfig { network: NetworkSettings disabledFeatures?: SafeFeatures + disabledWallets?: Wallets environment: SafeEnvironments } diff --git a/src/config/networks/xdai.ts b/src/config/networks/xdai.ts index 927edb8e..dee4c790 100644 --- a/src/config/networks/xdai.ts +++ b/src/config/networks/xdai.ts @@ -1,4 +1,4 @@ -import { EnvironmentSettings, ETHEREUM_NETWORK, NetworkConfig } from 'src/config/networks/network.d' +import { EnvironmentSettings, ETHEREUM_NETWORK, WALLETS, NetworkConfig } from 'src/config/networks/network.d' import xDaiLogo from 'src/config/assets/token_xdai.svg' const baseConfig: EnvironmentSettings = { @@ -35,7 +35,11 @@ const xDai: NetworkConfig = { decimals: 18, logoUri: xDaiLogo, }, - } + }, + disabledWallets:[ + WALLETS.TREZOR, + WALLETS.LEDGER + ] } export default xDai diff --git a/src/logic/wallets/utils/walletList.ts b/src/logic/wallets/utils/walletList.ts index 1939a1c3..02f13f09 100644 --- a/src/logic/wallets/utils/walletList.ts +++ b/src/logic/wallets/utils/walletList.ts @@ -1,22 +1,24 @@ import { WalletInitOptions } from 'bnc-onboard/dist/src/interfaces' -import { getNetworkId, getRpcServiceUrl } from 'src/config' -import { ETHEREUM_NETWORK } from 'src/config/networks/network.d' +import { getNetworkId, getRpcServiceUrl, getNetworkConfigDisabledWallets } from 'src/config' +import { ETHEREUM_NETWORK, WALLETS } from 'src/config/networks/network.d' import { FORTMATIC_KEY, PORTIS_ID } from 'src/utils/constants' const networkId = getNetworkId() +const disabledWallets = getNetworkConfigDisabledWallets() const PORTIS_DAPP_ID = PORTIS_ID[networkId] ?? PORTIS_ID[ETHEREUM_NETWORK.RINKEBY] const FORTMATIC_API_KEY = FORTMATIC_KEY[networkId] ?? FORTMATIC_KEY[ETHEREUM_NETWORK.RINKEBY] type Wallet = WalletInitOptions & { desktop: boolean + walletName: WALLETS } const rpcUrl = getRpcServiceUrl() const wallets: Wallet[] = [ - { walletName: 'metamask', preferred: true, desktop: false }, + { walletName: WALLETS.METAMASK, preferred: true, desktop: false }, { - walletName: 'walletConnect', + walletName: WALLETS.WALLET_CONNECT, preferred: true, // as stated in the documentation, `infuraKey` is not mandatory if rpc is provided rpc: { [networkId]: rpcUrl }, @@ -24,7 +26,7 @@ const wallets: Wallet[] = [ bridge: 'https://safe-walletconnect.gnosis.io/', }, { - walletName: 'trezor', + walletName: WALLETS.TREZOR, appUrl: 'gnosis-safe.io', preferred: true, email: 'safe@gnosis.io', @@ -32,40 +34,39 @@ const wallets: Wallet[] = [ rpcUrl, }, { - walletName: 'ledger', + walletName: WALLETS.LEDGER, desktop: true, preferred: true, rpcUrl, LedgerTransport: (window as any).TransportNodeHid, }, - { walletName: 'trust', preferred: true, desktop: false }, - { walletName: 'dapper', desktop: false }, + { walletName: WALLETS.TRUST, preferred: true, desktop: false }, + { walletName: WALLETS.DAPPER, desktop: false }, { - walletName: 'fortmatic', + walletName: WALLETS.FORTMATIC, apiKey: FORTMATIC_API_KEY, desktop: true, }, { - walletName: 'portis', + walletName: WALLETS.PORTIS, apiKey: PORTIS_DAPP_ID, desktop: true, }, - { walletName: 'authereum', desktop: false }, - { walletName: 'torus', desktop: true }, - { walletName: 'unilogin', desktop: true }, - { walletName: 'coinbase', desktop: false }, - { walletName: 'walletLink', rpcUrl, desktop: false }, - { walletName: 'opera', desktop: false }, - { walletName: 'operaTouch', desktop: false }, + { walletName: WALLETS.AUTHEREUM, desktop: false }, + { walletName: WALLETS.TORUS, desktop: true }, + { walletName: WALLETS.UNILOGIN, desktop: true }, + { walletName: WALLETS.COINBASE, desktop: false }, + { walletName: WALLETS.WALLET_LINK, rpcUrl, desktop: false }, + { walletName: WALLETS.OPERA, desktop: false }, + { walletName: WALLETS.OPERA_TOUCH, desktop: false }, ] export const getSupportedWallets = (): WalletInitOptions[] => { const { isDesktop } = window as any /* eslint-disable no-unused-vars */ - if (isDesktop) { return wallets.filter((wallet) => wallet.desktop).map(({ desktop, ...rest }) => rest) } - return wallets.map(({ desktop, ...rest }) => rest) + return wallets.map(({ desktop, ...rest }) => rest).filter((w) => !disabledWallets.includes(w.walletName)) } diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.tsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.tsx index 8ef6da59..728f05ce 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.tsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.tsx @@ -38,7 +38,6 @@ const { nativeCoin } = getNetworkInfo() const ExpandedTx = ({ cancelTx, tx }: ExpandedTxProps): React.ReactElement => { const { fromWei, toBN } = getWeb3().utils - const classes = useStyles() const nonce = useSelector(safeNonceSelector) const threshold = useSelector(safeThresholdSelector) as number