WIP, rebasing.
This commit is contained in:
parent
14aa806267
commit
162d84e2d2
5 changed files with 35 additions and 36 deletions
|
|
@ -15,7 +15,7 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
|
|||
return;
|
||||
}
|
||||
if (paired) {
|
||||
bitpayCardService.sync(apiContext, function(err, cards) {
|
||||
bitpayCardService.sync(apiContext, function(err, data) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error updating Debit Cards'), err);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, appConfigService, $ionicModal, $log, lodash, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService, bitpayAccountService, bitpayCardService, storageService, glideraService, gettextCatalog) {
|
||||
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, appConfigService, $ionicModal, $log, lodash, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService, bitpayAccountService, bitpayCardService, storageService, glideraService, gettextCatalog, buyAndSellService) {
|
||||
|
||||
var updateConfig = function() {
|
||||
var isCordova = platformInfo.isCordova;
|
||||
|
|
@ -34,7 +34,7 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
|
|||
});
|
||||
|
||||
if ($scope.bitpayCardEnabled) {
|
||||
bitpayCardService.getBitpayDebitCards(function(err, cards) {
|
||||
bitpayCardService.getCards(function(err, cards) {
|
||||
if (err) $log.error(err);
|
||||
$scope.bitpayCards = cards && cards.length > 0;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -143,22 +143,18 @@ angular.module('copayApp.services').factory('bitpayAccountService', function($lo
|
|||
|
||||
var accountsArray = [];
|
||||
lodash.forEach(Object.keys(accounts), function(key) {
|
||||
accounts[key].bitpayDebitCards = accounts[key]['bitpayDebitCards-' + bitpayService.getEnvironment().network];
|
||||
accounts[key].bitpayDebitCards = accounts[key].cards;
|
||||
accounts[key].email = key;
|
||||
accounts[key].firstName = accounts[key]['basicInfo-' + bitpayService.getEnvironment().network].givenName;
|
||||
accounts[key].lastName = accounts[key]['basicInfo-' + bitpayService.getEnvironment().network].familyName;
|
||||
accounts[key].firstName = accounts[key].givenName || '';
|
||||
accounts[key].lastName = accounts[key].familyName || '';
|
||||
accounts[key].apiContext = {
|
||||
token: accounts[key]['bitpayApi-' + bitpayService.getEnvironment().network].token,
|
||||
token: accounts[key].token,
|
||||
pairData: {
|
||||
email: key
|
||||
},
|
||||
appIdentity: appIdentity
|
||||
};
|
||||
|
||||
// Remove environment keyed attributes.
|
||||
delete accounts[key]['bitpayApi-' + bitpayService.getEnvironment().network];
|
||||
delete accounts[key]['bitpayDebitCards-' + bitpayService.getEnvironment().network];
|
||||
|
||||
accountsArray.push(accounts[key]);
|
||||
});
|
||||
return cb(null, accountsArray);
|
||||
|
|
@ -167,8 +163,7 @@ angular.module('copayApp.services').factory('bitpayAccountService', function($lo
|
|||
};
|
||||
|
||||
var setBitpayAccount = function(account, cb) {
|
||||
var data = JSON.stringify(account);
|
||||
storageService.setBitpayAccount(bitpayService.getEnvironment().network, data, function(err) {
|
||||
storageService.setBitpayAccount(bitpayService.getEnvironment().network, account, function(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
|||
cards: data.data.data,
|
||||
email: apiContext.pairData.email
|
||||
}
|
||||
root.setBitpayDebitCards(cardData, function(err) {
|
||||
storageService.setBitpayDebitCards(bitpayService.getEnvironment().network, cardData, function(err) {
|
||||
return cb(err, {token: apiContext.token, cards: data.data.data, email: apiContext.pairData.email});
|
||||
});
|
||||
}, function(data) {
|
||||
|
|
|
|||
|
|
@ -356,6 +356,7 @@ angular.module('copayApp.services')
|
|||
storage.remove('balanceCache-' + cardId, cb);
|
||||
};
|
||||
|
||||
// data: {
|
||||
// cards: [
|
||||
// eid: card id
|
||||
// id: card id
|
||||
|
|
@ -371,16 +372,17 @@ angular.module('copayApp.services')
|
|||
}
|
||||
data = data || {};
|
||||
if (lodash.isEmpty(data) || !data.email) return cb('Cannot set cards: no account to set');
|
||||
storage.get('bitpayAccounts-v3-' + network, function(err, bitpayAccounts) {
|
||||
|
||||
root.getBitpayAccounts(network, function(err, allAccounts) {
|
||||
if (err) return cb(err);
|
||||
|
||||
if (!allAccounts[email]) {
|
||||
return cb('Cannot set cards for unknown account ' + email);
|
||||
allAccounts = allAccounts || {};
|
||||
if (!allAccounts[data.email]) {
|
||||
return cb('Cannot set cards for unknown account ' + data.email);
|
||||
}
|
||||
bitpayAccounts = bitpayAccounts || {};
|
||||
bitpayAccounts[data.email] = bitpayAccounts[data.email] || {};
|
||||
bitpayAccounts[data.email]['bitpayDebitCards-' + network] = data.cards;
|
||||
storage.set('bitpayAccounts-v3-' + network, JSON.stringify(bitpayAccounts), cb);
|
||||
allAccounts[data.email] = allAccounts[data.email] || {};
|
||||
allAccounts[data.email]['bitpayDebitCards-' + network] = data.cards;
|
||||
storage.set('bitpayAccounts-v2-' + network, JSON.stringify(allAccounts), cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -400,13 +402,15 @@ angular.module('copayApp.services')
|
|||
|
||||
lodash.each(allAccounts, function(account, email) {
|
||||
|
||||
// Add account's email to card list, for convenience
|
||||
var cards = lodash.clone(account.cards);
|
||||
lodash.each(cards, function(x) {
|
||||
x.email = email;
|
||||
});
|
||||
if (account.cards) {
|
||||
// Add account's email to card list, for convenience
|
||||
var cards = lodash.clone(account.cards);
|
||||
lodash.each(cards, function(x) {
|
||||
x.email = email;
|
||||
});
|
||||
|
||||
allCards = allCards.concat(cards);
|
||||
allCards = allCards.concat(cards);
|
||||
}
|
||||
});
|
||||
|
||||
return cb(null, allCards);
|
||||
|
|
@ -494,25 +498,25 @@ angular.module('copayApp.services')
|
|||
// data: {
|
||||
// email: account email
|
||||
// token: account token
|
||||
// familyName: account family (last) name
|
||||
// givenName: account given (first) name
|
||||
// }
|
||||
root.setBitpayAccount = function(network, data, cb) {
|
||||
|
||||
if (!lodash.isObject(data) || !data.email || !data.token)
|
||||
return cb('No account to set');
|
||||
|
||||
var email = data.email;
|
||||
var token = data.token;
|
||||
|
||||
|
||||
root.getBitpayAccounts(network, function(err, allAccounts) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var account = allAccounts[email] || {};
|
||||
account.token = token;
|
||||
allAccounts = allAccounts || {};
|
||||
var account = allAccounts[data.email] || {};
|
||||
account.token = data.token;
|
||||
account.familyName = data.familyName;
|
||||
account.givenName = data.givenName;
|
||||
|
||||
allAccounts[email] = account;
|
||||
allAccounts[data.email] = account;
|
||||
|
||||
$log.info('Storing BitPay accounts with new account:' + email);
|
||||
$log.info('Storing BitPay accounts with new account:' + data.email);
|
||||
storage.set('bitpayAccounts-v2-' + network, allAccounts, cb);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue