Desktop using local storage only.

This commit is contained in:
Brendon Duncan 2018-06-11 12:23:39 +12:00
commit 435c2cacd4
2 changed files with 422 additions and 17 deletions

View file

@ -129,6 +129,37 @@ angular.module('copayApp.services')
* @param {Profile} profile - falsy if error or profile not found.
*/
/**
* @param {Error} error
* @param {String} profileStr - containing the profile
* @param {getProfileCallback} cb
*/
function _onOldProfileRetrieved(error, profileStr, cb) {
if (error) {
return cb(error, null);
}
if (!profileStr) {
// No profiles found. No errors either.
return cb(null, null);
}
decryptOnMobile(profileStr, function(decryptErr, decryptedStr) {
if (decryptErr) return cb(decryptErr, null);
var profile;
try {
profile = Profile.fromString(decryptedStr);
} catch (e) {
$log.debug('Could not read profile:', e);
return(new Error('Could not read profile.'), null);
}
cb(null, profile)
});
}
/**
*
* @param {Profile} oldProfile
@ -169,6 +200,13 @@ angular.module('copayApp.services')
* @param {getProfileCallback} cb
*/
root.getProfile = function(cb) {
if (platformInfo.isNW) {
storage.get('profile', function(getErr, getStr) {
_onOldProfileRetrieved(getErr, getStr, cb);
});
return
}
secureStorageService.get('profile', function(secureErr, secureStr) {
var secureProfile;
var oldProfile;
@ -188,11 +226,12 @@ angular.module('copayApp.services')
}
storage.get('profile', function(getErr, getStr) {
if (getErr) {
return cb(getErr);
_onOldProfileRetrieved(getErr, getStr, function(oldErr, oldProfile){
if (oldErr) {
return cb(oldErr, null);
}
if (!getStr) {
if (!oldProfile) {
if (secureProfile) {
return cb(null, secureProfile);
} else {
@ -200,20 +239,7 @@ angular.module('copayApp.services')
return cb(null, null);
}
}
decryptOnMobile(getStr, function(err, str) {
if (err) return cb(err);
var p, err;
try {
oldProfile = Profile.fromString(str);
} catch (e) {
$log.debug('Could not read profile:', e);
err = new Error('Could not read profile.');
return(err, null);
}
_migrateProfiles(oldProfile, secureProfile, cb);
});
});
});