diff options
Diffstat (limited to 'packages/website/ts/blockchain.ts')
-rw-r--r-- | packages/website/ts/blockchain.ts | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index fca9504d7..56a8c99f4 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -37,6 +37,7 @@ import { BlockchainErrs, ContractInstance, Order as PortalOrder, + Providers, ProviderType, Side, SideToAssetToken, @@ -57,6 +58,12 @@ import * as MintableArtifacts from '../contracts/Mintable.json'; const BLOCK_NUMBER_BACK_TRACK = 50; const GWEI_IN_WEI = 1000000000; +const providerToName: { [provider: string]: string } = { + [Providers.Metamask]: constants.PROVIDER_NAME_METAMASK, + [Providers.Parity]: constants.PROVIDER_NAME_PARITY_SIGNER, + [Providers.Mist]: constants.PROVIDER_NAME_MIST, +}; + export class Blockchain { public networkId: number; public nodeVersion: string; @@ -70,18 +77,12 @@ export class Blockchain { private _ledgerSubprovider: LedgerWalletSubprovider; private _defaultGasPrice: BigNumber; private static _getNameGivenProvider(provider: Web3.Provider): string { - if (!_.isUndefined((provider as any).isMetaMask)) { - return constants.PROVIDER_NAME_METAMASK; - } - - // HACK: We use the fact that Parity Signer's provider is an instance of their - // internal `Web3FrameProvider` class. - const isParitySigner = _.startsWith(provider.constructor.toString(), 'function Web3FrameProvider'); - if (isParitySigner) { - return constants.PROVIDER_NAME_PARITY_SIGNER; + const providerType = utils.getProviderType(provider); + const providerNameIfExists = providerToName[providerType]; + if (_.isUndefined(providerNameIfExists)) { + return constants.PROVIDER_NAME_GENERIC; } - - return constants.PROVIDER_NAME_GENERIC; + return providerNameIfExists; } private static async _getProviderAsync(injectedWeb3: Web3, networkIdIfExists: number) { const doesInjectedWeb3Exist = !_.isUndefined(injectedWeb3); |