From a2c6639962887844c23b56d863840ac25ee84e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 22 Dec 2016 12:27:43 -0300 Subject: [PATCH 1/3] manual loading and some details fixes --- src/js/controllers/amazon.js | 38 ++++++++---- src/js/controllers/confirm.js | 3 +- .../controllers/modals/amazonCardDetails.js | 32 +++++++--- src/js/services/amazonService.js | 2 +- src/js/services/onGoingProcess.js | 6 +- src/js/services/walletService.js | 62 ------------------- 6 files changed, 58 insertions(+), 85 deletions(-) diff --git a/src/js/controllers/amazon.js b/src/js/controllers/amazon.js index 402f831de..d0e36efe6 100644 --- a/src/js/controllers/amazon.js +++ b/src/js/controllers/amazon.js @@ -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('updateGiftCards', true); amazonService.getPendingGiftCards(function(err, gcds) { + if (lodash.isEmpty(gcds)) { + $timeout(function() { + ongoingProcess.set('updateGiftCards', false); + }, 1000); + } $timeout(function() { - $scope.giftCards = gcds; + $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('updateGiftCards', 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,10 +76,10 @@ 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(); }); @@ -80,7 +91,9 @@ angular.module('copayApp.controllers').controller('amazonController', }); }); - }, 1000); + }, 1000, { + 'leading': true + }); $scope.openCardModal = function(card) { $scope.card = card; @@ -92,8 +105,11 @@ angular.module('copayApp.controllers').controller('amazonController', $scope.amazonCardDetailsModal.show(); }); - $scope.$on('UpdateAmazonList', function(event) { - initAmazon(); + $scope.$on('modal.hidden', function() { + $scope.updatePendingGiftCards(); + $timeout(function() { + $ionicScrollDelegate.resize(); + }, 10); }); }; diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index f7365ec65..49fafd5cf 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -783,6 +783,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( invoiceUrl: $scope.paypro.url, invoiceTime: giftCardInvoiceTime }; + ongoingProcess.set('createGiftCard', 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('createGiftCard', false); $log.debug("Saving new gift card with status: " + newData.status); $scope.amazonGiftCard = newData; }); diff --git a/src/js/controllers/modals/amazonCardDetails.js b/src/js/controllers/modals/amazonCardDetails.js index b567c99b1..fee456e87 100644 --- a/src/js/controllers/modals/amazonCardDetails.js +++ b/src/js/controllers/modals/amazonCardDetails.js @@ -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('cancelGiftCard', true); amazonService.cancelGiftCard($scope.card, function(err, data) { - ongoingProcess.set('Canceling gift card...', false); + ongoingProcess.set('cancelGiftCard', 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('updateGiftCard', true); amazonService.getPendingGiftCards(function(err, gcds) { + if (lodash.isEmpty(gcds)) { + $timeout(function() { + ongoingProcess.set('updateGiftCard', 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('updateGiftCard', 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(); }); diff --git a/src/js/services/amazonService.js b/src/js/services/amazonService.js index 4d82bc337..a26d87dd9 100644 --- a/src/js/services/amazonService.js +++ b/src/js/services/amazonService.js @@ -8,7 +8,7 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo * Development: 'testnet' * Production: 'livenet' */ - credentials.NETWORK = 'livenet'; + credentials.NETWORK = 'testnet'; if (credentials.NETWORK == 'testnet') { credentials.BITPAY_API_URL = "https://test.bitpay.com"; diff --git a/src/js/services/onGoingProcess.js b/src/js/services/onGoingProcess.js index b543430ab..3248a7be2 100644 --- a/src/js/services/onGoingProcess.js +++ b/src/js/services/onGoingProcess.js @@ -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...'), + 'updateGiftCards': gettext('Updating Gift Cards...'), + 'updateGiftCard': gettext('Updating Gift Card...'), + 'cancelGiftCard': gettext('Canceling Gift Card...'), + 'createGiftCard': gettext('Creating Gift Card...') }; root.clear = function() { diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 4546dc4af..b12f94ce8 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -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) { From 3bef5ce7fffce993cbd635eb66d03e0da2c9f281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 22 Dec 2016 12:32:43 -0300 Subject: [PATCH 2/3] fixes --- src/js/controllers/amazon.js | 6 ++---- src/js/services/amazonService.js | 2 +- src/js/services/onGoingProcess.js | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/js/controllers/amazon.js b/src/js/controllers/amazon.js index d0e36efe6..0c6863d9e 100644 --- a/src/js/controllers/amazon.js +++ b/src/js/controllers/amazon.js @@ -82,7 +82,8 @@ angular.module('copayApp.controllers').controller('amazonController', $scope.giftCards = lodash.isEmpty(gcds) ? null : gcds; $timeout(function() { $scope.$digest(); - }); + $ionicScrollDelegate.resize(); + }, 10); }); }); } else $log.debug("pending gift card not available yet"); @@ -107,9 +108,6 @@ angular.module('copayApp.controllers').controller('amazonController', $scope.$on('modal.hidden', function() { $scope.updatePendingGiftCards(); - $timeout(function() { - $ionicScrollDelegate.resize(); - }, 10); }); }; diff --git a/src/js/services/amazonService.js b/src/js/services/amazonService.js index a26d87dd9..4d82bc337 100644 --- a/src/js/services/amazonService.js +++ b/src/js/services/amazonService.js @@ -8,7 +8,7 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo * Development: 'testnet' * Production: 'livenet' */ - credentials.NETWORK = 'testnet'; + credentials.NETWORK = 'livenet'; if (credentials.NETWORK == 'testnet') { credentials.BITPAY_API_URL = "https://test.bitpay.com"; diff --git a/src/js/services/onGoingProcess.js b/src/js/services/onGoingProcess.js index 3248a7be2..dab0a629a 100644 --- a/src/js/services/onGoingProcess.js +++ b/src/js/services/onGoingProcess.js @@ -40,10 +40,10 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti 'sending2faCode': gettext('Sending 2FA code...'), 'buyingBitcoin': gettext('Buying Bitcoin...'), 'sellingBitcoin': gettext('Selling Bitcoin...'), - 'updateGiftCards': gettext('Updating Gift Cards...'), - 'updateGiftCard': gettext('Updating Gift Card...'), - 'cancelGiftCard': gettext('Canceling Gift Card...'), - 'createGiftCard': gettext('Creating Gift Card...') + 'updateGiftCards': 'Updating Gift Cards...', + 'updateGiftCard': 'Updating Gift Card...', + 'cancelGiftCard': 'Canceling Gift Card...', + 'createGiftCard': 'Creating Gift Card...' }; root.clear = function() { From 4d63fc71bd2bb0138314e95780133e3874588409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Fri, 23 Dec 2016 12:10:19 -0300 Subject: [PATCH 3/3] processes names refactor --- src/js/controllers/amazon.js | 6 +++--- src/js/controllers/confirm.js | 4 ++-- src/js/controllers/modals/amazonCardDetails.js | 10 +++++----- src/js/services/onGoingProcess.js | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/js/controllers/amazon.js b/src/js/controllers/amazon.js index 0c6863d9e..df1c8b666 100644 --- a/src/js/controllers/amazon.js +++ b/src/js/controllers/amazon.js @@ -34,11 +34,11 @@ angular.module('copayApp.controllers').controller('amazonController', }; $scope.updatePendingGiftCards = lodash.debounce(function() { - ongoingProcess.set('updateGiftCards', true); + ongoingProcess.set('updatingGiftCards', true); amazonService.getPendingGiftCards(function(err, gcds) { if (lodash.isEmpty(gcds)) { $timeout(function() { - ongoingProcess.set('updateGiftCards', false); + ongoingProcess.set('updatingGiftCards', false); }, 1000); } $timeout(function() { @@ -49,7 +49,7 @@ angular.module('copayApp.controllers').controller('amazonController', lodash.forEach(gcds, function(dataFromStorage) { if (++index == Object.keys(gcds).length) { $timeout(function() { - ongoingProcess.set('updateGiftCards', false); + ongoingProcess.set('updatingGiftCards', false); }, 1000); } if (dataFromStorage.status == 'PENDING') { diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 49fafd5cf..80a46e2b3 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -783,7 +783,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( invoiceUrl: $scope.paypro.url, invoiceTime: giftCardInvoiceTime }; - ongoingProcess.set('createGiftCard', true); + ongoingProcess.set('creatingGiftCard', true); debounceCreate(count, dataSrc, onSendStatusChange); } }, onSendStatusChange); @@ -830,7 +830,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( } amazonService.savePendingGiftCard(newData, null, function(err) { - ongoingProcess.set('createGiftCard', false); + ongoingProcess.set('creatingGiftCard', false); $log.debug("Saving new gift card with status: " + newData.status); $scope.amazonGiftCard = newData; }); diff --git a/src/js/controllers/modals/amazonCardDetails.js b/src/js/controllers/modals/amazonCardDetails.js index fee456e87..af3778fd3 100644 --- a/src/js/controllers/modals/amazonCardDetails.js +++ b/src/js/controllers/modals/amazonCardDetails.js @@ -3,9 +3,9 @@ angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $log, $timeout, $ionicScrollDelegate, bwcError, amazonService, lodash, ongoingProcess, popupService, externalLinkService) { $scope.cancelGiftCard = function() { - ongoingProcess.set('cancelGiftCard', true); + ongoingProcess.set('cancelingGiftCard', true); amazonService.cancelGiftCard($scope.card, function(err, data) { - ongoingProcess.set('cancelGiftCard', false); + ongoingProcess.set('cancelingGiftCard', false); if (err) { popupService.showAlert('Error', bwcError.msg(err)); return; @@ -30,11 +30,11 @@ angular.module('copayApp.controllers').controller('amazonCardDetailsController', }; $scope.refreshGiftCard = function() { - ongoingProcess.set('updateGiftCard', true); + ongoingProcess.set('updatingGiftCard', true); amazonService.getPendingGiftCards(function(err, gcds) { if (lodash.isEmpty(gcds)) { $timeout(function() { - ongoingProcess.set('updateGiftCard', false); + ongoingProcess.set('updatingGiftCard', false); }, 1000); } if (err) { @@ -45,7 +45,7 @@ angular.module('copayApp.controllers').controller('amazonCardDetailsController', lodash.forEach(gcds, function(dataFromStorage) { if (++index == Object.keys(gcds).length) { $timeout(function() { - ongoingProcess.set('updateGiftCard', false); + ongoingProcess.set('updatingGiftCard', false); }, 1000); } if (dataFromStorage.status == 'PENDING' && dataFromStorage.invoiceId == $scope.card.invoiceId) { diff --git a/src/js/services/onGoingProcess.js b/src/js/services/onGoingProcess.js index dab0a629a..5319f9cf5 100644 --- a/src/js/services/onGoingProcess.js +++ b/src/js/services/onGoingProcess.js @@ -40,10 +40,10 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti 'sending2faCode': gettext('Sending 2FA code...'), 'buyingBitcoin': gettext('Buying Bitcoin...'), 'sellingBitcoin': gettext('Selling Bitcoin...'), - 'updateGiftCards': 'Updating Gift Cards...', - 'updateGiftCard': 'Updating Gift Card...', - 'cancelGiftCard': 'Canceling Gift Card...', - 'createGiftCard': 'Creating Gift Card...' + 'updatingGiftCards': 'Updating Gift Cards...', + 'updatingGiftCard': 'Updating Gift Card...', + 'cancelingGiftCard': 'Canceling Gift Card...', + 'creatingGiftCard': 'Creating Gift Card...' }; root.clear = function() {