diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-10 23:53:42 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-03-10 23:53:42 +0800 |
commit | cea8dcae3dac2265d3780c95d6581fe48e9b94a4 (patch) | |
tree | 527d82d0123ec38924c4459b833131f379e20f71 /packages/website/ts/utils/utils.ts | |
parent | fc7e7d9331692510b2cf5baebcff948ebf0afc07 (diff) | |
download | dexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar dexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.gz dexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.bz2 dexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.lz dexon-sol-tools-cea8dcae3dac2265d3780c95d6581fe48e9b94a4.tar.xz 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/utils/utils.ts')
-rw-r--r-- | packages/website/ts/utils/utils.ts | 35 |
1 files changed, 23 insertions, 12 deletions
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<void> { 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; + }, }; |