Skip to content

Commit

Permalink
Amazon uses new popupService
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgustavo committed Aug 30, 2016
1 parent 47856f0 commit 63327be
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
21 changes: 9 additions & 12 deletions public/views/buyAmazon.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
12 changes: 4 additions & 8 deletions src/js/controllers/amazon.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
Expand All @@ -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') {
Expand All @@ -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;
Expand Down
33 changes: 10 additions & 23 deletions src/js/controllers/buyAmazon.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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();
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/js/services/popupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 63327be

Please sign in to comment.