Merge pull request #5327 from gabrielbazan7/feat/addLoadingAmazon

manual loading and some details fixes
This commit is contained in:
Gustavo Maximiliano Cortez 2016-12-23 13:09:27 -03:00 committed by GitHub
commit 833b98ac21
5 changed files with 56 additions and 85 deletions

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('amazonController', angular.module('copayApp.controllers').controller('amazonController',
function($scope, $timeout, $ionicModal, $log, lodash, amazonService, platformInfo, externalLinkService, popupService, gettextCatalog) { function($scope, $timeout, $ionicModal, $log, $ionicScrollDelegate, lodash, amazonService, platformInfo, externalLinkService, popupService, ongoingProcess) {
$scope.network = amazonService.getEnvironment(); $scope.network = amazonService.getEnvironment();
@ -12,7 +12,7 @@ angular.module('copayApp.controllers').controller('amazonController',
var initAmazon = function() { var initAmazon = function() {
amazonService.getPendingGiftCards(function(err, gcds) { amazonService.getPendingGiftCards(function(err, gcds) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err); popupService.showAlert('Error', err);
return; return;
} }
$scope.giftCards = lodash.isEmpty(gcds) ? null : gcds; $scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
@ -24,7 +24,7 @@ angular.module('copayApp.controllers').controller('amazonController',
claimCode: $scope.cardClaimCode claimCode: $scope.cardClaimCode
}); });
if (lodash.isEmpty(card)) { if (lodash.isEmpty(card)) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Card not found')); popupService.showAlert('Error', 'Card not found');
return; return;
} }
$scope.openCardModal(card); $scope.openCardModal(card);
@ -34,18 +34,29 @@ angular.module('copayApp.controllers').controller('amazonController',
}; };
$scope.updatePendingGiftCards = lodash.debounce(function() { $scope.updatePendingGiftCards = lodash.debounce(function() {
ongoingProcess.set('updatingGiftCards', true);
amazonService.getPendingGiftCards(function(err, gcds) { amazonService.getPendingGiftCards(function(err, gcds) {
if (lodash.isEmpty(gcds)) {
$timeout(function() {
ongoingProcess.set('updatingGiftCards', false);
}, 1000);
}
$timeout(function() { $timeout(function() {
$scope.giftCards = gcds; $scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
$scope.$digest(); $scope.$digest();
}); });
var index = 0;
lodash.forEach(gcds, function(dataFromStorage) { lodash.forEach(gcds, function(dataFromStorage) {
if (++index == Object.keys(gcds).length) {
$timeout(function() {
ongoingProcess.set('updatingGiftCards', false);
}, 1000);
}
if (dataFromStorage.status == 'PENDING') { if (dataFromStorage.status == 'PENDING') {
$log.debug("creating gift card"); $log.debug("creating gift card");
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) { amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err); popupService.showAlert('Error', err);
return; return;
} }
if (giftCard.status != 'PENDING') { if (giftCard.status != 'PENDING') {
@ -65,13 +76,14 @@ angular.module('copayApp.controllers').controller('amazonController',
$log.debug("Saving new gift card"); $log.debug("Saving new gift card");
amazonService.getPendingGiftCards(function(err, gcds) { amazonService.getPendingGiftCards(function(err, gcds) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err); popupService.showAlert('Error', err);
return; return;
} }
$scope.giftCards = gcds; $scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
$timeout(function() { $timeout(function() {
$scope.$digest(); $scope.$digest();
}); $ionicScrollDelegate.resize();
}, 10);
}); });
}); });
} else $log.debug("pending gift card not available yet"); } else $log.debug("pending gift card not available yet");
@ -80,7 +92,9 @@ angular.module('copayApp.controllers').controller('amazonController',
}); });
}); });
}, 1000); }, 1000, {
'leading': true
});
$scope.openCardModal = function(card) { $scope.openCardModal = function(card) {
$scope.card = card; $scope.card = card;
@ -92,8 +106,8 @@ angular.module('copayApp.controllers').controller('amazonController',
$scope.amazonCardDetailsModal.show(); $scope.amazonCardDetailsModal.show();
}); });
$scope.$on('UpdateAmazonList', function(event) { $scope.$on('modal.hidden', function() {
initAmazon(); $scope.updatePendingGiftCards();
}); });
}; };

View file

@ -783,6 +783,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
invoiceUrl: $scope.paypro.url, invoiceUrl: $scope.paypro.url,
invoiceTime: giftCardInvoiceTime invoiceTime: giftCardInvoiceTime
}; };
ongoingProcess.set('creatingGiftCard', true);
debounceCreate(count, dataSrc, onSendStatusChange); debounceCreate(count, dataSrc, onSendStatusChange);
} }
}, onSendStatusChange); }, onSendStatusChange);
@ -795,7 +796,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
var debounceCreateGiftCard = function(count, dataSrc, onSendStatusChange) { var debounceCreateGiftCard = function(count, dataSrc, onSendStatusChange) {
amazonService.createGiftCard(dataSrc, function(err, giftCard) { amazonService.createGiftCard(dataSrc, function(err, giftCard) {
$log.debug("creating gift card " + count); $log.debug("creating gift card " + count);
if (err) { if (err) {
@ -830,6 +830,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
} }
amazonService.savePendingGiftCard(newData, null, function(err) { amazonService.savePendingGiftCard(newData, null, function(err) {
ongoingProcess.set('creatingGiftCard', false);
$log.debug("Saving new gift card with status: " + newData.status); $log.debug("Saving new gift card with status: " + newData.status);
$scope.amazonGiftCard = newData; $scope.amazonGiftCard = newData;
}); });

View file

@ -1,18 +1,22 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $log, $timeout, bwcError, amazonService, lodash, ongoingProcess, popupService, gettextCatalog, externalLinkService) { angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $log, $timeout, $ionicScrollDelegate, bwcError, amazonService, lodash, ongoingProcess, popupService, externalLinkService) {
$scope.cancelGiftCard = function() { $scope.cancelGiftCard = function() {
ongoingProcess.set('Canceling gift card...', true); ongoingProcess.set('cancelingGiftCard', true);
amazonService.cancelGiftCard($scope.card, function(err, data) { amazonService.cancelGiftCard($scope.card, function(err, data) {
ongoingProcess.set('Canceling gift card...', false); ongoingProcess.set('cancelingGiftCard', false);
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); popupService.showAlert('Error', bwcError.msg(err));
return; return;
} }
$scope.card.cardStatus = data.cardStatus; $scope.card.cardStatus = data.cardStatus;
$timeout(function() {
$ionicScrollDelegate.resize();
$ionicScrollDelegate.scrollTop();
}, 10);
amazonService.savePendingGiftCard($scope.card, null, function(err) { amazonService.savePendingGiftCard($scope.card, null, function(err) {
$scope.$emit('UpdateAmazonList'); $scope.refreshGiftCard();
}); });
}); });
}; };
@ -21,23 +25,34 @@ angular.module('copayApp.controllers').controller('amazonCardDetailsController',
amazonService.savePendingGiftCard($scope.card, { amazonService.savePendingGiftCard($scope.card, {
remove: true remove: true
}, function(err) { }, function(err) {
$scope.$emit('UpdateAmazonList');
$scope.cancel(); $scope.cancel();
}); });
}; };
$scope.refreshGiftCard = function() { $scope.refreshGiftCard = function() {
ongoingProcess.set('updatingGiftCard', true);
amazonService.getPendingGiftCards(function(err, gcds) { amazonService.getPendingGiftCards(function(err, gcds) {
if (lodash.isEmpty(gcds)) {
$timeout(function() {
ongoingProcess.set('updatingGiftCard', false);
}, 1000);
}
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err); popupService.showAlert('Error', err);
return; return;
} }
var index = 0;
lodash.forEach(gcds, function(dataFromStorage) { lodash.forEach(gcds, function(dataFromStorage) {
if (++index == Object.keys(gcds).length) {
$timeout(function() {
ongoingProcess.set('updatingGiftCard', false);
}, 1000);
}
if (dataFromStorage.status == 'PENDING' && dataFromStorage.invoiceId == $scope.card.invoiceId) { if (dataFromStorage.status == 'PENDING' && dataFromStorage.invoiceId == $scope.card.invoiceId) {
$log.debug("creating gift card"); $log.debug("creating gift card");
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) { amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err)); popupService.showAlert('Error', bwcError.msg(err));
return; return;
} }
if (!lodash.isEmpty(giftCard)) { if (!lodash.isEmpty(giftCard)) {
@ -46,7 +61,6 @@ angular.module('copayApp.controllers').controller('amazonCardDetailsController',
amazonService.savePendingGiftCard(newData, null, function(err) { amazonService.savePendingGiftCard(newData, null, function(err) {
$log.debug("Saving new gift card"); $log.debug("Saving new gift card");
$scope.card = newData; $scope.card = newData;
$scope.$emit('UpdateAmazonList');
$timeout(function() { $timeout(function() {
$scope.$digest(); $scope.$digest();
}); });

View file

@ -39,7 +39,11 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
'sendingByEmail': gettext('Preparing addresses...'), 'sendingByEmail': gettext('Preparing addresses...'),
'sending2faCode': gettext('Sending 2FA code...'), 'sending2faCode': gettext('Sending 2FA code...'),
'buyingBitcoin': gettext('Buying Bitcoin...'), 'buyingBitcoin': gettext('Buying Bitcoin...'),
'sellingBitcoin': gettext('Selling Bitcoin...') 'sellingBitcoin': gettext('Selling Bitcoin...'),
'updatingGiftCards': 'Updating Gift Cards...',
'updatingGiftCard': 'Updating Gift Card...',
'cancelingGiftCard': 'Canceling Gift Card...',
'creatingGiftCard': 'Creating Gift Card...'
}; };
root.clear = function() { root.clear = function() {

View file

@ -12,23 +12,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
var errors = bwcService.getErrors(); var errors = bwcService.getErrors();
// UI Related
root.openStatusModal = function(type, txp, cb) {
var scope = $rootScope.$new(true);
scope.type = type;
scope.tx = txFormatService.processTx(txp);
scope.color = txp.color;
scope.cb = cb;
$ionicModal.fromTemplateUrl('views/modals/tx-status.html', {
scope: scope,
animation: 'slide-in-up'
}).then(function(modal) {
scope.txStatusModal = modal;
scope.txStatusModal.show();
});
};
var _signWithLedger = function(wallet, txp, cb) { var _signWithLedger = function(wallet, txp, cb) {
$log.info('Requesting Ledger Chrome app to sign the transaction'); $log.info('Requesting Ledger Chrome app to sign the transaction');
@ -961,23 +944,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (err) return cb(bwcError.msg(err)); if (err) return cb(bwcError.msg(err));
$rootScope.$emit('Local/TxAction', wallet.id); $rootScope.$emit('Local/TxAction', wallet.id);
var type = root.getViewStatus(wallet, broadcastedTxp);
if (!customStatusHandler) {
root.openStatusModal(type, broadcastedTxp, function() {});
}
return cb(null, broadcastedTxp); return cb(null, broadcastedTxp);
}); });
} else { } else {
$rootScope.$emit('Local/TxAction', wallet.id); $rootScope.$emit('Local/TxAction', wallet.id);
var type = root.getViewStatus(wallet, signedTxp);
if (!customStatusHandler) {
root.openStatusModal(type, signedTxp, function() {});
}
return cb(null, signedTxp); return cb(null, signedTxp);
} }
}); });
@ -1053,38 +1023,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
} catch (e) {} } catch (e) {}
} }
root.getViewStatus = function(wallet, txp) {
var status = txp.status;
var type;
var INMEDIATE_SECS = 10;
if (status == 'broadcasted') {
type = 'broadcasted';
} else {
var n = txp.actions.length;
var action = lodash.find(txp.actions, {
copayerId: wallet.credentials.copayerId
});
if (!action) {
type = 'created';
} else if (action.type == 'accept') {
// created and accepted at the same time?
if (n == 1 && action.createdOn - txp.createdOn < INMEDIATE_SECS) {
type = 'created';
} else {
type = 'accepted';
}
} else if (action.type == 'reject') {
type = 'rejected';
} else {
throw new Error('Unknown type:' + type);
}
}
return type;
};
root.getSendMaxInfo = function(wallet, opts, cb) { root.getSendMaxInfo = function(wallet, opts, cb) {
opts = opts || {}; opts = opts || {};
wallet.getSendMaxInfo(opts, function(err, res) { wallet.getSendMaxInfo(opts, function(err, res) {