diff --git a/src/js/controllers/bitpayCard.js b/src/js/controllers/bitpayCard.js index 0c8a85bd3..f50218d9f 100644 --- a/src/js/controllers/bitpayCard.js +++ b/src/js/controllers/bitpayCard.js @@ -7,7 +7,7 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi $scope.dateRange = { value: 'last30Days' }; - $scope.network = bitpayService.getEnvironment(); + $scope.network = bitpayService.getEnvironment().network; var updateHistoryFromCache = function(cb) { bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) { diff --git a/src/js/services/appIdentityService.js b/src/js/services/appIdentityService.js index 6df3f136d..3f6debbbe 100644 --- a/src/js/services/appIdentityService.js +++ b/src/js/services/appIdentityService.js @@ -7,9 +7,6 @@ angular.module('copayApp.services').factory('appIdentityService', function($log, var pubkey, sin, isNew; storageService.getAppIdentity(network, function(err, data) { if (err) return cb(err); - if (lodash.isString(data)) { - data = JSON.parse(data); - } var appIdentity = data || {}; if (lodash.isEmpty(appIdentity) || (appIdentity && !appIdentity.priv)) { isNew = true; diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js index ce8e787c7..d26b35c9b 100644 --- a/src/js/services/bitpayCardService.js +++ b/src/js/services/bitpayCardService.js @@ -60,7 +60,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, method: 'getInvoiceHistory', params: JSON.stringify(params) }; - appIdentityService.getIdentity(bitpayService.getEnvironment(), function(err, appIdentity) { + appIdentityService.getIdentity(bitpayService.getEnvironment().network, function(err, appIdentity) { if (err) return cb(err); root.getBitpayDebitCards(function(err, data) { if (err) return cb(err); @@ -97,7 +97,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, method: 'generateTopUpInvoice', params: JSON.stringify(params) }; - appIdentityService.getIdentity(bitpayService.getEnvironment(), function(err, appIdentity) { + appIdentityService.getIdentity(bitpayService.getEnvironment().network, function(err, appIdentity) { if (err) return cb(err); root.getBitpayDebitCards(function(err, data) { if (err) return cb(err); @@ -127,7 +127,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, }; root.getBitpayDebitCards = function(cb) { - storageService.getBitpayDebitCards(bitpayService.getEnvironment(), function(err, data) { + storageService.getBitpayDebitCards(bitpayService.getEnvironment().network, function(err, data) { if (err) return cb(err); if (lodash.isString(data)) { data = JSON.parse(data); @@ -139,14 +139,14 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, root.setBitpayDebitCards = function(data, cb) { data = JSON.stringify(data); - storageService.setBitpayDebitCards(bitpayService.getEnvironment(), data, function(err) { + storageService.setBitpayDebitCards(bitpayService.getEnvironment().network, data, function(err) { if (err) return cb(err); return cb(); }); }; root.getBitpayDebitCardsHistory = function(cardId, cb) { - storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment(), function(err, data) { + storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment().network, function(err, data) { if (err) return cb(err); if (lodash.isString(data)) { data = JSON.parse(data); @@ -158,7 +158,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, }; root.setBitpayDebitCardsHistory = function(cardId, data, opts, cb) { - storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment(), function(err, oldData) { + storageService.getBitpayDebitCardsHistory(bitpayService.getEnvironment().network, function(err, oldData) { if (lodash.isString(oldData)) { oldData = JSON.parse(oldData); } @@ -172,19 +172,19 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log, } inv = JSON.stringify(inv); - storageService.setBitpayDebitCardsHistory(bitpayService.getEnvironment(), inv, function(err) { + storageService.setBitpayDebitCardsHistory(bitpayService.getEnvironment().network, inv, function(err) { return cb(err); }); }); }; root.remove = function(card, cb) { - storageService.removeBitpayDebitCard(bitpayService.getEnvironment(), card, function(err) { + storageService.removeBitpayDebitCard(bitpayService.getEnvironment().network, card, function(err) { if (err) { $log.error('Error removing BitPay debit card: ' + err); // Continue, try to remove/cleanup card history } - storageService.removeBitpayDebitCardHistory(bitpayService.getEnvironment(), card, function(err) { + storageService.removeBitpayDebitCardHistory(bitpayService.getEnvironment().network, card, function(err) { if (err) { $log.error('Error removing BitPay debit card transaction history: ' + err); return cb(err); diff --git a/src/js/services/bitpayService.js b/src/js/services/bitpayService.js index 12c3177e6..c0c3a5233 100644 --- a/src/js/services/bitpayService.js +++ b/src/js/services/bitpayService.js @@ -7,7 +7,9 @@ angular.module('copayApp.services').factory('bitpayService', function($log, $htt var BITPAY_API_URL = NETWORK == 'livenet' ? 'https://bitpay.com' : 'https://test.bitpay.com'; root.getEnvironment = function() { - return NETWORK; + return { + network: NETWORK + }; }; /* @@ -58,7 +60,7 @@ angular.module('copayApp.services').factory('bitpayService', function($log, $htt code: pairData.otp } }; - appIdentityService.getIdentity(root.getEnvironment(), function(err, appIdentity) { + appIdentityService.getIdentity(root.getEnvironment().network, function(err, appIdentity) { if (err) return cb(err); $http(_postAuth('/api/v2/', json, appIdentity)).then(function(data) { if (data && data.data.error) return cb(data.data.error); @@ -132,7 +134,7 @@ angular.module('copayApp.services').factory('bitpayService', function($log, $htt var setBitpayAccount = function(accountData, cb) { var data = JSON.stringify(accountData); - storageService.setBitpayAccount(root.getEnvironment(), data, function(err) { + storageService.setBitpayAccount(root.getEnvironment().network, data, function(err) { if (err) return cb(err); return cb(); }); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index bb23f641d..70d766bf7 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -728,7 +728,13 @@ angular.module('copayApp.services') }; root.getAppIdentity = function(network, cb) { - storage.get('appIdentity-' + network, cb); + storage.get('appIdentity-' + network, function(err, data) { + if (err) return cb(err); + if (lodash.isString(data)) { + data = JSON.parse(data); + } + cb(err, data); + }); }; root.removeAppIdentity = function(network, cb) {