diff --git a/package.json b/package.json index 430d3cbce..f2e4f1c40 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@ionic-native/clipboard": "4.1.0", "@ionic-native/core": "3.12.1", "@ionic-native/file": "4.1.0", - "@ionic-native/qr-scanner": "^4.1.0", + "@ionic-native/qr-scanner": "4.1.0", "@ionic-native/social-sharing": "4.1.0", "@ionic-native/splash-screen": "3.12.1", "@ionic-native/status-bar": "3.12.1", @@ -39,13 +39,15 @@ "@ngx-translate/core": "6.0.1", "@nsalaun/ng-logger": "2.0.1", "ajv": "5.2.2", + "angular2-moment": "1.7.0", "autoprefixer": "7.1.2", - "cordova-android": "^6.2.3", + "bitcore-wallet-client": "6.0.0", + "cordova-android": "6.2.3", "cordova-clipboard": "1.0.0", "cordova-ios": "4.4.0", "cordova-plugin-console": "1.0.5", "cordova-plugin-device": "1.1.4", - "cordova-plugin-qrscanner": "^2.5.0", + "cordova-plugin-qrscanner": "2.5.0", "cordova-plugin-splashscreen": "4.0.3", "cordova-plugin-statusbar": "2.2.2", "cordova-plugin-whitelist": "1.3.1", @@ -115,4 +117,4 @@ "ios" ] } -} \ No newline at end of file +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6b0debc83..8313f97d8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -16,6 +16,7 @@ import { NgLoggerModule, Logger, Level } from '@nsalaun/ng-logger'; import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { TranslatePoHttpLoader } from '@biesbjerg/ngx-translate-po-http-loader'; import { NgxQRCodeModule } from 'ngx-qrcode2'; +import { MomentModule } from 'angular2-moment'; /* Copay App */ import { CopayApp } from './app.component'; @@ -50,6 +51,7 @@ import { ConfigProvider } from '../providers/config/config'; import { LanguageProvider } from '../providers/language/language'; import { ScanProvider } from '../providers/scan/scan'; import { ProfileProvider } from '../providers/profile/profile'; +import { BwcProvider } from '../providers/bwc/bwc'; export function createTranslateLoader(http: Http) { return new TranslatePoHttpLoader(http, 'assets/i18n', '.po'); @@ -79,6 +81,7 @@ export function createTranslateLoader(http: Http) { HttpModule, NgLoggerModule.forRoot(Level.LOG), NgxQRCodeModule, + MomentModule, TranslateModule.forRoot({ loader: { provide: TranslateLoader, @@ -136,7 +139,8 @@ export function createTranslateLoader(http: Http) { LanguageProvider, QRScanner, ScanProvider, - ProfileProvider + ProfileProvider, + BwcProvider ] }) export class AppModule { } diff --git a/src/pages/onboarding/onboarding.ts b/src/pages/onboarding/onboarding.ts index d0dd912eb..e1448aadf 100644 --- a/src/pages/onboarding/onboarding.ts +++ b/src/pages/onboarding/onboarding.ts @@ -1,6 +1,8 @@ import { Component } from '@angular/core'; import { NavController, NavParams } from 'ionic-angular'; +import { ProfileProvider } from '../../providers/profile/profile'; + import { TourPage } from './tour/tour'; import { TabsPage } from '../tabs/tabs'; @@ -12,16 +14,19 @@ export class OnboardingPage { constructor( public navCtrl: NavController, - public navParams: NavParams + public navParams: NavParams, + private profile: ProfileProvider ) { } ionViewDidLoad() { console.log('ionViewDidLoad OnboardingPage'); + this.createProfile(); } createProfile() { // TODO: create a new profile + this.profile.create(); } getStarted() { diff --git a/src/providers/bwc/bwc.ts b/src/providers/bwc/bwc.ts new file mode 100644 index 000000000..5dd162a64 --- /dev/null +++ b/src/providers/bwc/bwc.ts @@ -0,0 +1,48 @@ +import { Injectable } from '@angular/core'; + +//import * as BWC from 'bitcore-wallet-client'; + +@Injectable() +export class BwcProvider { + /* + public buildTx = BWC.buildTx; + public parseSecret = BWC.parseSecret; + public Client = BWC; + */ + constructor() { + console.log('Hello BwcProvider Provider'); + } + /* + getBitcore() { + return BWC.Bitcore; + } + + getErrors() { + return BWC.errors; + } + + getSJCL() { + return BWC.sjcl; + } + + getUtils() { + return BWC.Utils; + } + + getClient(walletData, opts) { + opts = opts || {}; + + //note opts use `bwsurl` all lowercase; + let bwc = new BWC({ + baseUrl: opts.bwsurl || 'https://bws.bitpay.com/bws/api', + verbose: opts.verbose, + timeout: 100000, + transports: ['polling'], + }); + if (walletData) + bwc.import(walletData, opts); + return bwc; + } + */ + +} diff --git a/src/providers/profile/profile.ts b/src/providers/profile/profile.ts index 937fb010d..a4d9b63d2 100644 --- a/src/providers/profile/profile.ts +++ b/src/providers/profile/profile.ts @@ -1,11 +1,40 @@ import { Injectable } from '@angular/core'; +import * as moment from 'moment'; +import * as _ from 'lodash'; import { PersistenceProvider } from '../persistence/persistence'; +import { ConfigProvider } from '../config/config'; +import { BwcProvider } from '../bwc/bwc'; + +interface Profile { + version: string; + createdOn: Number; + credentials: Array; + disclaimerAccepted: boolean; + checked: Object; + checkedUA?: Object; +} + +class Profile implements Profile { + constructor( + public version: string = '1.0.0', + public createdOn: Number = moment( new Date() ).valueOf(), + public credentials: Array = new Array(), + public disclaimerAccepted: boolean = false, + public checked: Object = new Object() + ) { + // Nothing to do + } + +} @Injectable() export class ProfileProvider { + public profile: Profile; constructor( - private persistence: PersistenceProvider + private persistence: PersistenceProvider, + private config: ConfigProvider, + private bwc: BwcProvider ) { console.log('Hello ProfileProvider Provider'); } @@ -20,4 +49,45 @@ export class ProfileProvider { }); }; + create() { + this.profile = new Profile(); + + console.log('[profile.ts:33]', this.profile); //TODO + + this.persistence.storeNewProfile(this.profile).then(() => { + // bindProfile (this.profile) + }, (error) => { + // Todo: error? + }); + } + + bind(profile: Profile) { + let l = profile.credentials.length; + let i = 0; + let totalBound = 0; + + if (!l) return; + + _.each(profile.credentials, function(credentials) { + this.bindWallet(credentials, function(err, bound) { + i++; + totalBound += bound; + if (i == l) { + console.log('Bound ' + totalBound + ' out of ' + l + ' wallets'); + return; + } + }); + }); + } + + bindWallet(credentials) { + let defaults = this.config.get(); + + /* + let client = this.bwc.getClient(JSON.stringify(credentials), { + bwsurl: defaults['bws']['url'], + }); + */ + } + }