diff --git a/package.json b/package.json index b38b31fcd..c8d36b4d1 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,13 @@ "@angular/http": "4.1.3", "@angular/platform-browser": "4.1.3", "@angular/platform-browser-dynamic": "4.1.3", + "@angular/tsc-wrapped": "^4.3.2", "@ionic-native/core": "3.12.1", "@ionic-native/splash-screen": "3.12.1", "@ionic-native/status-bar": "3.12.1", "@ionic/storage": "2.0.1", "@nsalaun/ng-logger": "^2.0.1", - "@types/lodash": "^4.14.71", + "autoprefixer": "^7.1.2", "ionic-angular": "3.5.3", "ionicons": "3.0.0", "lodash": "^4.17.4", @@ -42,7 +43,9 @@ "@ionic/app-scripts": "2.0.2", "@ionic/cli-plugin-cordova": "1.5.0", "@ionic/cli-plugin-ionic-angular": "1.4.0", + "@types/chrome": "0.0.47", "@types/jasmine": "^2.5.53", + "@types/lodash": "^4.14.71", "@types/node": "^8.0.17", "codecov": "^2.2.0", "ionic": "3.6.0", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5b8958503..0fcbf0bdb 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -22,6 +22,7 @@ import { SplashScreen } from '@ionic-native/splash-screen'; import { WalletProvider } from '../providers/wallet-provider/wallet-provider'; import { StorageProvider } from '../providers/storage-provider/storage-provider'; import { AppProvider } from '../providers/app-provider/app-provider'; +import { PlatformProvider } from '../providers/platform/platform'; // Set different log level depending on environment. const LOG_LEVEL = Level.LOG; @@ -63,7 +64,8 @@ if (isDevMode()){ {provide: ErrorHandler, useClass: IonicErrorHandler}, WalletProvider, StorageProvider, - AppProvider + AppProvider, + PlatformProvider ] }) export class AppModule {} diff --git a/src/providers/platform/platform.ts b/src/providers/platform/platform.ts new file mode 100644 index 000000000..88284a584 --- /dev/null +++ b/src/providers/platform/platform.ts @@ -0,0 +1,93 @@ +import { Injectable } from '@angular/core'; +import { Platform } from 'ionic-angular'; +import { Logger } from '@nsalaun/ng-logger'; + +@Injectable() +export class PlatformProvider { + isAndroid: boolean; + isIOS: boolean; + isWP: boolean; + isSafari: boolean; + isCordova: boolean; + isNW: boolean; + ua: string; + isMobile: boolean; + isChromeApp: boolean; + isDevel: boolean; + supportsLedger: boolean; + supportsTrezor: boolean; + versionIntelTEE: string; + supportsIntelTEE: boolean; + + constructor(private platform: Platform, private log: Logger) { + var ua = navigator ? navigator.userAgent : null; + + if (!ua) { + console.log('Could not determine navigator. Using fixed string'); + ua = 'dummy user-agent'; + } + + // Fixes IOS WebKit UA + ua = ua.replace(/\(\d+\)$/, ''); + + this.isAndroid = platform.is('android'); + this.isIOS = platform.is('ios'); + this.isWP = platform.is('windows') && platform.is('mobile'); + this.ua = ua; + this.isCordova = platform.is('cordova'); + this.isNW = this.isNodeWebkit(); + this.isMobile = platform.is('mobile'); + this.isChromeApp = this.getBrowserName() == 'chrome' && chrome && chrome.runtime && chrome.runtime.id && !this.isNW; + this.isDevel = !this.isMobile && !this.isChromeApp && !this.isNW; + this.supportsLedger = this.isChromeApp; + this.supportsTrezor = this.isChromeApp || this.isDevel; + this.versionIntelTEE = this.getVersionIntelTee(); + this.supportsIntelTEE = this.versionIntelTEE.length > 0; + } + + getBrowserName(): string { + let userAgent = window.navigator.userAgent; + let browsers = { chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer/i }; + + for (let key in browsers) { + if (browsers[key].test(userAgent)) { + return key; + } + }; + + return 'unknown'; + } + + isNodeWebkit(): boolean { + let isNode = (typeof process !== "undefined" && typeof require !== "undefined"); + if (isNode) { + try { + return (typeof require('nw.gui') !== "undefined"); + } catch (e) { + return false; + } + } + } + + getVersionIntelTee(): string { + let v = ''; + let isWindows = navigator.platform.indexOf('Win') > -1; + + if (!this.isNodeWebkit() || !isWindows) { + return v; + } + + try { + var IntelWallet = require('intelWalletCon'); + if (IntelWallet.getVersion) { + v = IntelWallet.getVersion(); + } else { + v = 'Alpha'; + } + if (v.length > 0) { + this.log.info('Intel TEE library ' + v); + } + } catch (e) { } + return v; + } +} diff --git a/src/providers/storage/local-storage.spec.ts b/src/providers/storage/local-storage.spec.ts new file mode 100644 index 000000000..fa7895e67 --- /dev/null +++ b/src/providers/storage/local-storage.spec.ts @@ -0,0 +1,11 @@ +import { LocalStorage } from './local-storage'; + +describe('Local Storage', () => { + it('should do nothing', () => { + expect(true).toBeTruthy(); + }); + it('should get', () => { + var storage = new LocalStorage(); + expect(storage.get('myKey')).toEqual('myKey'); + }); +}); \ No newline at end of file diff --git a/src/providers/storage/local-storage.ts b/src/providers/storage/local-storage.ts new file mode 100644 index 000000000..e509e9e48 --- /dev/null +++ b/src/providers/storage/local-storage.ts @@ -0,0 +1,7 @@ +import { PlatformProvider } from '../platform/platform'; +import { Logger } from '@nsalaun/ng-logger'; + +export class LocalStorage { + constructor(private platform: PlatformProvider, private log: Logger) { + } +} diff --git a/src/providers/storage/storage.spec.ts b/src/providers/storage/storage.spec.ts index ad97296f3..bdadf5b39 100644 --- a/src/providers/storage/storage.spec.ts +++ b/src/providers/storage/storage.spec.ts @@ -4,8 +4,4 @@ describe('Storage Service', () => { it('should do nothing', () => { expect(true).toBeTruthy(); }); - it('should get', () => { - var storage = new StorageProvider(); - expect(storage.get('myKey')).toEqual('myKey'); - }); }); \ No newline at end of file diff --git a/src/providers/storage/storage.ts b/src/providers/storage/storage.ts index 9c715533a..08298e3f2 100644 --- a/src/providers/storage/storage.ts +++ b/src/providers/storage/storage.ts @@ -1,13 +1,10 @@ import { Injectable } from '@angular/core'; +import { Platform } from 'ionic-angular'; + @Injectable() export class StorageProvider { - - constructor() { - console.log('Hello StorageService Provider'); - } - - public get(key:string):string { - return key; + storage: + constructor(public platform: Platform) { } } diff --git a/tsconfig.json b/tsconfig.json index 2e450f9f1..0bc9009af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,5 +22,9 @@ "compileOnSave": false, "atom": { "rewriteTsconfig": false - } -} \ No newline at end of file + }, + "types": [ + "chrome", + "lodash" + ] +}