Improved bitpay account pairing and management of paired state and data.
This commit is contained in:
parent
15d12823ab
commit
63bc3d8f63
23 changed files with 691 additions and 208 deletions
75
src/js/controllers/preferencesBitpayServices.js
Normal file
75
src/js/controllers/preferencesBitpayServices.js
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesBitpayServicesController',
|
||||
function($rootScope, $scope, $state, $timeout, $ionicHistory, bitpayAccountService, bitpayCardService, popupService, gettextCatalog) {
|
||||
|
||||
$scope.removeAccount = function(account) {
|
||||
var title = gettextCatalog.getString('Remove BitPay Account?');
|
||||
var msg = gettextCatalog.getString('Removing your BitPay account will remove all associated BitPay account data from this device.<br/><br/>Are you sure you would like to remove your BitPay Account ({{email}}) from this device?', {
|
||||
email: account.email
|
||||
});
|
||||
popupService.showConfirm(title, msg, null, null, function(res) {
|
||||
if (res) {
|
||||
removeAccount(account);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.removeCard = function(card) {
|
||||
var title = gettextCatalog.getString('Remove BitPay Card?');
|
||||
var msg = gettextCatalog.getString('Are you sure you would like to remove your BitPay Card ({{lastFourDigits}}) from this device?', {
|
||||
lastFourDigits: card.lastFourDigits
|
||||
});
|
||||
popupService.showConfirm(title, msg, null, null, function(res) {
|
||||
if (res) {
|
||||
removeCard(card);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var removeAccount = function(account) {
|
||||
bitpayAccountService.removeAccount(account, function(err) {
|
||||
if (err) {
|
||||
return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not remove account'));
|
||||
}
|
||||
setScope(function() {
|
||||
// If there are no paired accounts then change views.
|
||||
if ($scope.bitpayAccounts.length == 0) {
|
||||
$state.go('tabs.settings').then(function() {
|
||||
$ionicHistory.clearHistory();
|
||||
$state.go('tabs.home');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var removeCard = function(card) {
|
||||
bitpayCardService.removeCard(card, function(err) {
|
||||
if (err) {
|
||||
return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not remove card'));
|
||||
}
|
||||
setScope();
|
||||
});
|
||||
};
|
||||
|
||||
var setScope = function(cb) {
|
||||
bitpayAccountService.getAccounts(function(err, data) {
|
||||
if (err) return;
|
||||
$scope.bitpayAccounts = data;
|
||||
|
||||
bitpayCardService.getBitpayDebitCards(function(err, data) {
|
||||
if (err) return;
|
||||
$scope.bitpayCards = data;
|
||||
if (cb) {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
setScope();
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue