mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #6936 from Gamboster/feat/profileProviderV4
Feat: Profile provider v4
This commit is contained in:
commit
33f1a8780b
|
@ -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",
|
||||||
|
@ -179,4 +179,4 @@
|
||||||
"ios"
|
"ios"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,23 +48,21 @@ export class CopayApp {
|
||||||
this.splashScreen.hide();
|
this.splashScreen.hide();
|
||||||
}
|
}
|
||||||
// Check Profile
|
// Check Profile
|
||||||
this.profile.get().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;
|
}).catch((err: any) => {
|
||||||
} else {
|
if (!err) this.profile.createProfile();
|
||||||
// TODO: go to onboarding page
|
this.logger.warn(err);
|
||||||
this.logger.warn('Profile does not exist. Go to Onboarding.');
|
this.rootPage = OnboardingPage;
|
||||||
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();
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
import * as moment from 'moment';
|
||||||
|
|
||||||
|
export class Profile {
|
||||||
|
|
||||||
|
public version: string;
|
||||||
|
public createdOn: Number;
|
||||||
|
public credentials: Array<any>;
|
||||||
|
public disclaimerAccepted: boolean;
|
||||||
|
public checked: Object;
|
||||||
|
public checkedUA?: any;
|
||||||
|
public dirty: boolean;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.version = '1.0.0';
|
||||||
|
}
|
||||||
|
|
||||||
|
public create(opts?: any): any {
|
||||||
|
opts = opts ? opts : {};
|
||||||
|
let x = new Profile();
|
||||||
|
x.createdOn = Date.now();
|
||||||
|
x.credentials = opts.credentials || [];
|
||||||
|
x.disclaimerAccepted = false;
|
||||||
|
x.checked = {};
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
|
||||||
|
public fromObj(obj: any): any {
|
||||||
|
let x = new Profile();
|
||||||
|
|
||||||
|
x.createdOn = obj.createdOn;
|
||||||
|
x.credentials = obj.credentials;
|
||||||
|
x.disclaimerAccepted = obj.disclaimerAccepted;
|
||||||
|
x.checked = obj.checked || {};
|
||||||
|
x.checkedUA = obj.checkedUA || {};
|
||||||
|
|
||||||
|
if (x.credentials[0] && typeof x.credentials[0] != 'object')
|
||||||
|
throw ("credentials should be an object");
|
||||||
|
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
|
||||||
|
public fromString(str: string): any {
|
||||||
|
return this.fromObj(JSON.parse(str));
|
||||||
|
};
|
||||||
|
|
||||||
|
public toObj(): string {
|
||||||
|
delete this.dirty;
|
||||||
|
return JSON.stringify(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public hasWallet(walletId: string): boolean {
|
||||||
|
for (let i in this.credentials) {
|
||||||
|
let c = this.credentials[i];
|
||||||
|
if (c.walletId == walletId) return true;
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
public isChecked(ua: any, walletId: string): boolean {
|
||||||
|
return !!(this.checkedUA == ua && this.checked[walletId]);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public isDeviceChecked(ua: any): boolean {
|
||||||
|
return this.checkedUA == ua;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public setChecked(ua: any, walletId: string): void {
|
||||||
|
if (this.checkedUA != ua) {
|
||||||
|
this.checkedUA = ua;
|
||||||
|
this.checked = {};
|
||||||
|
}
|
||||||
|
this.checked[walletId] = true;
|
||||||
|
this.dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
public addWallet(credentials: any): boolean {
|
||||||
|
if (!credentials.walletId)
|
||||||
|
throw 'credentials must have .walletId';
|
||||||
|
|
||||||
|
if (this.hasWallet(credentials.walletId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.credentials.push(credentials);
|
||||||
|
this.dirty = true;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
public updateWallet(credentials: any): boolean {
|
||||||
|
if (!credentials.walletId)
|
||||||
|
throw 'credentials must have .walletId';
|
||||||
|
|
||||||
|
if (!this.hasWallet(credentials.walletId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.credentials = this.credentials.map((c: any) => {
|
||||||
|
if (c.walletId != credentials.walletId) {
|
||||||
|
return c;
|
||||||
|
} else {
|
||||||
|
return credentials
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.dirty = true;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
public deleteWallet(walletId: string): boolean {
|
||||||
|
if (!this.hasWallet(walletId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.credentials = this.credentials.filter(function (c) {
|
||||||
|
return c.walletId != walletId;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.dirty = true;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
|
@ -17,19 +17,20 @@ export class HomePage {
|
||||||
private release: ReleaseProvider,
|
private release: ReleaseProvider,
|
||||||
) {
|
) {
|
||||||
this.release.getLatestAppVersion()
|
this.release.getLatestAppVersion()
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('Error:', err)})
|
console.log('Error:', err)
|
||||||
.then((version) => {
|
})
|
||||||
console.log('Current app version:',version);
|
.then((version) => {
|
||||||
var result = this.release.checkForUpdates(version);
|
console.log('Current app version:', version);
|
||||||
console.log('Update available:', result.updateAvailable);
|
var result = this.release.checkForUpdates(version);
|
||||||
});
|
console.log('Update available:', result.updateAvailable);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ionViewDidLoad() {
|
ionViewDidLoad() {
|
||||||
console.log('ionViewDidLoad HomePage');
|
console.log('ionViewDidLoad HomePage');
|
||||||
|
|
||||||
this.wallets = this.profile.bind();
|
this.wallets = this.profile.getWallets();
|
||||||
console.log('[home.ts:20]', this.wallets); //TODO
|
console.log('[home.ts:20]', this.wallets); //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getStarted() {
|
getStarted() {
|
||||||
|
|
|
@ -117,7 +117,7 @@ export class ConfigProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
set(newOpts: object) {
|
public set(newOpts: object) {
|
||||||
let config = _.cloneDeep(this.configDefault);
|
let config = _.cloneDeep(this.configDefault);
|
||||||
|
|
||||||
if (_.isString(newOpts)) {
|
if (_.isString(newOpts)) {
|
||||||
|
@ -125,15 +125,19 @@ export class ConfigProvider {
|
||||||
}
|
}
|
||||||
_.merge(config, this.configCache, newOpts);
|
_.merge(config, this.configCache, newOpts);
|
||||||
this.configCache = config;
|
this.configCache = config;
|
||||||
|
this.events.publish('config:updated', this.configCache);
|
||||||
|
|
||||||
this.persistence.storeConfig(this.configCache).then(() => {
|
this.persistence.storeConfig(this.configCache).then(() => {
|
||||||
this.logger.info('Config saved');
|
this.logger.info('Config saved');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.events.publish('config:updated', this.configCache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get() {
|
public get(): Object {
|
||||||
return this.configCache;
|
return this.configCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getDefaults(): Object {
|
||||||
|
return this.configDefault;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue