From 761964ea3ae907328a091d8cd45ecfe21370e2bc Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 16 Jun 2016 16:06:43 -0300 Subject: [PATCH] use scope only --- public/views/paperWallet.html | 28 +++++++------- src/js/controllers/paperWallet.js | 63 +++++++++++++++---------------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/public/views/paperWallet.html b/public/views/paperWallet.html index 630f9a066..fa6f83c96 100644 --- a/public/views/paperWallet.html +++ b/public/views/paperWallet.html @@ -4,21 +4,21 @@ ng-init="titleSection='Sweep paper wallet'; goBackToState = 'preferencesAdvanced';"> -
-

-
- {{paperWallet.error|translate}} +
+

+
+ {{error|translate}}
-
+
- +
- +
-
+
@@ -28,30 +28,30 @@

-
+

Funds found

- {{paperWallet.balance}} + {{balance}}
diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js index e0f7c143f..c5f244608 100644 --- a/src/js/controllers/paperWallet.js +++ b/src/js/controllers/paperWallet.js @@ -1,21 +1,20 @@ angular.module('copayApp.controllers').controller('paperWalletController', - function($scope, $http, $timeout, $log, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess) { - var self = this; + function($scope, $timeout, $log, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess) { var fc = profileService.focusedClient; var rawTx; - self.onQrCodeScanned = function(data) { + $scope.onQrCodeScanned = function(data) { $scope.inputData = data; - self.onData(data); - } + $scope.onData(data); + }; - self.onData = function(data) { - self.error = ''; - self.scannedKey = data; - self.isPkEncrypted = (data.substring(0,2) == '6P'); - } + $scope.onData = function(data) { + $scope.error = null; + $scope.scannedKey = data; + $scope.isPkEncrypted = (data.substring(0, 2) == '6P'); + }; - self._scanFunds = function(cb) { + function _scanFunds(cb) { function getPrivateKey(scannedKey, isPkEncrypted, passphrase, cb) { if (!isPkEncrypted) return cb(null, scannedKey); fc.decryptBIP38PrivateKey(scannedKey, passphrase, null, cb); @@ -32,9 +31,9 @@ angular.module('copayApp.controllers').controller('paperWalletController', return false; } return true; - } + }; - getPrivateKey(self.scannedKey, self.isPkEncrypted, $scope.passphrase, function(err, privateKey) { + getPrivateKey($scope.scannedKey, $scope.isPkEncrypted, $scope.passphrase, function(err, privateKey) { if (err) return cb(err); if (!checkPrivateKey(privateKey)) return cb(new Error('Invalid private key')); @@ -43,37 +42,37 @@ angular.module('copayApp.controllers').controller('paperWalletController', return cb(null, privateKey, balance); }); }); - } + }; - self.scanFunds = function() { - self.privateKey = ''; - self.balanceSat = 0; - self.error = ''; + $scope.scanFunds = function() { + $scope.privateKey = ''; + $scope.balanceSat = 0; + $scope.error = null; ongoingProcess.set('scanning', true); $timeout(function() { - self._scanFunds(function(err, privateKey, balance) { + _scanFunds(function(err, privateKey, balance) { ongoingProcess.set('scanning', false); if (err) { $log.error(err); - self.error = err.message || err.toString(); + $scope.error = err.message || err.toString(); } else { - self.privateKey = privateKey; - self.balanceSat = balance; + $scope.privateKey = privateKey; + $scope.balanceSat = balance; var config = configService.getSync().wallet.settings; - self.balance = profileService.formatAmount(balance) + ' ' + config.unitName; + $scope.balance = profileService.formatAmount(balance) + ' ' + config.unitName; } $scope.$apply(); }); }, 100); - } + }; - self._sweepWallet = function(cb) { + function _sweepWallet(cb) { addressService.getAddress(fc.credentials.walletId, true, function(err, destinationAddress) { if (err) return cb(err); - fc.buildTxFromPrivateKey(self.privateKey, destinationAddress, null, function(err, tx) { + fc.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, tx) { if (err) return cb(err); fc.broadcastRawTx({ @@ -87,17 +86,17 @@ angular.module('copayApp.controllers').controller('paperWalletController', }); }; - self.sweepWallet = function() { + $scope.sweepWallet = function() { ongoingProcess.set('sweepingWallet', true); - self.sending = true; - self.error = ''; + $scope.sending = true; + $scope.error = null; $timeout(function() { - self._sweepWallet(function(err, destinationAddress, txid) { + _sweepWallet(function(err, destinationAddress, txid) { ongoingProcess.set('sweepingWallet', false); if (err) { - self.error = err.message || err.toString(); + $scope.error = err.message || err.toString(); $log.error(err); } else { txStatus.notify({ @@ -110,5 +109,5 @@ angular.module('copayApp.controllers').controller('paperWalletController', $scope.$apply(); }); }, 100); - } + }; });