aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/env.ts
diff options
context:
space:
mode:
authorAugust Skare <post@augustskare.no>2018-11-16 18:28:24 +0800
committerAugust Skare <post@augustskare.no>2018-11-16 18:28:24 +0800
commitc08108144825c33d8db26053c1d2d41460b09359 (patch)
tree6f21ce1e6834e0130b0f6063a097014cc1cc671f /packages/instant/src/util/env.ts
parent54bd7df900316504e4403bc94cffd92930a6c763 (diff)
parentcabb7432b9a6d4a5bb8da6fc7fe4522d24e4ece5 (diff)
downloaddexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar
dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.gz
dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.bz2
dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.lz
dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.xz
dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.tar.zst
dexon-sol-tools-c08108144825c33d8db26053c1d2d41460b09359.zip
Merge branch 'development' into dev-tools-pages
Diffstat (limited to 'packages/instant/src/util/env.ts')
-rw-r--r--packages/instant/src/util/env.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/instant/src/util/env.ts b/packages/instant/src/util/env.ts
new file mode 100644
index 000000000..4a32f9cb1
--- /dev/null
+++ b/packages/instant/src/util/env.ts
@@ -0,0 +1,65 @@
+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 = {
+ 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 bowser.mobile;
+ },
+ getOperatingSystem(): OperatingSystem {
+ 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;
+ }
+ },
+ 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) {
+ return ProviderType.MetaMask;
+ } else if (!_.isUndefined(_.get(window, 'SOFA'))) {
+ return ProviderType.CoinbaseWallet;
+ } else if (!_.isUndefined(_.get(window, '__CIPHER__'))) {
+ return ProviderType.Cipher;
+ }
+ return;
+ },
+ getProviderName(provider: Provider): string {
+ const providerTypeIfExists = envUtil.getProviderType(provider);
+ if (_.isUndefined(providerTypeIfExists)) {
+ return provider.constructor.name;
+ }
+ return PROVIDER_TYPE_TO_NAME[providerTypeIfExists];
+ },
+};