Merge pull request #5054 from ajp8164/bug/fix-parse-empty-bitpay-account-storage
Correct issue with parsing null returned from storage.
This commit is contained in:
commit
af018f0a18
1 changed files with 12 additions and 3 deletions
|
|
@ -444,7 +444,10 @@ angular.module('copayApp.services')
|
||||||
if (lodash.isEmpty(data) || !data.email) return cb('No card(s) to set');
|
if (lodash.isEmpty(data) || !data.email) return cb('No card(s) to set');
|
||||||
storage.get('bitpayAccounts-' + network, function(err, bitpayAccounts) {
|
storage.get('bitpayAccounts-' + network, function(err, bitpayAccounts) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
bitpayAccounts = JSON.parse(bitpayAccounts) || {};
|
if (lodash.isString(bitpayAccounts)) {
|
||||||
|
bitpayAccounts = JSON.parse(bitpayAccounts);
|
||||||
|
}
|
||||||
|
bitpayAccounts = bitpayAccounts || {};
|
||||||
bitpayAccounts[data.email] = bitpayAccounts[data.email] || {};
|
bitpayAccounts[data.email] = bitpayAccounts[data.email] || {};
|
||||||
bitpayAccounts[data.email]['bitpayDebitCards-' + network] = data;
|
bitpayAccounts[data.email]['bitpayDebitCards-' + network] = data;
|
||||||
storage.set('bitpayAccounts-' + network, JSON.stringify(bitpayAccounts), cb);
|
storage.set('bitpayAccounts-' + network, JSON.stringify(bitpayAccounts), cb);
|
||||||
|
|
@ -453,7 +456,10 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.getBitpayDebitCards = function(network, cb) {
|
root.getBitpayDebitCards = function(network, cb) {
|
||||||
storage.get('bitpayAccounts-' + network, function(err, bitpayAccounts) {
|
storage.get('bitpayAccounts-' + network, function(err, bitpayAccounts) {
|
||||||
bitpayAccounts = JSON.parse(bitpayAccounts) || {};
|
if (lodash.isString(bitpayAccounts)) {
|
||||||
|
bitpayAccounts = JSON.parse(bitpayAccounts);
|
||||||
|
}
|
||||||
|
bitpayAccounts = bitpayAccounts || {};
|
||||||
var cards = [];
|
var cards = [];
|
||||||
Object.keys(bitpayAccounts).forEach(function(email) {
|
Object.keys(bitpayAccounts).forEach(function(email) {
|
||||||
// For the UI, add the account email to the card object.
|
// For the UI, add the account email to the card object.
|
||||||
|
|
@ -475,7 +481,10 @@ angular.module('copayApp.services')
|
||||||
if (lodash.isEmpty(card) || !card.eid) return cb('No card to remove');
|
if (lodash.isEmpty(card) || !card.eid) return cb('No card to remove');
|
||||||
storage.get('bitpayAccounts-' + network, function(err, bitpayAccounts) {
|
storage.get('bitpayAccounts-' + network, function(err, bitpayAccounts) {
|
||||||
if (err) cb(err);
|
if (err) cb(err);
|
||||||
bitpayAccounts = JSON.parse(bitpayAccounts) || {};
|
if (lodash.isString(bitpayAccounts)) {
|
||||||
|
bitpayAccounts = JSON.parse(bitpayAccounts);
|
||||||
|
}
|
||||||
|
bitpayAccounts = bitpayAccounts || {};
|
||||||
Object.keys(bitpayAccounts).forEach(function(userId) {
|
Object.keys(bitpayAccounts).forEach(function(userId) {
|
||||||
var data = bitpayAccounts[userId]['bitpayDebitCards-' + network];
|
var data = bitpayAccounts[userId]['bitpayDebitCards-' + network];
|
||||||
var newCards = lodash.reject(data.cards, {'eid': card.eid});
|
var newCards = lodash.reject(data.cards, {'eid': card.eid});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue