Merge pull request #3 from gabrielbazan7/fix/profileProvider

fix issues with profile provider
This commit is contained in:
Gabriel Masclef 2017-10-19 12:27:10 -03:00 committed by GitHub
commit fd6ffef015
5 changed files with 24 additions and 44 deletions

View File

@ -127,7 +127,7 @@
"codecov": "2.2.0", "codecov": "2.2.0",
"fs-extra": "^4.0.2", "fs-extra": "^4.0.2",
"html-loader": "0.4.5", "html-loader": "0.4.5",
"ionic": "3.13.0", "ionic": "3.13.2",
"jasmine-core": "2.6.4", "jasmine-core": "2.6.4",
"jasmine-spec-reporter": "4.1.1", "jasmine-spec-reporter": "4.1.1",
"karma": "1.7.0", "karma": "1.7.0",

View File

@ -49,24 +49,20 @@ export class CopayApp {
} }
// Check Profile // Check Profile
this.profile.loadAndBindProfile().then((profile: any) => { this.profile.loadAndBindProfile().then((profile: any) => {
if (profile) { this.logger.info('Profile read. Go to HomePage.');
this.logger.info('Profile read. Go to HomePage.'); this.openLockModal();
this.openLockModal(); if (profile) this.rootPage = TabsPage;
this.rootPage = TabsPage;
} else {
// TODO: go to onboarding page
this.logger.warn('Profile does not exist. Go to Onboarding.');
this.rootPage = OnboardingPage;
}
}).catch((err: any) => { }).catch((err: any) => {
console.log(err); if (!err) this.profile.createProfile();
this.logger.warn(err);
this.rootPage = OnboardingPage;
}); });
}); });
} }
openLockModal() { openLockModal() {
let config = this.config.get(); let config: any = this.config.get();
let lockMethod = config['lock']['method']; let lockMethod = config.lock.method;
if (!lockMethod) return; if (!lockMethod) return;
if (lockMethod == 'PIN') this.openPINModal('checkPin'); if (lockMethod == 'PIN') this.openPINModal('checkPin');
if (lockMethod == 'Fingerprint') this.openFingerprintModal(); if (lockMethod == 'Fingerprint') this.openFingerprintModal();

View File

@ -14,9 +14,8 @@ export class Profile {
this.version = '1.0.0'; this.version = '1.0.0';
} }
public create(opts?: any): Profile { public create(opts?: any): any {
opts = opts ? opts : {}; opts = opts ? opts : {};
let x = new Profile(); let x = new Profile();
x.createdOn = Date.now(); x.createdOn = Date.now();
x.credentials = opts.credentials || []; x.credentials = opts.credentials || [];
@ -25,7 +24,7 @@ export class Profile {
return x; return x;
}; };
public fromObj(obj: any): Profile { public fromObj(obj: any): any {
let x = new Profile(); let x = new Profile();
x.createdOn = obj.createdOn; x.createdOn = obj.createdOn;
@ -40,7 +39,7 @@ export class Profile {
return x; return x;
}; };
public fromString(str: string): Profile { public fromString(str: string): any {
return this.fromObj(JSON.parse(str)); return this.fromObj(JSON.parse(str));
}; };

View File

@ -1,8 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular'; import { NavController, NavParams } from 'ionic-angular';
import { ProfileProvider } from '../../providers/profile/profile';
import { TourPage } from './tour/tour'; import { TourPage } from './tour/tour';
import { TabsPage } from '../tabs/tabs'; import { TabsPage } from '../tabs/tabs';
@ -14,19 +12,12 @@ export class OnboardingPage {
constructor( constructor(
public navCtrl: NavController, public navCtrl: NavController,
public navParams: NavParams, public navParams: NavParams
private profile: ProfileProvider
) { ) {
} }
ionViewDidLoad() { ionViewDidLoad() {
console.log('ionViewDidLoad OnboardingPage'); console.log('ionViewDidLoad OnboardingPage');
this.createProfile();
}
createProfile() {
// TODO: create a new profile
this.profile.createProfile();
} }
getStarted() { getStarted() {

View File

@ -15,7 +15,7 @@ import { Profile } from '../../models/profile/profile.model';
@Injectable() @Injectable()
export class ProfileProvider { export class ProfileProvider {
public wallet: any = {}; public wallet: any = {};
public profile: Profile; public profile: Profile = new Profile();
private UPDATE_PERIOD = 15; private UPDATE_PERIOD = 15;
private throttledBwsEvent: any; private throttledBwsEvent: any;
@ -35,8 +35,6 @@ export class ProfileProvider {
private languageProvider: LanguageProvider, private languageProvider: LanguageProvider,
private txFormatProvider: TxFormatProvider private txFormatProvider: TxFormatProvider
) { ) {
this.profile = new Profile;
console.log('Hello ProfileProvider Provider');
this.throttledBwsEvent = lodash.throttle((n, wallet) => { this.throttledBwsEvent = lodash.throttle((n, wallet) => {
this.newBwsEvent(n, wallet); this.newBwsEvent(n, wallet);
}, 10000); }, 10000);
@ -527,14 +525,12 @@ export class ProfileProvider {
public bindProfile(profile: any): Promise<any> { public bindProfile(profile: any): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.profile = profile;
let config = this.configProvider.get(); let config = this.configProvider.get();
let bindWallets = (): Promise<any> => { let bindWallets = (): Promise<any> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let l = this.profile.credentials.length; let l = profile.credentials.length;
let i = 0; let i = 0;
let totalBound = 0; let totalBound = 0;
@ -542,7 +538,7 @@ export class ProfileProvider {
return resolve(); return resolve();
} }
lodash.each(this.profile.credentials, (credentials) => { lodash.each(profile.credentials, (credentials) => {
this.bindWallet(credentials).then((bound: number) => { this.bindWallet(credentials).then((bound: number) => {
i++; i++;
totalBound += bound; totalBound += bound;
@ -558,11 +554,10 @@ export class ProfileProvider {
}; };
bindWallets().then(() => { bindWallets().then(() => {
this.isDisclaimerAccepted().then((val) => { this.isDisclaimerAccepted().then(() => {
if (!val) {
return reject(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
}
return resolve(); return resolve();
}).catch(() => {
return reject(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
}); });
}).catch((err: any) => { }).catch((err: any) => {
return reject(err); return reject(err);
@ -574,13 +569,13 @@ export class ProfileProvider {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let disclaimerAccepted = this.profile && this.profile.disclaimerAccepted; let disclaimerAccepted = this.profile && this.profile.disclaimerAccepted;
if (disclaimerAccepted) return resolve(true); if (disclaimerAccepted) return resolve();
// OLD flag // OLD flag
this.persistenceProvider.getCopayDisclaimerFlag().then((val) => { this.persistenceProvider.getCopayDisclaimerFlag().then((val) => {
if (val) { if (val) {
this.profile.disclaimerAccepted = true; this.profile.disclaimerAccepted = true;
return resolve(true); return resolve();
} else { } else {
return reject(); return reject();
} }
@ -619,13 +614,12 @@ export class ProfileProvider {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.persistenceProvider.getProfile().then((profile: any) => { this.persistenceProvider.getProfile().then((profile: any) => {
if (!profile) { if (!profile) {
resolve(profile); return reject();
return reject('NOPROFILE: No profile');
} }
// Deprecated: storageService.tryToMigrate // Deprecated: storageService.tryToMigrate
this.logger.debug('Profile read'); this.logger.debug('Profile read');
this.bindProfile(profile).then(() => { this.bindProfile(profile).then(() => {
return resolve(profile); return resolve();
}).catch((err: any) => { }).catch((err: any) => {
return reject(err); return reject(err);
}); });