diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-11-15 06:54:41 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-11-15 06:54:41 +0800 |
commit | fe23bf9e51dab87ee8c8995a9d53438daff19ea0 (patch) | |
tree | ffaeb68d17894f9efdb03fd7819ff91ca35b28b0 /packages/instant/src/util | |
parent | 1aae112d0e2c2b6c7ac16b491aa8345fe2aff486 (diff) | |
download | dexon-0x-contracts-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar.gz dexon-0x-contracts-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar.zst dexon-0x-contracts-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.zip |
feat: use capital values for enums
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r-- | packages/instant/src/util/env.ts | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/packages/instant/src/util/env.ts b/packages/instant/src/util/env.ts index 448ad5262..4a32f9cb1 100644 --- a/packages/instant/src/util/env.ts +++ b/packages/instant/src/util/env.ts @@ -2,6 +2,7 @@ import * as bowser from 'bowser'; import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; +import { PROVIDER_TYPE_TO_NAME } from '../constants'; import { Browser, OperatingSystem, ProviderType } from '../types'; export const envUtil = { @@ -40,28 +41,25 @@ export const envUtil = { return OperatingSystem.Other; } }, - getProviderName(provider: Provider): ProviderType | string { - const constructorName = provider.constructor.name; - let parsedProviderName = constructorName; - // https://ethereum.stackexchange.com/questions/24266/elegant-way-to-detect-current-provider-int-web3-js - switch (constructorName) { - case 'EthereumProvider': - parsedProviderName = ProviderType.Mist; - break; - - default: - parsedProviderName = constructorName; - break; - } - if ((provider as any).isParity) { - parsedProviderName = ProviderType.Parity; + getProviderType(provider: Provider): ProviderType | undefined { + if (provider.constructor.name === 'EthereumProvider') { + return ProviderType.Mist; + } else if ((provider as any).isParity) { + return ProviderType.Parity; } else if ((provider as any).isMetaMask) { - parsedProviderName = ProviderType.MetaMask; + return ProviderType.MetaMask; } else if (!_.isUndefined(_.get(window, 'SOFA'))) { - parsedProviderName = ProviderType.CoinbaseWallet; + return ProviderType.CoinbaseWallet; } else if (!_.isUndefined(_.get(window, '__CIPHER__'))) { - parsedProviderName = ProviderType.Cipher; + return ProviderType.Cipher; + } + return; + }, + getProviderName(provider: Provider): string { + const providerTypeIfExists = envUtil.getProviderType(provider); + if (_.isUndefined(providerTypeIfExists)) { + return provider.constructor.name; } - return parsedProviderName; + return PROVIDER_TYPE_TO_NAME[providerTypeIfExists]; }, }; |