aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--yarn.lock39
4 files changed, 81 insertions, 39 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];
},
};
diff --git a/yarn.lock b/yarn.lock
index 2a44c7c80..568ba5564 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1906,6 +1906,10 @@ aes-js@^0.2.3:
version "0.2.4"
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-0.2.4.tgz#94b881ab717286d015fa219e08fb66709dda5a3d"
+aes-js@^3.1.1:
+ version "3.1.2"
+ resolved "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz#db9aabde85d5caabbfc0d4f2a4446960f627146a"
+
agent-base@4, agent-base@^4.1.0, agent-base@~4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.1.tgz#d89e5999f797875674c07d87f260fc41e83e8ca9"
@@ -3347,7 +3351,7 @@ bs-logger@0.x:
dependencies:
fast-json-stable-stringify "^2.0.0"
-bs58@=4.0.1:
+bs58@=4.0.1, bs58@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a"
dependencies:
@@ -3370,6 +3374,14 @@ bs58check@^1.0.8:
bs58 "^3.1.0"
create-hash "^1.1.0"
+bs58check@^2.1.2:
+ version "2.1.2"
+ resolved "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc"
+ dependencies:
+ bs58 "^4.0.0"
+ create-hash "^1.1.0"
+ safe-buffer "^5.1.2"
+
bser@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719"
@@ -5957,6 +5969,19 @@ ethereumjs-wallet@0.6.0:
utf8 "^2.1.1"
uuid "^2.0.1"
+ethereumjs-wallet@~0.6.0:
+ version "0.6.2"
+ resolved "https://registry.npmjs.org/ethereumjs-wallet/-/ethereumjs-wallet-0.6.2.tgz#67244b6af3e8113b53d709124b25477b64aeccda"
+ dependencies:
+ aes-js "^3.1.1"
+ bs58check "^2.1.2"
+ ethereumjs-util "^5.2.0"
+ hdkey "^1.0.0"
+ safe-buffer "^5.1.2"
+ scrypt.js "^0.2.0"
+ utf8 "^3.0.0"
+ uuid "^3.3.2"
+
ethers@~4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.4.tgz#d3f85e8b27f4b59537e06526439b0fb15b44dc65"
@@ -7490,6 +7515,14 @@ hdkey@^0.7.0, hdkey@^0.7.1:
coinstring "^2.0.0"
secp256k1 "^3.0.1"
+hdkey@^1.0.0:
+ version "1.1.0"
+ resolved "https://registry.npmjs.org/hdkey/-/hdkey-1.1.0.tgz#e74e7b01d2c47f797fa65d1d839adb7a44639f29"
+ dependencies:
+ coinstring "^2.0.0"
+ safe-buffer "^5.1.1"
+ secp256k1 "^3.0.1"
+
he@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
@@ -15576,6 +15609,10 @@ utf8@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.2.tgz#1fa0d9270e9be850d9b05027f63519bf46457d96"
+utf8@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1"
+
util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"