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