Amazon uses new popupService

This commit is contained in:
Gustavo Maximiliano Cortez 2016-08-30 20:47:55 -03:00
parent 47856f03ff
commit 63327beceb
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
4 changed files with 25 additions and 45 deletions

View File

@ -12,18 +12,15 @@
<div ng-show="!buy.giftCard">
<div class="box-notification error" ng-show="buy.error" ng-click="buy.error = null">
{{buy.error}}
<div ng-show="buy.errorInfo">
There was an error when trying to buy gift card, but the funds were sent to BitPay Invoice. Please, contact
BitPay to refund your bitcoin
<div>
Amount: {{buy.errorInfo.amount}} {{buy.errorInfo.currency}}<br>
BitPay Invoice ID: {{buy.errorInfo.invoiceId}}.
</div>
<div class="text-center">
<a ng-click="openExternalLink(buy.errorInfo.invoiceUrl)">Open invoice</a>
</div>
<div class="box-notification error" ng-show="buy.errorInfo" ng-click="buy.errorInfo = null">
There was an error when trying to buy gift card, but the funds were sent to BitPay Invoice. Please, contact
BitPay to refund your bitcoin
<div>
Amount: {{buy.errorInfo.amount}} {{buy.errorInfo.currency}}<br>
BitPay Invoice ID: {{buy.errorInfo.invoiceId}}.
</div>
<div class="text-center">
<a ng-click="openExternalLink(buy.errorInfo.invoiceUrl)">Open invoice</a>
</div>
</div>

View File

@ -1,11 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('amazonController',
function($scope, $timeout, $ionicModal, $log, lodash, bwcError, amazonService, platformInfo, nodeWebkit) {
if (platformInfo.isCordova && StatusBar.isVisible) {
StatusBar.backgroundColorByHexString("#4B6178");
}
function($scope, $timeout, $ionicModal, $log, lodash, bwcError, amazonService, platformInfo, nodeWebkit, popupService) {
$scope.openExternalLink = function(url, target) {
if (platformInfo.isNW) {
@ -21,7 +17,7 @@ angular.module('copayApp.controllers').controller('amazonController',
$scope.network = amazonService.getEnvironment();
amazonService.getPendingGiftCards(function(err, gcds) {
if (err) {
self.error = err;
popupService.showAlert(err);
return;
}
$scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
@ -41,7 +37,7 @@ angular.module('copayApp.controllers').controller('amazonController',
$log.debug("creating gift card");
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) {
$log.debug(bwcError.msg(err));
popupService.showAlert(bwcError.msg(err));
return;
}
if (giftCard.status != 'PENDING') {
@ -61,7 +57,7 @@ angular.module('copayApp.controllers').controller('amazonController',
$log.debug("Saving new gift card");
amazonService.getPendingGiftCards(function(err, gcds) {
if (err) {
self.error = err;
popupService.showAlert(err);
return;
}
$scope.giftCards = gcds;

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('buyAmazonController',
function($rootScope, $scope, $ionicModal, $log, $timeout, $state, $ionicPopup, lodash, profileService, bwcError, gettext, configService, walletService, fingerprintService, amazonService, ongoingProcess, platformInfo, nodeWebkit) {
function($scope, $log, $timeout, $state, lodash, profileService, bwcError, gettextCatalog, configService, walletService, amazonService, ongoingProcess, platformInfo, nodeWebkit, popupService) {
var self = this;
var wallet;
@ -33,14 +33,13 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
};
this.createTx = function() {
self.error = null;
self.errorInfo = null;
if (lodash.isEmpty(wallet)) return;
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');
self.error = bwcError.msg('MISSING_PRIVATE_KEY');
popupService.showAler(gettextCatalog.getString('Error'), bwcError.msg('MISSING_PRIVATE_KEY'));
return;
}
@ -60,20 +59,14 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
amazonService.createBitPayInvoice(dataSrc, function(err, dataInvoice) {
if (err) {
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
$timeout(function() {
$scope.$digest();
});
popupService.showAler(gettextCatalog.getString('Error'), bwcError.msg(err));
return;
}
amazonService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) {
if (err) {
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
$timeout(function() {
$scope.$digest();
});
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
return;
}
@ -88,19 +81,16 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
$log.warn('Could not fetch payment request:', err);
var msg = err.toString();
if (msg.match('HTTP')) {
msg = gettext('Could not fetch payment information');
msg = gettextCatalog.getString('Could not fetch payment information');
}
self.error = msg;
$timeout(function() {
$scope.$digest();
});
popupService.showAlert(gettextCatalog.getString('Error'), msg);
return;
}
if (!paypro.verified) {
ongoingProcess.set('Processing Transaction...', false);
$log.warn('Failed to verify payment protocol signatures');
self.error = gettext('Payment Protocol Invalid');
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Payment Protocol Invalid'));
$timeout(function() {
$scope.$digest();
});
@ -133,16 +123,13 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
walletService.createTx(wallet, txp, function(err, createdTxp) {
ongoingProcess.set('Processing Transaction...', false);
if (err) {
self.error = bwcError.msg(err);
$timeout(function() {
$scope.$digest();
});
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
return;
}
walletService.publishAndSign(wallet, createdTxp, function(err, tx) {
if (err) {
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
walletService.removeTx(wallet, tx, function(err) {
if (err) $log.debug(err);
});
@ -182,7 +169,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
giftCard = {};
giftCard.status = 'FAILURE';
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
self.errorInfo = dataSrc;
$timeout(function() {
$scope.$digest();

View File

@ -62,12 +62,12 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni
* Show a simple alert popup
*
* @param {String} Title
* @param {String} Message
* @param {String} Message (optional)
* @param {Callback} Function (optional)
*/
this.showAlert = function(title, msg, cb) {
var message = msg.message ? msg.message : msg;
var message = (msg && msg.message) ? msg.message : msg;
$log.warn(title + ": " + message);
if (isCordova)