Fix upgrade accounts so they don't overwrite each other.

This commit is contained in:
Andy Phillipson 2017-01-24 10:33:08 -05:00
parent 56bff1db41
commit 484e09e4ff
1 changed files with 8 additions and 8 deletions

View File

@ -163,6 +163,7 @@ angular.module('copayApp.services')
// Needs upgrade
upgraded += ' ' + key;
var acctData = {
acct: data[key],
token: data[key]['bitpayDebitCards-' + network].token,
email: key
};
@ -274,18 +275,17 @@ angular.module('copayApp.services')
data = JSON.parse(data);
}
data = data || {};
if (lodash.isEmpty(data) || !data.email) return cb('No account to set');
storage.get('bitpayAccounts-' + network, function(err, bitpayAccounts) {
if (lodash.isEmpty(data) || !data.email || !data.acct) return cb('No account to set');
storage.get('bitpayAccounts-v2-' + network, function(err, bitpayAccounts) {
if (err) return cb(err);
if (lodash.isString(bitpayAccounts)) {
bitpayAccounts = JSON.parse(bitpayAccounts);
}
// Ensure only the specified account is set (data.email)
var upgradedBitpayAccount = {};
upgradedBitpayAccount[data.email] = bitpayAccounts[data.email] || {};
upgradedBitpayAccount[data.email]['bitpayApi-' + network] = {};
upgradedBitpayAccount[data.email]['bitpayApi-' + network].token = data.token;
storage.set('bitpayAccounts-v2-' + network, JSON.stringify(upgradedBitpayAccount), cb);
bitpayAccounts = bitpayAccounts || {};
bitpayAccounts[data.email] = data.acct;
bitpayAccounts[data.email]['bitpayApi-' + network] = {};
bitpayAccounts[data.email]['bitpayApi-' + network].token = data.token;
storage.set('bitpayAccounts-v2-' + network, JSON.stringify(bitpayAccounts), cb);
});
};