mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #3 from gabrielbazan7/fix/profileProvider
fix issues with profile provider
This commit is contained in:
commit
fd6ffef015
|
@ -127,7 +127,7 @@
|
|||
"codecov": "2.2.0",
|
||||
"fs-extra": "^4.0.2",
|
||||
"html-loader": "0.4.5",
|
||||
"ionic": "3.13.0",
|
||||
"ionic": "3.13.2",
|
||||
"jasmine-core": "2.6.4",
|
||||
"jasmine-spec-reporter": "4.1.1",
|
||||
"karma": "1.7.0",
|
||||
|
@ -179,4 +179,4 @@
|
|||
"ios"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,24 +49,20 @@ export class CopayApp {
|
|||
}
|
||||
// Check Profile
|
||||
this.profile.loadAndBindProfile().then((profile: any) => {
|
||||
if (profile) {
|
||||
this.logger.info('Profile read. Go to HomePage.');
|
||||
this.openLockModal();
|
||||
this.rootPage = TabsPage;
|
||||
} else {
|
||||
// TODO: go to onboarding page
|
||||
this.logger.warn('Profile does not exist. Go to Onboarding.');
|
||||
this.rootPage = OnboardingPage;
|
||||
}
|
||||
this.logger.info('Profile read. Go to HomePage.');
|
||||
this.openLockModal();
|
||||
if (profile) this.rootPage = TabsPage;
|
||||
}).catch((err: any) => {
|
||||
console.log(err);
|
||||
if (!err) this.profile.createProfile();
|
||||
this.logger.warn(err);
|
||||
this.rootPage = OnboardingPage;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
openLockModal() {
|
||||
let config = this.config.get();
|
||||
let lockMethod = config['lock']['method'];
|
||||
let config: any = this.config.get();
|
||||
let lockMethod = config.lock.method;
|
||||
if (!lockMethod) return;
|
||||
if (lockMethod == 'PIN') this.openPINModal('checkPin');
|
||||
if (lockMethod == 'Fingerprint') this.openFingerprintModal();
|
||||
|
|
|
@ -14,9 +14,8 @@ export class Profile {
|
|||
this.version = '1.0.0';
|
||||
}
|
||||
|
||||
public create(opts?: any): Profile {
|
||||
public create(opts?: any): any {
|
||||
opts = opts ? opts : {};
|
||||
|
||||
let x = new Profile();
|
||||
x.createdOn = Date.now();
|
||||
x.credentials = opts.credentials || [];
|
||||
|
@ -25,7 +24,7 @@ export class Profile {
|
|||
return x;
|
||||
};
|
||||
|
||||
public fromObj(obj: any): Profile {
|
||||
public fromObj(obj: any): any {
|
||||
let x = new Profile();
|
||||
|
||||
x.createdOn = obj.createdOn;
|
||||
|
@ -40,7 +39,7 @@ export class Profile {
|
|||
return x;
|
||||
};
|
||||
|
||||
public fromString(str: string): Profile {
|
||||
public fromString(str: string): any {
|
||||
return this.fromObj(JSON.parse(str));
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
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';
|
||||
|
||||
|
@ -14,19 +12,12 @@ export class OnboardingPage {
|
|||
|
||||
constructor(
|
||||
public navCtrl: NavController,
|
||||
public navParams: NavParams,
|
||||
private profile: ProfileProvider
|
||||
public navParams: NavParams
|
||||
) {
|
||||
}
|
||||
|
||||
ionViewDidLoad() {
|
||||
console.log('ionViewDidLoad OnboardingPage');
|
||||
this.createProfile();
|
||||
}
|
||||
|
||||
createProfile() {
|
||||
// TODO: create a new profile
|
||||
this.profile.createProfile();
|
||||
}
|
||||
|
||||
getStarted() {
|
||||
|
|
|
@ -15,7 +15,7 @@ import { Profile } from '../../models/profile/profile.model';
|
|||
@Injectable()
|
||||
export class ProfileProvider {
|
||||
public wallet: any = {};
|
||||
public profile: Profile;
|
||||
public profile: Profile = new Profile();
|
||||
|
||||
private UPDATE_PERIOD = 15;
|
||||
private throttledBwsEvent: any;
|
||||
|
@ -35,8 +35,6 @@ export class ProfileProvider {
|
|||
private languageProvider: LanguageProvider,
|
||||
private txFormatProvider: TxFormatProvider
|
||||
) {
|
||||
this.profile = new Profile;
|
||||
console.log('Hello ProfileProvider Provider');
|
||||
this.throttledBwsEvent = lodash.throttle((n, wallet) => {
|
||||
this.newBwsEvent(n, wallet);
|
||||
}, 10000);
|
||||
|
@ -527,14 +525,12 @@ export class ProfileProvider {
|
|||
|
||||
public bindProfile(profile: any): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.profile = profile;
|
||||
|
||||
let config = this.configProvider.get();
|
||||
|
||||
let bindWallets = (): Promise<any> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let l = this.profile.credentials.length;
|
||||
let l = profile.credentials.length;
|
||||
let i = 0;
|
||||
let totalBound = 0;
|
||||
|
||||
|
@ -542,7 +538,7 @@ export class ProfileProvider {
|
|||
return resolve();
|
||||
}
|
||||
|
||||
lodash.each(this.profile.credentials, (credentials) => {
|
||||
lodash.each(profile.credentials, (credentials) => {
|
||||
this.bindWallet(credentials).then((bound: number) => {
|
||||
i++;
|
||||
totalBound += bound;
|
||||
|
@ -558,11 +554,10 @@ export class ProfileProvider {
|
|||
};
|
||||
|
||||
bindWallets().then(() => {
|
||||
this.isDisclaimerAccepted().then((val) => {
|
||||
if (!val) {
|
||||
return reject(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
||||
}
|
||||
this.isDisclaimerAccepted().then(() => {
|
||||
return resolve();
|
||||
}).catch(() => {
|
||||
return reject(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
||||
});
|
||||
}).catch((err: any) => {
|
||||
return reject(err);
|
||||
|
@ -574,13 +569,13 @@ export class ProfileProvider {
|
|||
return new Promise((resolve, reject) => {
|
||||
|
||||
let disclaimerAccepted = this.profile && this.profile.disclaimerAccepted;
|
||||
if (disclaimerAccepted) return resolve(true);
|
||||
if (disclaimerAccepted) return resolve();
|
||||
|
||||
// OLD flag
|
||||
this.persistenceProvider.getCopayDisclaimerFlag().then((val) => {
|
||||
if (val) {
|
||||
this.profile.disclaimerAccepted = true;
|
||||
return resolve(true);
|
||||
return resolve();
|
||||
} else {
|
||||
return reject();
|
||||
}
|
||||
|
@ -619,13 +614,12 @@ export class ProfileProvider {
|
|||
return new Promise((resolve, reject) => {
|
||||
this.persistenceProvider.getProfile().then((profile: any) => {
|
||||
if (!profile) {
|
||||
resolve(profile);
|
||||
return reject('NOPROFILE: No profile');
|
||||
return reject();
|
||||
}
|
||||
// Deprecated: storageService.tryToMigrate
|
||||
this.logger.debug('Profile read');
|
||||
this.bindProfile(profile).then(() => {
|
||||
return resolve(profile);
|
||||
return resolve();
|
||||
}).catch((err: any) => {
|
||||
return reject(err);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue