diff options
author | Francesco Agosti <francesco.agosti93@gmail.com> | 2018-07-06 02:09:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-06 02:09:25 +0800 |
commit | e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a (patch) | |
tree | 077f051e45ffb23693c52973443cbf1713398650 /packages/website/ts/utils/utils.ts | |
parent | 87a7a4ad2d55641cbe06d7157df0d8f0996d033a (diff) | |
parent | 302b9deef3a7625caa6d49ccc497936d5e4f07e2 (diff) | |
download | dexon-sol-tools-e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a.tar dexon-sol-tools-e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a.tar.gz dexon-sol-tools-e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a.tar.bz2 dexon-sol-tools-e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a.tar.lz dexon-sol-tools-e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a.tar.xz dexon-sol-tools-e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a.tar.zst dexon-sol-tools-e0f80c5e6aea48e83108d6c6cd481cdce26c9a4a.zip |
Merge pull request #816 from 0xProject/feature/website/portal-mobile-improvements
Make onboarding and wallet copy dynamic based on OS
Diffstat (limited to 'packages/website/ts/utils/utils.ts')
-rw-r--r-- | packages/website/ts/utils/utils.ts | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 2cda41545..623819fc9 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -15,6 +15,7 @@ import { BlockchainCallErrs, BrowserType, Environments, + OperatingSystemType, Order, Providers, ProviderType, @@ -401,9 +402,12 @@ export const utils = { openUrl(url: string): void { window.open(url, '_blank'); }, - isMobile(screenWidth: ScreenWidths): boolean { + isMobileWidth(screenWidth: ScreenWidths): boolean { return screenWidth === ScreenWidths.Sm; }, + isMobileOperatingSystem(): boolean { + return bowser.mobile; + }, getBrowserType(): BrowserType { if (bowser.chrome) { return BrowserType.Chrome; @@ -415,7 +419,59 @@ export const utils = { return BrowserType.Other; } }, + getOperatingSystem(): OperatingSystemType { + if (bowser.android) { + return OperatingSystemType.Android; + } else if (bowser.ios) { + return OperatingSystemType.iOS; + } else if (bowser.mac) { + return OperatingSystemType.Mac; + } else if (bowser.windows) { + return OperatingSystemType.Windows; + } else if (bowser.windowsphone) { + return OperatingSystemType.WindowsPhone; + } else if (bowser.linux) { + return OperatingSystemType.Linux; + } else { + return OperatingSystemType.Other; + } + }, isTokenTracked(token: Token): boolean { return !_.isUndefined(token.trackedTimestamp); }, + // Returns a [downloadLink, isOnMobile] tuple. + getBestWalletDownloadLinkAndIsMobile(): [string, boolean] { + const browserType = utils.getBrowserType(); + const isOnMobile = utils.isMobileOperatingSystem(); + const operatingSystem = utils.getOperatingSystem(); + let downloadLink; + if (isOnMobile) { + switch (operatingSystem) { + case OperatingSystemType.Android: + downloadLink = constants.URL_TOSHI_ANDROID_APP_STORE; + break; + case OperatingSystemType.iOS: + downloadLink = constants.URL_TOSHI_IOS_APP_STORE; + break; + default: + // Toshi is only supported on these mobile OSes - just default to iOS + downloadLink = constants.URL_TOSHI_IOS_APP_STORE; + } + } else { + switch (browserType) { + case BrowserType.Chrome: + downloadLink = constants.URL_METAMASK_CHROME_STORE; + break; + case BrowserType.Firefox: + downloadLink = constants.URL_METAMASK_FIREFOX_STORE; + break; + case BrowserType.Opera: + downloadLink = constants.URL_METAMASK_OPERA_STORE; + break; + default: + downloadLink = constants.URL_METAMASK_HOMEPAGE; + } + } + return [downloadLink, isOnMobile]; + }, }; |