From 17685dd810d46895e04fa7489eb9fcca66f1e1a2 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Fri, 1 Jun 2018 10:42:38 +1200 Subject: [PATCH] Fixed some issues after the refactor. --- src/js/services/mobileSecureStorageService.js | 104 +++++++++--------- src/js/services/secureStorageService.js | 3 + 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/js/services/mobileSecureStorageService.js b/src/js/services/mobileSecureStorageService.js index 93a2ec591..56c3e2df6 100644 --- a/src/js/services/mobileSecureStorageService.js +++ b/src/js/services/mobileSecureStorageService.js @@ -9,52 +9,6 @@ angular.module('copayApp.services').factory('mobileSecureStorageService', functi var storage = null; - this.get = function(key, cb) { - if (!isReady) { - if (initialisationFailed) { - cb(new Error("mobileSecureStorageService initialisation failed.")); - } else { - pending.push(function(){ root.get(key, cb); }); - } - return - } - - storage.get( - function (value) { - cb(null, value); - }, - function (error) { - if (error.message === 'Failure in SecureStorage.get() - The specified item could not be found in the keychain' || // iOS - error.message === 'Key [_SS_profile] not found.') { // Android - // The callback expects no error, but also no value, if it cannot be found. - cb(null, null); - } else { - cb(new Error(error)); - } - }, - key); - } - - this.set = function(key, value, cb) { - if (!isReady) { - if (initialisationFailed) { - cb(new Error("mobileSecureStorageService initialisation failed.")); - } else { - pending.push(function(){ root.set(key, value, cb); }); - } - return - } - - storage.set( - function (value) { - cb(); - }, - function (error) { - cb(new Error(error)); - }, - key, value); - } - if (platformInfo.isCordova) { storage = new cordova.plugins.SecureStorage( function () { @@ -73,19 +27,65 @@ angular.module('copayApp.services').factory('mobileSecureStorageService', functi } root.get = function(key, cb) { - if (platformInfo.isMobile) { - storage.get(key, cb); - } else { + + if (!platformInfo.isMobile) { cb(new Error('mobileSecureStorageService is only available on mobile.')); + return; } + + if (!isReady) { + if (initialisationFailed) { + cb(new Error('mobileSecureStorageService initialisation failed.')); + } else { + $log.debug('mss.get() queued.'); + pending.push(function(){ root.get(key, cb); }); + } + return; + } + + $log.debug('mss.get() running.'); + storage.get( + function (value) { + $log.debug('mss.get() succeeded.'); + cb(null, value); + }, + function (error) { + $log.debug('mss get failed. ' + error); + if (error.message === 'Failure in SecureStorage.get() - The specified item could not be found in the keychain' || // iOS + error.message === 'Key [_SS_profile] not found.') { // Android + // The callback expects no error, but also no value, if it cannot be found. + cb(null, null); + } else { + cb(new Error(error)); + } + }, + key); }; root.set = function(key, value, cb) { - if (platformInfo.isMobile) { - storage.set(key, v, cb); - } else { + + if (!platformInfo.isMobile) { cb(new Error('mobileSecureStorageService is only available on mobile.')); + } + + if (!isReady) { + if (initialisationFailed) { + cb(new Error('mobileSecureStorageService initialisation failed.')); + } else { + pending.push(function(){ root.set(key, value, cb); }); + } + return; } + + storage.set( + function (value) { + cb(); + }, + function (error) { + cb(new Error(error)); + }, + key, value); + }; return root; diff --git a/src/js/services/secureStorageService.js b/src/js/services/secureStorageService.js index c066109c2..e7179bf62 100644 --- a/src/js/services/secureStorageService.js +++ b/src/js/services/secureStorageService.js @@ -9,9 +9,12 @@ angular.module('copayApp.services').factory('secureStorageService', function(des } root.get = function(k, cb) { + $log.debug('ss.get()'); if (platformInfo.isMobile) { + $log.debug('ss.get() using mobile.'); mobileSecureStorageService.get(k, cb); } else if (platformInfo.isNW) { + $log.debug('ss.get() using desktop.'); desktopSecureStorageService.get(k, cb); } else { // Browser localStorageService.get(alteredKeyIndicatingDesireForSecureStorage(k), cb);