fix old format migration
This commit is contained in:
parent
34bc2ba209
commit
776154ffbf
2 changed files with 24 additions and 7 deletions
|
|
@ -209,7 +209,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
register();
|
register();
|
||||||
storageService.removeBitpayDebitCardHistory(cardId, cb);
|
storageService.removeBalanceCache(cardId, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -345,15 +345,15 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setBalanceCache = function(cardId, data, cb) {
|
root.setBalanceCache = function(cardId, data, cb) {
|
||||||
storage.set('bitpayDebitCardBalance-' + cardId, data, cb);
|
storage.set('balanceCache-' + cardId, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getBalanceCache = function(cardId, cb) {
|
root.getBalanceCache = function(cardId, cb) {
|
||||||
storage.get('bitpayDebitCardBalance-' + cardId, cb);
|
storage.get('balanceCache-' + cardId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.removeBitpayDebitCardHistory = function(cardId, cb) {
|
root.removeBalanceCache = function(cardId, cb) {
|
||||||
storage.remove('bitpayDebitCardHistory-' + cardId, cb);
|
storage.remove('balanceCache-' + cardId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
// cards: [
|
// cards: [
|
||||||
|
|
@ -452,17 +452,34 @@ angular.module('copayApp.services')
|
||||||
allAccounts = JSON.parse(allAccountsStr);
|
allAccounts = JSON.parse(allAccountsStr);
|
||||||
} catch (e) {};
|
} catch (e) {};
|
||||||
|
|
||||||
|
var anyMigration;
|
||||||
|
|
||||||
lodash.each(allAccounts, function(account, email) {
|
lodash.each(allAccounts, function(account, email) {
|
||||||
|
|
||||||
// Migrate old `'bitpayApi-' + network` key, if exists
|
// Migrate old `'bitpayApi-' + network` key, if exists
|
||||||
if (!account.token && account['bitpayApi-' + network].token) {
|
if (!account.token && account['bitpayApi-' + network].token) {
|
||||||
|
|
||||||
$log.info('Migrating all bitpayApi-network branch');
|
$log.info('Migrating all bitpayApi-network branch');
|
||||||
account = account['bitpayApi-' + network];
|
account.token = account['bitpayApi-' + network].token;
|
||||||
|
account.cards = lodash.clone(account['bitpayApi-' + network].cards);
|
||||||
|
if (!account.cards) {
|
||||||
|
account.cards = lodash.clone(account['bitpayDebitCards-' + network]);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete account['bitpayDebitCards-' + network];
|
||||||
delete account['bitpayApi-' + network];
|
delete account['bitpayApi-' + network];
|
||||||
|
anyMigration = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return cb(err, allAccounts);
|
if (anyMigration) {
|
||||||
|
storage.set('bitpayAccounts-v2-' + network, allAccounts, function(){
|
||||||
|
return cb(err, allAccounts);
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
return cb(err, allAccounts);
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue