From c8b2a975f47bdacd1cc255c92ffbe3906b36e7be Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 13 Nov 2018 14:30:27 -0800 Subject: feat: change install wallet panel content based on browser and os --- packages/instant/src/util/env.ts | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/instant/src/util/env.ts (limited to 'packages/instant/src/util/env.ts') diff --git a/packages/instant/src/util/env.ts b/packages/instant/src/util/env.ts new file mode 100644 index 000000000..038ec6c88 --- /dev/null +++ b/packages/instant/src/util/env.ts @@ -0,0 +1,42 @@ +import * as bowser from 'bowser'; + +import { Browser, OperatingSystem } from '../types'; + +export const envUtil = { + getBrowser(): Browser { + if (bowser.chrome) { + return Browser.Chrome; + } else if (bowser.firefox) { + return Browser.Firefox; + } else if (bowser.opera) { + return Browser.Opera; + } else if (bowser.msedge) { + return Browser.Edge; + } else if (bowser.safari) { + return Browser.Safari; + } else { + return Browser.Other; + } + }, + isMobileOperatingSystem(): boolean { + return true; + }, + getOperatingSystem(): OperatingSystem { + return OperatingSystem.iOS; + // if (bowser.android) { + // return OperatingSystem.Android; + // } else if (bowser.ios) { + // return OperatingSystem.iOS; + // } else if (bowser.mac) { + // return OperatingSystem.Mac; + // } else if (bowser.windows) { + // return OperatingSystem.Windows; + // } else if (bowser.windowsphone) { + // return OperatingSystem.WindowsPhone; + // } else if (bowser.linux) { + // return OperatingSystem.Linux; + // } else { + // return OperatingSystem.Other; + // } + }, +}; -- cgit v1.2.3 From 35bfd493e87b5d6c76f5bb2176b0992891a4a555 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 13 Nov 2018 17:07:38 -0800 Subject: feat: display the correct provider type and change unlock / install prompt content --- packages/instant/src/util/env.ts | 61 ++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'packages/instant/src/util/env.ts') diff --git a/packages/instant/src/util/env.ts b/packages/instant/src/util/env.ts index 038ec6c88..448ad5262 100644 --- a/packages/instant/src/util/env.ts +++ b/packages/instant/src/util/env.ts @@ -1,6 +1,8 @@ import * as bowser from 'bowser'; +import { Provider } from 'ethereum-types'; +import * as _ from 'lodash'; -import { Browser, OperatingSystem } from '../types'; +import { Browser, OperatingSystem, ProviderType } from '../types'; export const envUtil = { getBrowser(): Browser { @@ -19,24 +21,47 @@ export const envUtil = { } }, isMobileOperatingSystem(): boolean { - return true; + return bowser.mobile; }, getOperatingSystem(): OperatingSystem { - return OperatingSystem.iOS; - // if (bowser.android) { - // return OperatingSystem.Android; - // } else if (bowser.ios) { - // return OperatingSystem.iOS; - // } else if (bowser.mac) { - // return OperatingSystem.Mac; - // } else if (bowser.windows) { - // return OperatingSystem.Windows; - // } else if (bowser.windowsphone) { - // return OperatingSystem.WindowsPhone; - // } else if (bowser.linux) { - // return OperatingSystem.Linux; - // } else { - // return OperatingSystem.Other; - // } + if (bowser.android) { + return OperatingSystem.Android; + } else if (bowser.ios) { + return OperatingSystem.iOS; + } else if (bowser.mac) { + return OperatingSystem.Mac; + } else if (bowser.windows) { + return OperatingSystem.Windows; + } else if (bowser.windowsphone) { + return OperatingSystem.WindowsPhone; + } else if (bowser.linux) { + return OperatingSystem.Linux; + } else { + 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; + } else if ((provider as any).isMetaMask) { + parsedProviderName = ProviderType.MetaMask; + } else if (!_.isUndefined(_.get(window, 'SOFA'))) { + parsedProviderName = ProviderType.CoinbaseWallet; + } else if (!_.isUndefined(_.get(window, '__CIPHER__'))) { + parsedProviderName = ProviderType.Cipher; + } + return parsedProviderName; }, }; -- cgit v1.2.3 From fe23bf9e51dab87ee8c8995a9d53438daff19ea0 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 14 Nov 2018 14:54:41 -0800 Subject: feat: use capital values for enums --- packages/instant/src/util/env.ts | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'packages/instant/src/util/env.ts') 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]; }, }; -- cgit v1.2.3