Enable/Disable wallets by configuration flag (#1504)

* Add disableWallets key to config

* Fix merge issues
This commit is contained in:
Mati Dastugue 2020-10-23 08:30:09 -03:00 committed by GitHub
parent 8aeb5a1c01
commit c9e9fe8ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 23 deletions

View File

@ -1,5 +1,5 @@
import networks from 'src/config/networks' 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 { APP_ENV, ETHERSCAN_API_KEY, GOOGLE_ANALYTICS_ID, INFURA_TOKEN, NETWORK, NODE_ENV } from 'src/utils/constants'
import { ensureOnce } from 'src/utils/singleton' import { ensureOnce } from 'src/utils/singleton'
import memoize from 'lodash.memoize' import memoize from 'lodash.memoize'
@ -25,6 +25,7 @@ const getCurrentEnvironment = (): string => {
type NetworkSpecificConfiguration = EnvironmentSettings & { type NetworkSpecificConfiguration = EnvironmentSettings & {
network: NetworkSettings, network: NetworkSettings,
disabledFeatures?: SafeFeatures, disabledFeatures?: SafeFeatures,
disabledWallets?: Wallets,
} }
const configuration = (): NetworkSpecificConfiguration => { const configuration = (): NetworkSpecificConfiguration => {
@ -50,6 +51,7 @@ const configuration = (): NetworkSpecificConfiguration => {
...networkBaseConfig, ...networkBaseConfig,
network: configFile.network, network: configFile.network,
disabledFeatures: configFile.disabledFeatures, 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 getNetworkConfigDisabledFeatures = (): SafeFeatures => getConfig()?.disabledFeatures || []
export const getNetworkConfigDisabledWallets = (): Wallets => getConfig()?.disabledWallets || []
export const getNetworkInfo = (): NetworkSettings => getConfig()?.network export const getNetworkInfo = (): NetworkSettings => getConfig()?.network
export const getTxServiceUriFrom = (safeAddress: string) => `/safes/${safeAddress}/transactions/` export const getTxServiceUriFrom = (safeAddress: string) => `/safes/${safeAddress}/transactions/`

View File

@ -1,5 +1,23 @@
// matches src/logic/tokens/store/model/token.ts `TokenProps` type // 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 { export enum FEATURES {
ERC721 = 'ERC721', ERC721 = 'ERC721',
ERC1155 = 'ERC1155', ERC1155 = 'ERC1155',
@ -44,6 +62,9 @@ export type NetworkSettings = {
// If non is present, all the sections are available. // If non is present, all the sections are available.
export type SafeFeatures = FEATURES[] export type SafeFeatures = FEATURES[]
export type Wallets = WALLETS[]
type GasPrice = { type GasPrice = {
gasPrice: number gasPrice: number
gasPriceOracleUrl?: string gasPriceOracleUrl?: string
@ -73,5 +94,6 @@ type SafeEnvironments = {
export interface NetworkConfig { export interface NetworkConfig {
network: NetworkSettings network: NetworkSettings
disabledFeatures?: SafeFeatures disabledFeatures?: SafeFeatures
disabledWallets?: Wallets
environment: SafeEnvironments environment: SafeEnvironments
} }

View File

@ -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' import xDaiLogo from 'src/config/assets/token_xdai.svg'
const baseConfig: EnvironmentSettings = { const baseConfig: EnvironmentSettings = {
@ -35,7 +35,11 @@ const xDai: NetworkConfig = {
decimals: 18, decimals: 18,
logoUri: xDaiLogo, logoUri: xDaiLogo,
}, },
} },
disabledWallets:[
WALLETS.TREZOR,
WALLETS.LEDGER
]
} }
export default xDai export default xDai

View File

@ -1,22 +1,24 @@
import { WalletInitOptions } from 'bnc-onboard/dist/src/interfaces' import { WalletInitOptions } from 'bnc-onboard/dist/src/interfaces'
import { getNetworkId, getRpcServiceUrl } from 'src/config' import { getNetworkId, getRpcServiceUrl, getNetworkConfigDisabledWallets } from 'src/config'
import { ETHEREUM_NETWORK } from 'src/config/networks/network.d' import { ETHEREUM_NETWORK, WALLETS } from 'src/config/networks/network.d'
import { FORTMATIC_KEY, PORTIS_ID } from 'src/utils/constants' import { FORTMATIC_KEY, PORTIS_ID } from 'src/utils/constants'
const networkId = getNetworkId() const networkId = getNetworkId()
const disabledWallets = getNetworkConfigDisabledWallets()
const PORTIS_DAPP_ID = PORTIS_ID[networkId] ?? PORTIS_ID[ETHEREUM_NETWORK.RINKEBY] const PORTIS_DAPP_ID = PORTIS_ID[networkId] ?? PORTIS_ID[ETHEREUM_NETWORK.RINKEBY]
const FORTMATIC_API_KEY = FORTMATIC_KEY[networkId] ?? FORTMATIC_KEY[ETHEREUM_NETWORK.RINKEBY] const FORTMATIC_API_KEY = FORTMATIC_KEY[networkId] ?? FORTMATIC_KEY[ETHEREUM_NETWORK.RINKEBY]
type Wallet = WalletInitOptions & { type Wallet = WalletInitOptions & {
desktop: boolean desktop: boolean
walletName: WALLETS
} }
const rpcUrl = getRpcServiceUrl() const rpcUrl = getRpcServiceUrl()
const wallets: Wallet[] = [ const wallets: Wallet[] = [
{ walletName: 'metamask', preferred: true, desktop: false }, { walletName: WALLETS.METAMASK, preferred: true, desktop: false },
{ {
walletName: 'walletConnect', walletName: WALLETS.WALLET_CONNECT,
preferred: true, preferred: true,
// as stated in the documentation, `infuraKey` is not mandatory if rpc is provided // as stated in the documentation, `infuraKey` is not mandatory if rpc is provided
rpc: { [networkId]: rpcUrl }, rpc: { [networkId]: rpcUrl },
@ -24,7 +26,7 @@ const wallets: Wallet[] = [
bridge: 'https://safe-walletconnect.gnosis.io/', bridge: 'https://safe-walletconnect.gnosis.io/',
}, },
{ {
walletName: 'trezor', walletName: WALLETS.TREZOR,
appUrl: 'gnosis-safe.io', appUrl: 'gnosis-safe.io',
preferred: true, preferred: true,
email: 'safe@gnosis.io', email: 'safe@gnosis.io',
@ -32,40 +34,39 @@ const wallets: Wallet[] = [
rpcUrl, rpcUrl,
}, },
{ {
walletName: 'ledger', walletName: WALLETS.LEDGER,
desktop: true, desktop: true,
preferred: true, preferred: true,
rpcUrl, rpcUrl,
LedgerTransport: (window as any).TransportNodeHid, LedgerTransport: (window as any).TransportNodeHid,
}, },
{ walletName: 'trust', preferred: true, desktop: false }, { walletName: WALLETS.TRUST, preferred: true, desktop: false },
{ walletName: 'dapper', desktop: false }, { walletName: WALLETS.DAPPER, desktop: false },
{ {
walletName: 'fortmatic', walletName: WALLETS.FORTMATIC,
apiKey: FORTMATIC_API_KEY, apiKey: FORTMATIC_API_KEY,
desktop: true, desktop: true,
}, },
{ {
walletName: 'portis', walletName: WALLETS.PORTIS,
apiKey: PORTIS_DAPP_ID, apiKey: PORTIS_DAPP_ID,
desktop: true, desktop: true,
}, },
{ walletName: 'authereum', desktop: false }, { walletName: WALLETS.AUTHEREUM, desktop: false },
{ walletName: 'torus', desktop: true }, { walletName: WALLETS.TORUS, desktop: true },
{ walletName: 'unilogin', desktop: true }, { walletName: WALLETS.UNILOGIN, desktop: true },
{ walletName: 'coinbase', desktop: false }, { walletName: WALLETS.COINBASE, desktop: false },
{ walletName: 'walletLink', rpcUrl, desktop: false }, { walletName: WALLETS.WALLET_LINK, rpcUrl, desktop: false },
{ walletName: 'opera', desktop: false }, { walletName: WALLETS.OPERA, desktop: false },
{ walletName: 'operaTouch', desktop: false }, { walletName: WALLETS.OPERA_TOUCH, desktop: false },
] ]
export const getSupportedWallets = (): WalletInitOptions[] => { export const getSupportedWallets = (): WalletInitOptions[] => {
const { isDesktop } = window as any const { isDesktop } = window as any
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
if (isDesktop) { if (isDesktop) {
return wallets.filter((wallet) => wallet.desktop).map(({ desktop, ...rest }) => rest) 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))
} }

View File

@ -38,7 +38,6 @@ const { nativeCoin } = getNetworkInfo()
const ExpandedTx = ({ cancelTx, tx }: ExpandedTxProps): React.ReactElement => { const ExpandedTx = ({ cancelTx, tx }: ExpandedTxProps): React.ReactElement => {
const { fromWei, toBN } = getWeb3().utils const { fromWei, toBN } = getWeb3().utils
const classes = useStyles() const classes = useStyles()
const nonce = useSelector(safeNonceSelector) const nonce = useSelector(safeNonceSelector)
const threshold = useSelector(safeThresholdSelector) as number const threshold = useSelector(safeThresholdSelector) as number