From 2724911a050f520af2baacee3d71f5af43e50b36 Mon Sep 17 00:00:00 2001 From: JDonadio Date: Wed, 5 Apr 2017 14:38:06 -0300 Subject: [PATCH] fix params and errors handling --- src/js/services/incomingData.js | 10 ++--- src/js/services/payproService.js | 64 +++++++++++++------------------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index 0c730ed79..c9d633eb8 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, $rootScope, payproService, scannerService, appConfigService) { +angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, $rootScope, payproService, scannerService, appConfigService, popupService, gettextCatalog) { var root = {}; @@ -93,10 +93,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat if (parsed.r) { payproService.getPayProDetails(parsed.r, function(err, details) { - if (err && addr && amount) { - goSend(addr, amount, message); - } - handlePayPro(details); + if (err) { + if (addr && amount) goSend(addr, amount, message); + else popupService.showAlert(gettextCatalog.getString('Error'), err); + } else handlePayPro(details); }); } else { goSend(addr, amount, message); diff --git a/src/js/services/payproService.js b/src/js/services/payproService.js index ba5adb4b9..96ed90441 100644 --- a/src/js/services/payproService.js +++ b/src/js/services/payproService.js @@ -1,51 +1,39 @@ 'use strict'; angular.module('copayApp.services').factory('payproService', -function($window, profileService, platformInfo, popupService, gettextCatalog, ongoingProcess, $log) { + function(profileService, platformInfo, gettextCatalog, ongoingProcess, $log) { - var ret = {}; + var ret = {}; - ret.getPayProDetails = function(uri, cb, disableLoader) { - if (!cb) cb = function() {}; + ret.getPayProDetails = function(uri, cb, disableLoader) { + if (!cb) cb = function() {}; - var wallet = profileService.getWallets({ - onlyComplete: true - })[0]; + var wallet = profileService.getWallets({ + onlyComplete: true + })[0]; - if (!wallet) return cb(); + if (!wallet) return cb(); - if (platformInfo.isChromeApp) { - popupService.showAlert(gettextCatalog.getString('Payment Protocol not supported on Chrome App')); - return cb(true); - } - - $log.debug('Fetch PayPro Request...', uri); - - if(!disableLoader) { - ongoingProcess.set('fetchingPayPro', true); - } - - wallet.fetchPayPro({ - payProUrl: uri, - }, function(err, paypro) { - - if(!disableLoader) { - ongoingProcess.set('fetchingPayPro', false); + if (platformInfo.isChromeApp) { + return cb(gettextCatalog.getString('Payment Protocol not supported on Chrome App')); } - if (err) { - return cb(true); - } + $log.debug('Fetch PayPro Request...', uri); - if (!paypro.verified) { - $log.warn('Failed to verify payment protocol signatures'); - popupService.showAlert(gettextCatalog.getString('Payment Protocol Invalid')); - return cb(true); - } - cb(null, paypro); + if (!disableLoader) ongoingProcess.set('fetchingPayPro', true); - }); - }; + wallet.fetchPayPro({ + payProUrl: uri, + }, function(err, paypro) { + if (!disableLoader) ongoingProcess.set('fetchingPayPro', false); + if (err) return cb(err); + else if (!paypro.verified) { + $log.warn('Failed to verify payment protocol signatures'); + return cb(gettextCatalog.getString('Payment Protocol Invalid')); + } + return cb(null, paypro); + }); + }; - return ret; -}); + return ret; + });