Wallet/src/js/controllers/bitpayCardIntro.js

64 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-10-04 12:06:06 -03:00
'use strict';
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService, appIdentityService, bitpayService) {
2016-10-04 12:06:06 -03:00
$scope.$on("$ionicView.beforeEnter", function(event, data) {
2016-10-06 19:23:39 -03:00
if (data.stateParams && data.stateParams.secret) {
var pairData = {
2016-10-06 19:23:39 -03:00
secret: data.stateParams.secret,
email: data.stateParams.email,
otp: data.stateParams.otp
};
var pairingReason = gettextCatalog.getString('add your BitPay Visa<sup>&reg;</sup> card(s)');
bitpayService.pair(pairData, pairingReason, function(err, paired, apiContext) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
if (paired) {
bitpayCardService.fetchBitpayDebitCards(apiContext, function(err, data) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
// Set flag for nextStep
storageService.setNextStep('BitpayCard', 'true', function(err) {});
// Save data
bitpayCardService.setBitpayDebitCards(data, function(err) {
if (err) return;
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home').then(function() {
if (data.cards[0]) {
$state.transitionTo('tabs.bitpayCard', {
id: data.cards[0].id
});
}
});
});
});
}
2016-10-06 19:23:39 -03:00
});
} else {
appIdentityService.getIdentity(bitpayService.getEnvironment(), function(err, appIdentity) {
if (err) popupService.showAlert(null, err);
else $log.info('App identity: OK');
2016-10-07 19:21:46 -03:00
});
2016-10-06 19:23:39 -03:00
}
2016-10-04 12:06:06 -03:00
});
$scope.bitPayCardInfo = function() {
var url = 'https://bitpay.com/visa/faq';
externalLinkService.open(url);
};
2016-10-04 12:06:06 -03:00
$scope.orderBitPayCard = function() {
var url = 'https://bitpay.com/visa/get-started';
2016-10-13 20:11:02 -03:00
externalLinkService.open(url);
2016-10-04 12:06:06 -03:00
};
2016-10-06 19:23:39 -03:00
$scope.connectBitPayCard = function() {
var url = 'https://bitpay.com/visa/dashboard/add-to-bitpay-wallet-confirm';
2016-10-13 20:11:02 -03:00
externalLinkService.open(url);
2016-10-06 19:23:39 -03:00
};
2016-10-04 12:06:06 -03:00
});