aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/blockchain.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-10 23:53:42 +0800
committerFabio Berger <me@fabioberger.com>2018-03-10 23:53:42 +0800
commitcea8dcae3dac2265d3780c95d6581fe48e9b94a4 (patch)
tree527d82d0123ec38924c4459b833131f379e20f71 /packages/website/ts/blockchain.ts
parentfc7e7d9331692510b2cf5baebcff948ebf0afc07 (diff)
downloaddexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.gz
dexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.zst
dexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.zip
Refactor Analytics so that calls to ReactGA are all in a single module, combining the provider type util function, moving GA id to configs and using utils.onPageLoadAsync
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 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);