Merge pull request #7007 from gabrielbazan7/fix/profileSetUp

fix profile set up
This commit is contained in:
Gustavo Maximiliano Cortez 2017-10-30 16:43:09 -03:00 committed by GitHub
commit c5eb33bcb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 41 deletions

View File

@ -77,7 +77,7 @@
"angular2-qrcode": "2.0.1",
"asn1.js": "4.5.2",
"autoprefixer": "7.1.2",
"bitcore-wallet-client": "6.2.0",
"bitcore-wallet-client": "6.4.0",
"buffer-compare": "1.1.1",
"cordova-android": "6.2.3",
"cordova-clipboard": "^1.1.0",
@ -129,7 +129,7 @@
"codecov": "2.2.0",
"fs-extra": "^4.0.2",
"html-loader": "0.4.5",
"ionic": "3.15.0",
"ionic": "3.15.2",
"jasmine-core": "2.6.4",
"jasmine-spec-reporter": "4.1.1",
"karma": "1.7.0",

View File

@ -13,6 +13,7 @@ import { TabsPage } from '../pages/tabs/tabs';
import { OnboardingPage } from '../pages/onboarding/onboarding';
import { PinModalPage } from '../pages/pin/pin';
import { FingerprintModalPage } from '../pages/fingerprint/fingerprint';
import { DisclaimerPage } from '../pages/onboarding/disclaimer/disclaimer';
@Component({
templateUrl: 'app.html',
@ -49,13 +50,15 @@ export class CopayApp {
}
// Check Profile
this.profile.loadAndBindProfile().then((profile: any) => {
this.logger.info('Profile read. Go to HomePage.');
this.openLockModal();
if (profile) this.rootPage = TabsPage;
else {
this.profile.createProfile();
this.rootPage = OnboardingPage;
}
}).catch((err: any) => {
if (!err) this.profile.createProfile();
this.logger.warn(err);
this.rootPage = OnboardingPage;
this.rootPage = DisclaimerPage;
});
});
}

View File

@ -14,7 +14,7 @@ export class Profile {
this.version = '1.0.0';
}
public create(opts?: any): any {
public create(opts?: any): Profile {
opts = opts ? opts : {};
let x = new Profile();
x.createdOn = Date.now();
@ -24,7 +24,7 @@ export class Profile {
return x;
};
public fromObj(obj: any): any {
public fromObj(obj: any): Profile {
let x = new Profile();
x.createdOn = obj.createdOn;
@ -35,11 +35,10 @@ export class Profile {
if (x.credentials[0] && typeof x.credentials[0] != 'object')
throw ("credentials should be an object");
return x;
};
public fromString(str: string): any {
public fromString(str: string): Profile {
return this.fromObj(JSON.parse(str));
};
@ -48,7 +47,6 @@ export class Profile {
return JSON.stringify(this);
};
public hasWallet(walletId: string): boolean {
for (let i in this.credentials) {
let c = this.credentials[i];

View File

@ -5,6 +5,8 @@ import { Logger } from '@nsalaun/ng-logger';
import { TermsOfUsePage } from '../../settings/about/terms-of-use/terms-of-use';
import { TabsPage } from '../../tabs/tabs';
import { PersistenceProvider } from '../../../providers/persistence/persistence';
@Component({
selector: 'page-disclaimer',
templateUrl: 'disclaimer.html',
@ -15,7 +17,8 @@ export class DisclaimerPage {
constructor(
public navCtrl: NavController,
private log: Logger
private logger: Logger,
private persistenceProvider: PersistenceProvider
) {
this.accepted = {
first: false,
@ -27,7 +30,7 @@ export class DisclaimerPage {
}
ionViewDidLoad() {
this.log.info('ionViewDidLoad DisclaimerPage');
this.logger.info('ionViewDidLoad DisclaimerPage');
}
selectTerms() {
@ -40,6 +43,7 @@ export class DisclaimerPage {
confirm() {
// TODO accept disclaimer
this.persistenceProvider.setDisclaimerAccepted();
this.navCtrl.setRoot(TabsPage);
this.navCtrl.popToRoot();
}

View File

@ -55,8 +55,9 @@ export let persistenceProviderFactory = (platform: PlatformProvider, log: Logger
@Injectable()
export class PersistenceProvider {
constructor( @Inject(ISTORAGE) public storage: IStorage, private log: Logger) {
this.log.info('PersistenceProvider initialized.');
constructor( @Inject(ISTORAGE) public storage: IStorage, private logger: Logger) {
this.logger.info('PersistenceProvider initialized.');
};
storeNewProfile(profile): Promise<void> {
@ -159,6 +160,10 @@ export class PersistenceProvider {
return this.storage.get(Keys.HIDE_BALANCE(walletId));
};
setDisclaimerAccepted(): Promise<any> {
return this.storage.set(Keys.AGREE_DISCLAIMER, true);
}
//for compatibility
getCopayDisclaimerFlag(): Promise<any> {
return this.storage.get(Keys.AGREE_DISCLAIMER);
@ -283,14 +288,14 @@ export class PersistenceProvider {
block += '12345678901234567890123456789012345678901234567890';
}
this.storage.set('test', block).catch(err => {
this.log.error('CheckQuota Return:' + err);
this.logger.error('CheckQuota Return:' + err);
});
};
setTxHistory(walletId: string, txs: any): Promise<void> {
return this.storage.set(Keys.TX_HISTORY(walletId), txs).catch(err => {
this.log.error('Error saving tx History. Size:' + txs.length);
this.log.error(err);
this.logger.error('Error saving tx History. Size:' + txs.length);
this.logger.error(err);
});
}
@ -395,7 +400,7 @@ export class PersistenceProvider {
account.givenName = data.givenName;
allAccounts[data.email] = account;
this.log.info('Storing BitPay accounts with new account:' + data.email);
this.logger.info('Storing BitPay accounts with new account:' + data.email);
return this.storage.set(Keys.BITPAY_ACCOUNTS_V2(network), allAccounts);
});
};

View File

@ -15,7 +15,7 @@ import { Profile } from '../../models/profile/profile.model';
@Injectable()
export class ProfileProvider {
public wallet: any = {};
public profile: Profile = new Profile();
public profile: Profile;
private UPDATE_PERIOD = 15;
private throttledBwsEvent: any;
@ -502,25 +502,11 @@ export class ProfileProvider {
});
}
public createProfile(): Promise<any> {
return new Promise((resolve, reject) => {
this.logger.info('Creating profile');
let defaults = this.configProvider.getDefaults();
let config = this.configProvider.get();
let profile = this.profile.create();
this.persistenceProvider.storeNewProfile(profile).then((err: any) => {
this.bindProfile(profile).then(() => {
// ignore NONAGREEDDISCLAIMER
return resolve();
});
}).catch((err) => {
if (err && err.toString().match('NONAGREEDDISCLAIMER')) {
return reject();
}
return reject(err);
});
});
public createProfile(): void {
this.logger.info('Creating profile');
this.profile = new Profile();
this.profile = this.profile.create();
this.persistenceProvider.storeNewProfile(this.profile);
}
public bindProfile(profile: any): Promise<any> {
@ -613,13 +599,16 @@ export class ProfileProvider {
public loadAndBindProfile(): Promise<any> {
return new Promise((resolve, reject) => {
this.persistenceProvider.getProfile().then((profile: any) => {
if (!profile) {
return reject();
return resolve();
}
this.profile = new Profile();
this.profile = this.profile.fromObj(profile);
// Deprecated: storageService.tryToMigrate
this.logger.debug('Profile read');
this.bindProfile(profile).then(() => {
return resolve();
this.bindProfile(this.profile).then(() => {
return resolve(this.profile);
}).catch((err: any) => {
return reject(err);
});