From cea8dcae3dac2265d3780c95d6581fe48e9b94a4 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sat, 10 Mar 2018 16:53:42 +0100 Subject: 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 --- packages/website/ts/utils/utils.ts | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'packages/website/ts/utils/utils.ts') diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index a40db805b..5fcd3f8e5 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -4,10 +4,11 @@ import { BigNumber } from '@0xproject/utils'; import deepEqual = require('deep-equal'); import * as _ from 'lodash'; import * as moment from 'moment'; -import { Order, ScreenWidths, Side, SideToAssetToken, Token, TokenByAddress } from 'ts/types'; +import { Order, Providers, ScreenWidths, Side, SideToAssetToken, Token, TokenByAddress } from 'ts/types'; import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; import * as u2f from 'ts/vendor/u2f_api'; +import Web3 = require('web3'); const LG_MIN_EM = 64; const MD_MIN_EM = 52; @@ -268,17 +269,6 @@ export const utils = { const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`; return baseUrl; }, - web3ProviderToString(provider: Web3Provider): string { - let parsedProviderName = provider.constructor.name; - if (provider.constructor.name === 'MetamaskInpageProvider') { - parsedProviderName = 'METAMASK'; - } else if (provider.constructor.name === 'EthereumProvider') { - parsedProviderName = 'MIST'; - } else if ((provider as any).isParity) { - parsedProviderName = 'PARITY'; - } - return parsedProviderName; - }, async onPageLoadAsync(): Promise { if (document.readyState === 'complete') { return; // Already loaded @@ -287,4 +277,25 @@ export const utils = { window.onload = () => resolve(); }); }, + getProviderType(provider: Web3.Provider): Providers | string { + const constructorName = provider.constructor.name; + let parsedProviderName = constructorName; + switch (constructorName) { + case 'MetamaskInpageProvider': + parsedProviderName = Providers.Metamask; + break; + + case 'EthereumProvider': + parsedProviderName = Providers.Mist; + break; + + default: + parsedProviderName = constructorName; + break; + } + if ((provider as any).isParity) { + parsedProviderName = Providers.Parity; + } + return parsedProviderName; + }, }; -- cgit v1.2.3