Skip to content

Commit

Permalink
Merge pull request #9705 from cmgustavo/ref/profile-file-storage-02
Browse files Browse the repository at this point in the history
WIP ref(file-storage): adds more console.log
  • Loading branch information
matiu authored May 10, 2019
2 parents 74e9698 + b3dc4db commit 2c33b95
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 28 deletions.
20 changes: 15 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,21 @@ export class CopayApp {
this.onProfileLoad(profile);
})
.catch((err: Error) => {
this.logger.warn('LoadAndBindProfile', err.message);
this.rootPage =
err.message == 'ONBOARDINGNONCOMPLETED: Onboarding non completed'
? OnboardingPage
: DisclaimerPage;
switch (err.message) {
case 'NONAGREEDDISCLAIMER':
this.logger.warn('Non agreed disclaimer');
this.rootPage = DisclaimerPage;
break;
case 'ONBOARDINGNONCOMPLETED':
this.logger.warn('Onboarding non completed');
this.rootPage = OnboardingPage;
break;
default:
this.popupProvider.ionicAlert(
'Could not initialize the app',
err.message
);
}
});
}

Expand Down
9 changes: 5 additions & 4 deletions src/models/profile/profile.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ export class Profile {
this.version = '1.0.0';
}

static create(opts?): Profile {
opts = opts ? opts : {};
static create(): Profile {
let x = new Profile();
x.createdOn = Date.now();
x.credentials = opts.credentials || [];
x.credentials = [];
x.disclaimerAccepted = false;
x.onboardingCompleted = false;
x.checked = {};
return x;
}

static fromObj(obj): Profile {
obj = obj ? obj : {};
if (!obj || typeof obj != 'object') {
throw new Error('Wrong params at Profile.fromObj: ' + obj);
}
let x = new Profile();
x.createdOn = obj.createdOn;
x.credentials = obj.credentials || [];
Expand Down
6 changes: 4 additions & 2 deletions src/providers/persistence/storage/file-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ export class FileStorage implements IStorage {
return new Promise((resolve, reject) => {
fileEntry.createWriter(fileWriter => {
fileWriter.onwriteend = () => {
this.log.debug('Successful file write...');
return resolve();
};

fileWriter.onerror = () => {
return reject();
fileWriter.onerror = e => {
this.log.error('Failed file write: ' + e.toString());
return reject(e.toString());
};

if (_.isObject(v)) v = JSON.stringify(v);
Expand Down
47 changes: 30 additions & 17 deletions src/providers/profile/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,14 @@ export class ProfileProvider {

public updateCredentials(credentials): void {
this.profile.updateWallet(credentials);
this.persistenceProvider.storeProfile(this.profile);
this.persistenceProvider.storeProfile(this.profile).then(
() => {
this.logger.debug('Updated modified Profile(updateCredentials)');
},
e => {
this.logger.error('Could not save Profile(updateCredentials)', e);
}
);
}

private runValidation(wallet, delay?: number, retryDelay?: number) {
Expand Down Expand Up @@ -421,10 +428,16 @@ export class ProfileProvider {

public storeProfileIfDirty(): void {
if (this.profile.dirty) {
this.persistenceProvider.storeProfile(this.profile).then(() => {
this.logger.debug('Saved modified Profile');
return;
});
this.persistenceProvider.storeProfile(this.profile).then(
() => {
this.logger.debug('Saved modified Profile');
return;
},
e => {
this.logger.error('Could not save Profile(Dirty)', e);
return;
}
);
} else {
return;
}
Expand Down Expand Up @@ -688,11 +701,17 @@ export class ProfileProvider {

this.saveBwsUrl(walletId, opts);

return this.persistenceProvider.storeProfile(this.profile).then(() => {
if (!opts.skipEvent) this.events.publish('Local/WalletListChange');
return this.persistenceProvider.storeProfile(this.profile).then(
() => {
if (!opts.skipEvent) this.events.publish('Local/WalletListChange');

return Promise.resolve(wallet);
});
return Promise.resolve(wallet);
},
e => {
this.logger.error('Could not save Profile(addAndBindWalletClient)', e);
return Promise.reject(e);
}
);
}

private saveBwsUrl(walletId, opts): void {
Expand Down Expand Up @@ -931,9 +950,7 @@ export class ProfileProvider {
return resolve();
})
.catch(() => {
return reject(
new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')
);
return reject(new Error('NONAGREEDDISCLAIMER'));
});
})
.catch(() => {
Expand All @@ -948,11 +965,7 @@ export class ProfileProvider {
});
})
.catch(() => {
return reject(
new Error(
'ONBOARDINGNONCOMPLETED: Onboarding non completed'
)
);
return reject(new Error('ONBOARDINGNONCOMPLETED'));
});
});
})
Expand Down

0 comments on commit 2c33b95

Please sign in to comment.