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

View File

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

View File

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

View File

@ -39,7 +39,11 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
'sendingByEmail': gettext('Preparing addresses...'),
'sending2faCode': gettext('Sending 2FA code...'),
'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() {

View File

@ -12,23 +12,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
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) {
$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));
$rootScope.$emit('Local/TxAction', wallet.id);
var type = root.getViewStatus(wallet, broadcastedTxp);
if (!customStatusHandler) {
root.openStatusModal(type, broadcastedTxp, function() {});
}
return cb(null, broadcastedTxp);
});
} else {
$rootScope.$emit('Local/TxAction', wallet.id);
var type = root.getViewStatus(wallet, signedTxp);
if (!customStatusHandler) {
root.openStatusModal(type, signedTxp, function() {});
}
return cb(null, signedTxp);
}
});
@ -1053,38 +1023,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
} 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) {
opts = opts || {};
wallet.getSendMaxInfo(opts, function(err, res) {