aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/blockchain.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-12 18:28:34 +0800
committerGitHub <noreply@github.com>2018-03-12 18:28:34 +0800
commit76a31b6fd69038779166a2532d6d6ee677a91406 (patch)
tree85d37695519c18c9e66e53667c69eb5dd9c8c92b /packages/website/ts/blockchain.ts
parent0ad3d06ef969904ce1121b76ca129d25839af781 (diff)
parent8a58ffda86289d8126fa5ff56ea24f7b31f3757f (diff)
downloaddexon-0x-contracts-76a31b6fd69038779166a2532d6d6ee677a91406.tar.gz
dexon-0x-contracts-76a31b6fd69038779166a2532d6d6ee677a91406.tar.zst
dexon-0x-contracts-76a31b6fd69038779166a2532d6d6ee677a91406.zip
Merge pull request #447 from 0xProject/refactorAnalytics
Refactor Website Analytics
Diffstat (limited to 'packages/website/ts/blockchain.ts')
-rw-r--r--packages/website/ts/blockchain.ts23
1 files changed, 12 insertions, 11 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index 14582eae9..c92023541 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -39,6 +39,7 @@ import {
BlockchainErrs,
ContractInstance,
Order as PortalOrder,
+ Providers,
ProviderType,
Side,
SideToAssetToken,
@@ -58,6 +59,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;
@@ -71,18 +78,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);