aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-11-15 06:54:41 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-11-15 06:54:41 +0800
commitfe23bf9e51dab87ee8c8995a9d53438daff19ea0 (patch)
treeffaeb68d17894f9efdb03fd7819ff91ca35b28b0 /packages/instant
parent1aae112d0e2c2b6c7ac16b491aa8345fe2aff486 (diff)
downloaddexon-sol-tools-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar
dexon-sol-tools-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar.gz
dexon-sol-tools-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar.bz2
dexon-sol-tools-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar.lz
dexon-sol-tools-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar.xz
dexon-sol-tools-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.tar.zst
dexon-sol-tools-fe23bf9e51dab87ee8c8995a9d53438daff19ea0.zip
feat: use capital values for enums
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/src/constants.ts9
-rw-r--r--packages/instant/src/types.ts36
-rw-r--r--packages/instant/src/util/env.ts36
3 files changed, 43 insertions, 38 deletions
diff --git a/packages/instant/src/constants.ts b/packages/instant/src/constants.ts
index 8170ae354..5bd2349b3 100644
--- a/packages/instant/src/constants.ts
+++ b/packages/instant/src/constants.ts
@@ -1,6 +1,6 @@
import { BigNumber } from '@0x/utils';
-import { AccountNotReady, AccountState, Network } from './types';
+import { AccountNotReady, AccountState, Network, ProviderType } from './types';
export const BIG_NUMBER_ZERO = new BigNumber(0);
export const ETH_DECIMALS = 18;
@@ -41,3 +41,10 @@ export const LOADING_ACCOUNT: AccountNotReady = {
export const LOCKED_ACCOUNT: AccountNotReady = {
state: AccountState.Locked,
};
+export const PROVIDER_TYPE_TO_NAME: { [key in ProviderType]: string } = {
+ [ProviderType.Cipher]: 'Cipher',
+ [ProviderType.MetaMask]: 'MetaMask',
+ [ProviderType.Mist]: 'Mist',
+ [ProviderType.CoinbaseWallet]: 'Coinbase Wallet',
+ [ProviderType.Parity]: 'Parity',
+};
diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts
index cbb1e2caf..67f21a396 100644
--- a/packages/instant/src/types.ts
+++ b/packages/instant/src/types.ts
@@ -140,28 +140,28 @@ export interface StandardSlidingPanelSettings {
}
export enum Browser {
- Chrome = 'Chrome',
- Firefox = 'Firefox',
- Opera = 'Opera',
- Safari = 'Safari',
- Edge = 'Edge',
- Other = 'Other',
+ Chrome = 'CHROME',
+ Firefox = 'FIREFOX',
+ Opera = 'OPERA',
+ Safari = 'SAFARI',
+ Edge = 'EDGE',
+ Other = 'OTHER',
}
export enum OperatingSystem {
- Android = 'Android',
- iOS = 'iOS',
- Mac = 'Mac',
- Windows = 'Windows',
- WindowsPhone = 'WindowsPhone',
- Linux = 'Linux',
- Other = 'Other',
+ Android = 'ANDROID',
+ iOS = 'IOS',
+ Mac = 'MAC',
+ Windows = 'WINDOWS',
+ WindowsPhone = 'WINDOWS_PHONE',
+ Linux = 'LINUX',
+ Other = 'OTHER',
}
export enum ProviderType {
- Parity = 'Parity',
- MetaMask = 'MetaMask',
- Mist = 'Mist',
- CoinbaseWallet = 'Coinbase Wallet',
- Cipher = 'Cipher',
+ Parity = 'PARITY',
+ MetaMask = 'META_MASK',
+ Mist = 'MIST',
+ CoinbaseWallet = 'COINBASE_WALLET',
+ Cipher = 'CIPHER',
}
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];
},
};