fetch paypro details before navigating to confirm view for a topup

This commit is contained in:
Marty Alcala 2016-10-26 16:03:20 -04:00
commit c0c08eeb59
4 changed files with 28 additions and 30 deletions

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError) { angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService) {
var unitToSatoshi; var unitToSatoshi;
var satToUnit; var satToUnit;
@ -203,7 +203,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
$timeout(function() { $timeout(function() {
bitpayCardService.topUp($scope.cardId, dataSrc, function(err, invoiceId) { bitpayCardService.topUp($scope.cardId, dataSrc, function(err, invoiceId) {
console.log('hereerere');
if (err) { if (err) {
ongoingProcess.set('Preparing transaction...', false); ongoingProcess.set('Preparing transaction...', false);
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
@ -211,18 +210,30 @@ angular.module('copayApp.controllers').controller('amountController', function($
} }
bitpayCardService.getInvoice(invoiceId, function(err, data) { bitpayCardService.getInvoice(invoiceId, function(err, data) {
ongoingProcess.set('Preparing transaction...', false);
if (err) { if (err) {
ongoingProcess.set('Preparing transaction...', false);
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
return; return;
} }
var payProUrl = data.paymentUrls.BIP73; var payProUrl = data.paymentUrls.BIP73;
$state.transitionTo('tabs.bitpayCard.confirm', { payproService.getPayProDetails(payProUrl, function(err, payProDetails) {
cardId: $scope.cardId, ongoingProcess.set('Preparing transaction...', false);
toName: $scope.toName, if (err) {
payProUrl: payProUrl popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
}); return;
}
var stateParams = {
cardId: $scope.cardId,
toName: $scope.toName,
toAmount: payProDetails.amount,
toAddress: payProDetails.toAddress,
description: payProDetails.memo,
paypro: payProDetails
};
$state.transitionTo('tabs.bitpayCard.confirm', stateParams);
}, true);
}); });
}); });
}); });

View file

@ -15,7 +15,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.toEmail = data.stateParams.toEmail; $scope.toEmail = data.stateParams.toEmail;
$scope.description = data.stateParams.description; $scope.description = data.stateParams.description;
$scope.paypro = data.stateParams.paypro; $scope.paypro = data.stateParams.paypro;
$scope.payProUrl = data.stateParams.payProUrl;
$scope._paypro = $scope.paypro; $scope._paypro = $scope.paypro;
$scope.paymentExpired = { $scope.paymentExpired = {
value: false value: false
@ -27,19 +26,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
var initConfirm = function() { var initConfirm = function() {
console.log('in init confirm');
console.log('$scope.paypro', $scope.paypro);
if($scope.payProUrl && !$scope.paypro) {
console.log('getting paypro details', $scope.payProUrl);
payproService.getPayProDetails($scope.payProUrl, function(err, details) {
console.log('paypro details', details);
$scope.toAmount = details.amount;
$scope.toAddress = details.toAddress;
$scope.description = details.memo;
$scope.paypro = details;
return initConfirm();
});
}
// TODO (URL , etc) // TODO (URL , etc)
if (!$scope.toAddress || !$scope.toAmount) { if (!$scope.toAddress || !$scope.toAmount) {
$log.error('Bad params at amount'); $log.error('Bad params at amount');

View file

@ -8,10 +8,6 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
$rootScope.$broadcast('incomingDataMenu.showMenu', data); $rootScope.$broadcast('incomingDataMenu.showMenu', data);
}; };
// $timeout(function() {
// root.redir();
// }, 2000);
root.redir = function(data) { root.redir = function(data) {
$log.debug('Processing incoming data: ' + data); $log.debug('Processing incoming data: ' + data);
@ -51,7 +47,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
} }
data = sanitizeUri(data); data = sanitizeUri(data);
data = 'https://test.bitpay.com:443/i/YSHFLkxxVAZhQMGFi9Ptq9'; //data = 'https://test.bitpay.com:443/i/YSHFLkxxVAZhQMGFi9Ptq9';
// BIP21 // BIP21
if (bitcore.URI.isValid(data)) { if (bitcore.URI.isValid(data)) {

View file

@ -5,7 +5,7 @@ function($window, profileService, platformInfo, popupService, gettextCatalog, on
var ret = {}; var ret = {};
ret.getPayProDetails = function(uri, cb) { ret.getPayProDetails = function(uri, cb, disableLoader) {
if (!cb) cb = function() {}; if (!cb) cb = function() {};
var wallet = profileService.getWallets({ var wallet = profileService.getWallets({
@ -21,13 +21,18 @@ function($window, profileService, platformInfo, popupService, gettextCatalog, on
$log.debug('Fetch PayPro Request...', uri); $log.debug('Fetch PayPro Request...', uri);
ongoingProcess.set('fetchingPayPro', true); if(!disableLoader) {
ongoingProcess.set('fetchingPayPro', true);
}
wallet.fetchPayPro({ wallet.fetchPayPro({
payProUrl: uri, payProUrl: uri,
}, function(err, paypro) { }, function(err, paypro) {
ongoingProcess.set('fetchingPayPro', false); if(!disableLoader) {
ongoingProcess.set('fetchingPayPro', false);
}
if (err) { if (err) {
return cb(true); return cb(true);
} }