From e16e93e408cca59e2d590d8617fc46fa332a2560 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 8 Sep 2016 19:50:18 -0300 Subject: [PATCH 1/3] fix sweep paper wallet flag - fix sweep process --- public/views/paperWallet.html | 156 ++++++++++-------- public/views/preferencesAdvanced.html | 4 +- src/js/controllers/backup.js | 5 +- src/js/controllers/paperWallet.js | 24 ++- .../preferencesAdvancedController.js | 10 ++ 5 files changed, 122 insertions(+), 77 deletions(-) create mode 100644 src/js/controllers/preferencesAdvancedController.js diff --git a/public/views/paperWallet.html b/public/views/paperWallet.html index eca39330a..ed1dede89 100644 --- a/public/views/paperWallet.html +++ b/public/views/paperWallet.html @@ -1,84 +1,100 @@ -
-
+ + + {{'Sweep paper wallet' | translate}} + + + + -
-
-
-

-
- - Backup Needed. - - Before receiving funds, you must backup your wallet. If this device is lost, it is impossible to access your funds without a backup. - + +
+
+

+
+ + Backup Needed. + + Before receiving funds, you must backup your wallet. If this device is lost, it is impossible to access your funds without a backup. + +
+
-
-
-
-

-
- {{error|translate}} -
-
-
-
-
- - -
- -
-
-
-
+ + diff --git a/public/views/preferencesAdvanced.html b/public/views/preferencesAdvanced.html index e63d6eb8c..1fcc94c14 100644 --- a/public/views/preferencesAdvanced.html +++ b/public/views/preferencesAdvanced.html @@ -5,7 +5,7 @@ - +
@@ -13,7 +13,7 @@ Wallet Information - + Sweep paper wallet diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index ce0cba754..e2c85231a 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -95,7 +95,10 @@ angular.module('copayApp.controllers').controller('backupController', if (val) { confirmBackupPopup.close(); if ($stateParams.fromOnboarding) $state.go('onboarding.disclaimer'); - else $state.go('tabs.home') + else { + $ionicHistory.clearHistory(); + $state.go('tabs.home'); + } } else { confirmBackupPopup.close(); $scope.goToStep(1); diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js index 6393fdc3f..06560a31b 100644 --- a/src/js/controllers/paperWallet.js +++ b/src/js/controllers/paperWallet.js @@ -1,11 +1,27 @@ angular.module('copayApp.controllers').controller('paperWalletController', - function($scope, $timeout, $log, $ionicModal, $ionicHistory, configService, profileService, $state, addressService, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) { - + function($scope, $timeout, $log, $ionicModal, $ionicHistory, platformInfo, configService, profileService, $state, addressService, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) { var wallet = profileService.getWallet($stateParams.walletId); var rawTx; + $scope.init = function() { + $scope.wallet = wallet; + $scope.isCordova = platformInfo.isCordova; + $scope.needsBackup = wallet.needsBackup; + $scope.walletAlias = wallet.name; + $scope.walletName = wallet.credentials.walletName; + $scope.formData = {}; + $scope.formData.inputData = null; + $scope.scannedKey = null; + $scope.balance = null; + $scope.balanceSat = null; + $scope.scanned = false; + $timeout(function() { + $scope.$apply(); + }, 10); + }; + $scope.onQrCodeScanned = function(data) { - $scope.inputData = data; + $scope.formData.inputData = data; $scope.onData(data); }; @@ -62,6 +78,7 @@ angular.module('copayApp.controllers').controller('paperWalletController', $scope.balanceSat = balance; var config = configService.getSync().wallet.settings; $scope.balance = txFormatService.formatAmount(balance) + ' ' + config.unitName; + $scope.scanned = true; } $scope.$apply(); @@ -125,5 +142,4 @@ angular.module('copayApp.controllers').controller('paperWalletController', $scope.txStatusModal.show(); }); }; - }); diff --git a/src/js/controllers/preferencesAdvancedController.js b/src/js/controllers/preferencesAdvancedController.js new file mode 100644 index 000000000..0af8cf258 --- /dev/null +++ b/src/js/controllers/preferencesAdvancedController.js @@ -0,0 +1,10 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('preferencesAdvancedController', function($scope, $timeout, $stateParams, profileService) { + var wallet = profileService.getWallet($stateParams.walletId); + $scope.network = wallet.network; + + $timeout(function() { + $scope.$apply(); + }, 1); +}); From ee99c0360252c19362a86068ef9b473512c6cb5f Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 8 Sep 2016 19:58:00 -0300 Subject: [PATCH 2/3] handle errors --- src/js/controllers/paperWallet.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js index 06560a31b..64e6b6176 100644 --- a/src/js/controllers/paperWallet.js +++ b/src/js/controllers/paperWallet.js @@ -1,5 +1,5 @@ angular.module('copayApp.controllers').controller('paperWalletController', - function($scope, $timeout, $log, $ionicModal, $ionicHistory, platformInfo, configService, profileService, $state, addressService, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) { + function($scope, $timeout, $log, $ionicModal, $ionicHistory, popupService, gettextCatalog, platformInfo, configService, profileService, $state, addressService, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) { var wallet = profileService.getWallet($stateParams.walletId); var rawTx; @@ -26,7 +26,6 @@ angular.module('copayApp.controllers').controller('paperWalletController', }; $scope.onData = function(data) { - $scope.error = null; $scope.scannedKey = data; $scope.isPkEncrypted = (data.substring(0, 2) == '6P'); }; @@ -64,7 +63,6 @@ angular.module('copayApp.controllers').controller('paperWalletController', $scope.scanFunds = function() { $scope.privateKey = ''; $scope.balanceSat = 0; - $scope.error = null; ongoingProcess.set('scanning', true); $timeout(function() { @@ -72,7 +70,7 @@ angular.module('copayApp.controllers').controller('paperWalletController', ongoingProcess.set('scanning', false); if (err) { $log.error(err); - $scope.error = err.message || err.toString(); + popupService.showAlert(gettextCatalog.getString('Error scanning funds:'), err || err.toString()); } else { $scope.privateKey = privateKey; $scope.balanceSat = balance; @@ -107,15 +105,14 @@ angular.module('copayApp.controllers').controller('paperWalletController', $scope.sweepWallet = function() { ongoingProcess.set('sweepingWallet', true); $scope.sending = true; - $scope.error = null; $timeout(function() { _sweepWallet(function(err, destinationAddress, txid) { ongoingProcess.set('sweepingWallet', false); if (err) { - $scope.error = err.message || err.toString(); $log.error(err); + popupService.showAlert(gettextCatalog.getString('Error sweeping wallet:'), err || err.toString()); } else { var type = walletService.getViewStatus(wallet, txp); $scope.openStatusModal(type, txp, function() { From 1c35cf5e819b4dfb3698e1c8f741eb0457e200ae Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 9 Sep 2016 13:03:58 -0300 Subject: [PATCH 3/3] show status modal after sweep --- src/js/controllers/paperWallet.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js index 64e6b6176..27c784d2f 100644 --- a/src/js/controllers/paperWallet.js +++ b/src/js/controllers/paperWallet.js @@ -1,5 +1,5 @@ angular.module('copayApp.controllers').controller('paperWalletController', - function($scope, $timeout, $log, $ionicModal, $ionicHistory, popupService, gettextCatalog, platformInfo, configService, profileService, $state, addressService, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) { + function($scope, $timeout, $log, $ionicModal, $ionicHistory, popupService, gettextCatalog, platformInfo, configService, profileService, $state, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) { var wallet = profileService.getWallet($stateParams.walletId); var rawTx; @@ -85,7 +85,7 @@ angular.module('copayApp.controllers').controller('paperWalletController', }; function _sweepWallet(cb) { - addressService.getAddress(wallet.credentials.walletId, true, function(err, destinationAddress) { + walletService.getAddress(wallet, true, function(err, destinationAddress) { if (err) return cb(err); wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, tx) { @@ -109,13 +109,12 @@ angular.module('copayApp.controllers').controller('paperWalletController', $timeout(function() { _sweepWallet(function(err, destinationAddress, txid) { ongoingProcess.set('sweepingWallet', false); - + $scope.sending = false; if (err) { $log.error(err); popupService.showAlert(gettextCatalog.getString('Error sweeping wallet:'), err || err.toString()); } else { - var type = walletService.getViewStatus(wallet, txp); - $scope.openStatusModal(type, txp, function() { + $scope.openStatusModal('broadcasted', function() { $ionicHistory.clearHistory(); $state.go('tabs.home'); }); @@ -125,15 +124,15 @@ angular.module('copayApp.controllers').controller('paperWalletController', }, 100); }; - $scope.openStatusModal = function(type, txp, cb) { + $scope.openStatusModal = function(type, cb) { + $scope.tx = {}; + $scope.tx.amountStr = $scope.balance; $scope.type = type; - $scope.tx = txFormatService.processTx(txp); $scope.color = wallet.backgroundColor; $scope.cb = cb; $ionicModal.fromTemplateUrl('views/modals/tx-status.html', { - scope: $scope, - animation: 'slide-in-up' + scope: $scope }).then(function(modal) { $scope.txStatusModal = modal; $scope.txStatusModal.show();