use scope only
This commit is contained in:
parent
c1fd733bfa
commit
761964ea3a
2 changed files with 45 additions and 46 deletions
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue