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'; this.version = '1.0.0';
}; };
Profile.create = function(opts) { Profile.create = function(appVersion) {
opts = opts || {};
var x = new Profile(); var x = new Profile();
x.appVersion = appVersion;
x.createdOn = Date.now(); x.createdOn = Date.now();
x.credentials = opts.credentials || []; x.credentials = [];
x.disclaimerAccepted = true; x.disclaimerAccepted = true;
x.checked = {}; x.checked = {};
return x; return x;
@ -23,6 +23,7 @@ Profile.create = function(opts) {
Profile.fromObj = function(obj) { Profile.fromObj = function(obj) {
var x = new Profile(); var x = new Profile();
x.appVersion = obj.appVersion;
x.createdOn = obj.createdOn; x.createdOn = obj.createdOn;
x.credentials = obj.credentials; x.credentials = obj.credentials;
x.disclaimerAccepted = obj.disclaimerAccepted; x.disclaimerAccepted = obj.disclaimerAccepted;
@ -69,10 +70,12 @@ Profile.prototype.isDeviceChecked = function(ua) {
Profile.prototype.merge = function(other) { Profile.prototype.merge = function(other) {
var newCredentials = []; var newCredentials = [];
var otherCredentialsLength = other.credentials.length;
var thisProfile = this;
other.credentials.forEach(function(otherCredential) { other.credentials.forEach(function(otherCredential) {
var credentialExists = false; var credentialExists = false;
this.credentials.forEach(function(thisCredential) { thisProfile.credentials.forEach(function(thisCredential) {
if (otherCredential.walletId === thisCredential.walletId) { if (otherCredential.walletId === thisCredential.walletId) {
credentialExists = true; credentialExists = true;
} }
@ -85,6 +88,15 @@ Profile.prototype.merge = function(other) {
Array.prototype.push.apply(this.credentials, newCredentials); 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) { Profile.prototype.setChecked = function(ua, walletId) {
if (this.checkedUA != ua) { if (this.checkedUA != ua) {
this.checkedUA = ua; this.checkedUA = ua;

View file

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

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.services') 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 root = {};
var storage; var storage;
@ -136,11 +136,14 @@ angular.module('copayApp.services')
* @param {getProfileCallback} cb * @param {getProfileCallback} cb
*/ */
function _migrateProfiles(oldProfile, secureProfile, cb) { function _migrateProfiles(oldProfile, secureProfile, cb) {
var newProfile = oldProfile; var newProfile;
if (secureProfile) { if (secureProfile) {
secureProfile.merge(oldProfile); secureProfile.merge(oldProfile);
newProfile = secureProfile; newProfile = secureProfile;
} else {
newProfile = oldProfile;
newProfile.setAppVersion(appConfigService.version);
} }
root.storeNewProfile(newProfile, function(storeErr) { root.storeNewProfile(newProfile, function(storeErr) {