Now including app version is profile.

This commit is contained in:
Brendon Duncan 2018-06-05 11:34:14 +12:00
commit 16b5054ea2
3 changed files with 22 additions and 7 deletions

View file

@ -9,12 +9,12 @@ function Profile() {
this.version = '1.0.0';
};
Profile.create = function(opts) {
opts = opts || {};
Profile.create = function(appVersion) {
var x = new Profile();
x.appVersion = appVersion;
x.createdOn = Date.now();
x.credentials = opts.credentials || [];
x.credentials = [];
x.disclaimerAccepted = true;
x.checked = {};
return x;
@ -23,6 +23,7 @@ Profile.create = function(opts) {
Profile.fromObj = function(obj) {
var x = new Profile();
x.appVersion = obj.appVersion;
x.createdOn = obj.createdOn;
x.credentials = obj.credentials;
x.disclaimerAccepted = obj.disclaimerAccepted;
@ -69,10 +70,12 @@ Profile.prototype.isDeviceChecked = function(ua) {
Profile.prototype.merge = function(other) {
var newCredentials = [];
var otherCredentialsLength = other.credentials.length;
var thisProfile = this;
other.credentials.forEach(function(otherCredential) {
var credentialExists = false;
this.credentials.forEach(function(thisCredential) {
thisProfile.credentials.forEach(function(thisCredential) {
if (otherCredential.walletId === thisCredential.walletId) {
credentialExists = true;
}
@ -85,6 +88,15 @@ Profile.prototype.merge = function(other) {
Array.prototype.push.apply(this.credentials, newCredentials);
};
/**
* It's a simple operation, but it means that all the profile logic stays
* in this file.
* @param {string} appVersion - ie "4.11.0"
*/
Profile.prototype.setAppVersion = function(appVersion) {
this.appVersion = appVersion;
}
Profile.prototype.setChecked = function(ua, walletId) {
if (this.checkedUA != ua) {
this.checkedUA = ua;

View file

@ -706,7 +706,7 @@ angular.module('copayApp.services')
configService.get(function(err) {
if (err) $log.debug(err);
var p = Profile.create();
var p = Profile.create(appConfigService.version);
storageService.storeNewProfile(p, function(err) {
if (err) return cb(err);
root.bindProfile(p, function(err) {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services')
.factory('storageService', function(logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, secureStorageService, $timeout) {
.factory('storageService', function(appConfigService, logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, secureStorageService, $timeout) {
var root = {};
var storage;
@ -136,11 +136,14 @@ angular.module('copayApp.services')
* @param {getProfileCallback} cb
*/
function _migrateProfiles(oldProfile, secureProfile, cb) {
var newProfile = oldProfile;
var newProfile;
if (secureProfile) {
secureProfile.merge(oldProfile);
newProfile = secureProfile;
} else {
newProfile = oldProfile;
newProfile.setAppVersion(appConfigService.version);
}
root.storeNewProfile(newProfile, function(storeErr) {