Simplify Web3 Provider Identifier (#1861)
* Check in progress * Revert some files to develop.
This commit is contained in:
parent
0f6273ec03
commit
a057136c83
|
@ -43,10 +43,8 @@ import {
|
||||||
donationAddressMap
|
donationAddressMap
|
||||||
} from 'config';
|
} from 'config';
|
||||||
import { isWeb3NodeAvailable } from 'libs/nodes/web3';
|
import { isWeb3NodeAvailable } from 'libs/nodes/web3';
|
||||||
import CipherIcon from 'assets/images/wallets/cipher.svg';
|
import { getWeb3ProviderInfo } from 'utils/web3';
|
||||||
import LedgerIcon from 'assets/images/wallets/ledger.svg';
|
import LedgerIcon from 'assets/images/wallets/ledger.svg';
|
||||||
import MetamaskIcon from 'assets/images/wallets/metamask.svg';
|
|
||||||
import MistIcon from 'assets/images/wallets/mist.svg';
|
|
||||||
import TrezorIcon from 'assets/images/wallets/trezor.svg';
|
import TrezorIcon from 'assets/images/wallets/trezor.svg';
|
||||||
import ParitySignerIcon from 'assets/images/wallets/parity-signer.svg';
|
import ParitySignerIcon from 'assets/images/wallets/parity-signer.svg';
|
||||||
import { wikiLink as paritySignerHelpLink } from 'libs/wallet/non-deterministic/parity';
|
import { wikiLink as paritySignerHelpLink } from 'libs/wallet/non-deterministic/parity';
|
||||||
|
@ -108,41 +106,25 @@ export interface InsecureWalletInfo extends BaseWalletInfo {
|
||||||
// tslint:disable-next-line:no-empty-interface
|
// tslint:disable-next-line:no-empty-interface
|
||||||
interface MiscWalletInfo extends InsecureWalletInfo {}
|
interface MiscWalletInfo extends InsecureWalletInfo {}
|
||||||
|
|
||||||
const WEB3_TYPES = {
|
|
||||||
CipherProvider: {
|
|
||||||
lid: 'X_CIPHER',
|
|
||||||
icon: CipherIcon
|
|
||||||
},
|
|
||||||
MetamaskInpageProvider: {
|
|
||||||
lid: 'X_METAMASK',
|
|
||||||
icon: MetamaskIcon
|
|
||||||
},
|
|
||||||
EthereumProvider: {
|
|
||||||
lid: 'X_MIST',
|
|
||||||
icon: MistIcon
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
type SecureWallets = { [key in SecureWalletName]: SecureWalletInfo };
|
type SecureWallets = { [key in SecureWalletName]: SecureWalletInfo };
|
||||||
type InsecureWallets = { [key in InsecureWalletName]: InsecureWalletInfo };
|
type InsecureWallets = { [key in InsecureWalletName]: InsecureWalletInfo };
|
||||||
type MiscWallet = { [key in MiscWalletName]: MiscWalletInfo };
|
type MiscWallet = { [key in MiscWalletName]: MiscWalletInfo };
|
||||||
type Wallets = SecureWallets & InsecureWallets & MiscWallet;
|
type Wallets = SecureWallets & InsecureWallets & MiscWallet;
|
||||||
|
|
||||||
const WEB3_TYPE: keyof typeof WEB3_TYPES | false =
|
|
||||||
(window as any).web3 && (window as any).web3.currentProvider.constructor.name;
|
|
||||||
|
|
||||||
const SECURE_WALLETS = Object.values(SecureWalletName);
|
const SECURE_WALLETS = Object.values(SecureWalletName);
|
||||||
const INSECURE_WALLETS = Object.values(InsecureWalletName);
|
const INSECURE_WALLETS = Object.values(InsecureWalletName);
|
||||||
const MISC_WALLETS = Object.values(MiscWalletName);
|
const MISC_WALLETS = Object.values(MiscWalletName);
|
||||||
|
|
||||||
|
const web3info = getWeb3ProviderInfo();
|
||||||
|
|
||||||
const WalletDecrypt = withRouter<Props>(
|
const WalletDecrypt = withRouter<Props>(
|
||||||
class WalletDecryptClass extends Component<RouteComponentProps<{}> & Props, State> {
|
class WalletDecryptClass extends Component<RouteComponentProps<{}> & Props, State> {
|
||||||
// https://github.com/Microsoft/TypeScript/issues/13042
|
// https://github.com/Microsoft/TypeScript/issues/13042
|
||||||
// index signature should become [key: Wallets] (from config) once typescript bug is fixed
|
// index signature should become [key: Wallets] (from config) once typescript bug is fixed
|
||||||
public WALLETS: Wallets = {
|
public WALLETS: Wallets = {
|
||||||
[SecureWalletName.WEB3]: {
|
[SecureWalletName.WEB3]: {
|
||||||
lid: WEB3_TYPE && WEB3_TYPES[WEB3_TYPE] ? WEB3_TYPES[WEB3_TYPE].lid : 'X_WEB3',
|
lid: web3info.lid,
|
||||||
icon: WEB3_TYPE && WEB3_TYPES[WEB3_TYPE] && WEB3_TYPES[WEB3_TYPE].icon,
|
icon: web3info.icon,
|
||||||
description: 'ADD_WEB3DESC',
|
description: 'ADD_WEB3DESC',
|
||||||
component: Web3Decrypt,
|
component: Web3Decrypt,
|
||||||
initialParams: {},
|
initialParams: {},
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import MetamaskIcon from 'assets/images/wallets/metamask.svg';
|
||||||
|
import MistIcon from 'assets/images/wallets/mist.svg';
|
||||||
|
import CipherIcon from 'assets/images/wallets/cipher.svg';
|
||||||
|
|
||||||
|
interface Web3ProviderInfo {
|
||||||
|
lid: string;
|
||||||
|
icon: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const WEB3_CONFIGS: {
|
||||||
|
[classname: string]: Web3ProviderInfo;
|
||||||
|
} = {
|
||||||
|
CipherProvider: {
|
||||||
|
lid: 'X_CIPHER',
|
||||||
|
icon: CipherIcon
|
||||||
|
},
|
||||||
|
MetamaskInpageProvider: {
|
||||||
|
lid: 'X_METAMASK',
|
||||||
|
icon: MetamaskIcon
|
||||||
|
},
|
||||||
|
EthereumProvider: {
|
||||||
|
lid: 'X_MIST',
|
||||||
|
icon: MistIcon
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_WEB3_CONFIG: Web3ProviderInfo = {
|
||||||
|
lid: 'X_WEB3',
|
||||||
|
icon: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getWeb3ProviderInfo(): Web3ProviderInfo {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return DEFAULT_WEB3_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
const className = (window as any).web3 && (window as any).web3.currentProvider.constructor.name;
|
||||||
|
if (className && WEB3_CONFIGS[className]) {
|
||||||
|
return WEB3_CONFIGS[className];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DEFAULT_WEB3_CONFIG;
|
||||||
|
}
|
Loading…
Reference in New Issue