mirror of https://github.com/BTCPrivate/copay.git
Updated for 1.3.6.
This commit is contained in:
parent
7a2d386f34
commit
ff56fc2bee
|
@ -15,7 +15,7 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
|
|||
return;
|
||||
}
|
||||
if (paired) {
|
||||
bitpayCardService.sync(apiContext, function(err, data) {
|
||||
bitpayCardService.sync(apiContext, function(err, cards) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error updating Debit Cards'), err);
|
||||
return;
|
||||
|
@ -26,9 +26,9 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
|
|||
disableAnimate: true
|
||||
});
|
||||
$state.go('tabs.home').then(function() {
|
||||
if (data.cards[0]) {
|
||||
if (cards[0]) {
|
||||
$state.transitionTo('tabs.bitpayCard', {
|
||||
id: data.cards[0].id
|
||||
id: cards[0].id
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -78,7 +78,7 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
|
|||
if (account == undefined) {
|
||||
startPairBitPayAccount();
|
||||
} else {
|
||||
bitpayCardService.fetchBitpayDebitCards(account.apiContext, function(err, data) {
|
||||
bitpayCardService.sync(account.apiContext, function(err, data) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
|
|
|
@ -45,7 +45,7 @@ angular.module('copayApp.controllers').controller('preferencesBitpayServicesCont
|
|||
};
|
||||
|
||||
var removeCard = function(card) {
|
||||
bitpayCardService.removeCard(card, function(err) {
|
||||
bitpayCardService.remove(card.id, function(err) {
|
||||
if (err) {
|
||||
return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not remove card'));
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ angular.module('copayApp.controllers').controller('preferencesBitpayServicesCont
|
|||
};
|
||||
|
||||
var setScope = function(cb) {
|
||||
bitpayAccountService.getAccounts(function(err, data) {
|
||||
bitpayAccountService.getAccounts(function(err, accounts) {
|
||||
if (err) return;
|
||||
$scope.bitpayAccounts = data;
|
||||
$scope.bitpayAccounts = accounts;
|
||||
|
||||
bitpayCardService.getBitpayDebitCards(function(err, data) {
|
||||
bitpayCardService.getCards(function(err, cards) {
|
||||
if (err) return;
|
||||
$scope.bitpayCards = data;
|
||||
$scope.bitpayCards = cards;
|
||||
if (cb) {
|
||||
cb();
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ angular.module('copayApp.services').factory('bitpayAccountService', function($lo
|
|||
// from the server for each account (apiContext).
|
||||
root.getAccounts = function(cb) {
|
||||
root.getAccountsAsStored(function(err, accounts) {
|
||||
if (err || !accounts) {
|
||||
if (err || lodash.isEmpty(accounts)) {
|
||||
return cb(err, []);
|
||||
}
|
||||
appIdentityService.getIdentity(bitpayService.getEnvironment().network, function(err, appIdentity) {
|
||||
|
@ -143,10 +143,10 @@ angular.module('copayApp.services').factory('bitpayAccountService', function($lo
|
|||
|
||||
var accountsArray = [];
|
||||
lodash.forEach(Object.keys(accounts), function(key) {
|
||||
accounts[key].bitpayDebitCards = accounts[key].cards;
|
||||
accounts[key].cards = accounts[key].cards;
|
||||
accounts[key].email = key;
|
||||
accounts[key].firstName = accounts[key].givenName || '';
|
||||
accounts[key].lastName = accounts[key].familyName || '';
|
||||
accounts[key].givenName = accounts[key].givenName || '';
|
||||
accounts[key].familyName = accounts[key].familyName || '';
|
||||
accounts[key].apiContext = {
|
||||
token: accounts[key].token,
|
||||
pairData: {
|
||||
|
@ -164,29 +164,14 @@ angular.module('copayApp.services').factory('bitpayAccountService', function($lo
|
|||
|
||||
var setBitpayAccount = function(account, cb) {
|
||||
storageService.setBitpayAccount(bitpayService.getEnvironment().network, account, function(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb();
|
||||
return cb(err);
|
||||
});
|
||||
};
|
||||
|
||||
root.removeAccount = function(account, cb) {
|
||||
storageService.removeBitpayAccount(bitpayService.getEnvironment().network, account, function(err) {
|
||||
if (err) {
|
||||
$log.error('Error removing BitPay account: ' + err);
|
||||
// Continue, try to remove next step if necessary
|
||||
}
|
||||
storageService.getBitpayDebitCards(bitpayService.getEnvironment().network, function(err, cards) {
|
||||
if (err) {
|
||||
$log.error('Error attempting to get BitPay debit cards after account removal: ' + err);
|
||||
}
|
||||
if (cards.length == 0) {
|
||||
storageService.removeNextStep('BitpayCard', cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
bitpayCardService.registerNextStep();
|
||||
cb(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -47,13 +47,27 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
|||
bitpayService.post('/api/v2/' + apiContext.token, json, function(data) {
|
||||
if (data && data.data.error) return cb(data.data.error);
|
||||
$log.info('BitPay Get Debit Cards: SUCCESS');
|
||||
// Cache card data in storage
|
||||
var cardData = {
|
||||
cards: data.data.data,
|
||||
email: apiContext.pairData.email
|
||||
}
|
||||
storageService.setBitpayDebitCards(bitpayService.getEnvironment().network, cardData, function(err) {
|
||||
return cb(err, {token: apiContext.token, cards: data.data.data, email: apiContext.pairData.email});
|
||||
|
||||
var cards = [];
|
||||
|
||||
lodash.each(data.data.data, function(x) {
|
||||
var n = {};
|
||||
|
||||
if (!x.eid || !x.id || !x.lastFourDigits || !x.token) {
|
||||
$log.warn('BAD data from Bitpay card' + JSON.stringify(x));
|
||||
return;
|
||||
}
|
||||
|
||||
n.eid = x.eid;
|
||||
n.id = x.id;
|
||||
n.lastFourDigits = x.lastFourDigits;
|
||||
n.token = x.token;
|
||||
cards.push(n);
|
||||
});
|
||||
|
||||
storageService.setBitpayDebitCards(bitpayService.getEnvironment().network, apiContext.pairData.email, cards, function(err) {
|
||||
root.registerNextStep();
|
||||
return cb(err, cards);
|
||||
});
|
||||
}, function(data) {
|
||||
return cb(_setError('BitPay Card Error: Get Debit Cards', data));
|
||||
|
@ -186,36 +200,17 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
|||
}, cb);
|
||||
};
|
||||
|
||||
root.removeCard = function(card, cb) {
|
||||
storageService.removeBitpayDebitCard(bitpayService.getEnvironment().network, card, function(err) {
|
||||
root.remove = function(cardId, cb) {
|
||||
storageService.removeBitpayDebitCard(bitpayService.getEnvironment().network, cardId, function(err) {
|
||||
if (err) {
|
||||
$log.error('Error removing BitPay debit card: ' + err);
|
||||
// Continue, try to remove/cleanup next step and card history
|
||||
return cb(err);
|
||||
}
|
||||
// Next two items in parallel
|
||||
//
|
||||
// If there are no more cards in storage then re-enable the next step entry
|
||||
storageService.getBitpayDebitCards(bitpayService.getEnvironment().network, function(err, cards) {
|
||||
if (err) {
|
||||
$log.error('Error getting BitPay debit cards after remove: ' + err);
|
||||
// Continue, try to remove next step if necessary
|
||||
}
|
||||
if (cards.length == 0) {
|
||||
storageService.removeNextStep('BitpayCard', cb);
|
||||
}
|
||||
});
|
||||
storageService.removeBitpayDebitCardHistory(bitpayService.getEnvironment().network, card, function(err) {
|
||||
if (err) {
|
||||
$log.error('Error removing BitPay debit card transaction history: ' + err);
|
||||
return cb(err);
|
||||
}
|
||||
$log.info('Successfully removed BitPay debit card');
|
||||
return cb();
|
||||
});
|
||||
root.registerNextStep();
|
||||
storageService.removeBalanceCache(cardId, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
root.getRates = function(currency, cb) {
|
||||
bitpayService.get('/rates/' + currency, function(data) {
|
||||
$log.info('BitPay Get Rates: SUCCESS');
|
||||
|
@ -1303,7 +1298,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
|||
};
|
||||
|
||||
|
||||
var register = function() {
|
||||
root.registerNextStep = function() {
|
||||
root.getCards(function(err, cards) {
|
||||
if (lodash.isEmpty(cards)) {
|
||||
nextStepsService.register(nextStepItem);
|
||||
|
@ -1313,7 +1308,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
|||
});
|
||||
};
|
||||
|
||||
register();
|
||||
root.registerNextStep();
|
||||
return root;
|
||||
|
||||
});
|
||||
|
|
|
@ -356,33 +356,22 @@ angular.module('copayApp.services')
|
|||
storage.remove('balanceCache-' + cardId, cb);
|
||||
};
|
||||
|
||||
// data: {
|
||||
// cards: [
|
||||
// eid: card id
|
||||
// id: card id
|
||||
// lastFourDigits: card number
|
||||
// token: card token
|
||||
// ]
|
||||
// email: account email
|
||||
// token: account token
|
||||
// }
|
||||
root.setBitpayDebitCards = function(network, data, cb) {
|
||||
if (lodash.isString(data)) {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
data = data || {};
|
||||
if (lodash.isEmpty(data) || !data.email) return cb('Cannot set cards: no account to set');
|
||||
|
||||
// cards: [
|
||||
// eid: card id
|
||||
// id: card id
|
||||
// lastFourDigits: card number
|
||||
// token: card token
|
||||
// ]
|
||||
root.setBitpayDebitCards = function(network, email, cards, cb) {
|
||||
root.getBitpayAccounts(network, function(err, allAccounts) {
|
||||
if (err) return cb(err);
|
||||
|
||||
allAccounts = allAccounts || {};
|
||||
if (!allAccounts[data.email]) {
|
||||
return cb('Cannot set cards for unknown account ' + data.email);
|
||||
if (!allAccounts[email]) {
|
||||
return cb('Cannot set cards for unknown account ' + email);
|
||||
}
|
||||
allAccounts[data.email] = allAccounts[data.email] || {};
|
||||
allAccounts[data.email]['bitpayDebitCards-' + network] = data.cards;
|
||||
storage.set('bitpayAccounts-v2-' + network, JSON.stringify(allAccounts), cb);
|
||||
|
||||
allAccounts[email].cards = cards;
|
||||
storage.set('bitpayAccounts-v2-' + network, allAccounts, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -403,7 +392,7 @@ angular.module('copayApp.services')
|
|||
lodash.each(allAccounts, function(account, email) {
|
||||
|
||||
if (account.cards) {
|
||||
// Add account's email to card list, for convenience
|
||||
// Add account's email to each card
|
||||
var cards = lodash.clone(account.cards);
|
||||
lodash.each(cards, function(x) {
|
||||
x.email = email;
|
||||
|
@ -417,14 +406,7 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
// card: {
|
||||
// eid: card id
|
||||
// id: card id
|
||||
// lastFourDigits: card number
|
||||
// token: card token
|
||||
// }
|
||||
root.removeBitpayDebitCard = function(network, cardEid, cb) {
|
||||
|
||||
root.getBitpayAccounts(network, function(err, allAccounts) {
|
||||
|
||||
lodash.each(allAccounts, function(account) {
|
||||
|
@ -500,7 +482,6 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
// data: {
|
||||
// email: account email
|
||||
// token: account token
|
||||
|
@ -530,7 +511,7 @@ angular.module('copayApp.services')
|
|||
// account: {
|
||||
// email: account email
|
||||
// apiContext: the context needed for making future api calls
|
||||
// bitpayDebitCards: an array of cards
|
||||
// cards: an array of cards
|
||||
// }
|
||||
root.removeBitpayAccount = function(network, account, cb) {
|
||||
if (lodash.isString(account)) {
|
||||
|
@ -538,36 +519,14 @@ angular.module('copayApp.services')
|
|||
}
|
||||
account = account || {};
|
||||
if (lodash.isEmpty(account)) return cb('No account to remove');
|
||||
storage.get('bitpayAccounts-v3-' + network, function(err, bitpayAccounts) {
|
||||
storage.get('bitpayAccounts-v2-' + network, function(err, bitpayAccounts) {
|
||||
if (err) cb(err);
|
||||
if (lodash.isString(bitpayAccounts)) {
|
||||
bitpayAccounts = JSON.parse(bitpayAccounts);
|
||||
}
|
||||
bitpayAccounts = bitpayAccounts || {};
|
||||
delete bitpayAccounts[account.email];
|
||||
storage.set('bitpayAccounts-v3-' + network, JSON.stringify(bitpayAccounts), cb);
|
||||
});
|
||||
};
|
||||
|
||||
// account: {
|
||||
// email: account email
|
||||
// apiContext: the context needed for making future api calls
|
||||
// bitpayDebitCards: an array of cards
|
||||
// }
|
||||
root.removeBitpayAccount = function(network, account, cb) {
|
||||
if (lodash.isString(account)) {
|
||||
account = JSON.parse(account);
|
||||
}
|
||||
account = account || {};
|
||||
if (lodash.isEmpty(account)) return cb('No account to remove');
|
||||
storage.get('bitpayAccounts-v3-' + network, function(err, bitpayAccounts) {
|
||||
if (err) cb(err);
|
||||
if (lodash.isString(bitpayAccounts)) {
|
||||
bitpayAccounts = JSON.parse(bitpayAccounts);
|
||||
}
|
||||
bitpayAccounts = bitpayAccounts || {};
|
||||
delete bitpayAccounts[account.email];
|
||||
storage.set('bitpayAccounts-v3-' + network, JSON.stringify(bitpayAccounts), cb);
|
||||
storage.set('bitpayAccounts-v2-' + network, JSON.stringify(bitpayAccounts), cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<div class="account-inner">
|
||||
<div class="account-details">
|
||||
<div class="account-name">
|
||||
{{a.firstName}} {{a.lastName}}
|
||||
{{a.givenName}} {{a.familyName}}
|
||||
</div>
|
||||
<p class="account-email" ng-if="a.email">
|
||||
<span>{{a.email}}</span>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</div>
|
||||
<div class="item item-icon-right" ng-repeat="account in bitpayAccounts">
|
||||
<span class="item-title">
|
||||
{{account.firstName}} {{account.lastName}}
|
||||
{{account.givenName}} {{account.familyName}}
|
||||
</span>
|
||||
<span class="item-subtitle">
|
||||
{{account.email}}
|
||||
|
|
Loading…
Reference in New Issue