use scope only
This commit is contained in:
parent
c1fd733bfa
commit
761964ea3a
2 changed files with 45 additions and 46 deletions
|
|
@ -4,21 +4,21 @@
|
|||
ng-init="titleSection='Sweep paper wallet'; goBackToState = 'preferencesAdvanced';">
|
||||
</div>
|
||||
|
||||
<div class="content preferences" ng-controller="paperWalletController as paperWallet">
|
||||
<h4 ng-show="!paperWallet.error"></h4>
|
||||
<div class="box-notification m20b" ng-show="paperWallet.error">
|
||||
<span class="text-warning">{{paperWallet.error|translate}}</span>
|
||||
<div class="content preferences" ng-controller="paperWalletController">
|
||||
<h4 ng-show="!error"></h4>
|
||||
<div class="box-notification m20b" ng-show="error">
|
||||
<span class="text-warning">{{error|translate}}</span>
|
||||
</div>
|
||||
<form ng-show="!paperWallet.balance" class="oh">
|
||||
<form ng-show="!balance" class="oh">
|
||||
<div class="row">
|
||||
<div class="large-12 medium-12 columns">
|
||||
<div class="input">
|
||||
<label for="inputData" translate>Paper Wallet Private Key</label>
|
||||
<input type="text" placeholder="{{'Paste your paper wallet private key here'|translate}}" ng-model="inputData" id="inputData" ng-change="paperWallet.onData(inputData)">
|
||||
<input type="text" placeholder="{{'Paste your paper wallet private key here'|translate}}" ng-model="inputData" id="inputData" ng-change="onData(inputData)">
|
||||
<div class="qr-scanner-input">
|
||||
<qr-scanner on-scan="paperWallet.onQrCodeScanned(data)"></qr-scanner>
|
||||
<qr-scanner on-scan="onQrCodeScanned(data)"></qr-scanner>
|
||||
</div>
|
||||
<div ng-show="paperWallet.isPkEncrypted">
|
||||
<div ng-show="isPkEncrypted">
|
||||
<label for="passphrase">
|
||||
<span translate>Password</span>
|
||||
</label>
|
||||
|
|
@ -28,30 +28,30 @@
|
|||
</p>
|
||||
</div>
|
||||
<button
|
||||
ng-disabled="paperWallet.scanning || !paperWallet.scannedKey"
|
||||
ng-disabled="scanning || !scannedKey"
|
||||
ng-style="{'background-color':index.backgroundColor}"
|
||||
class="button black round expand"
|
||||
ng-click="paperWallet.scanFunds()"
|
||||
ng-click="scanFunds()"
|
||||
translate>Scan Wallet Funds
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div ng-show="paperWallet.balance" class="row">
|
||||
<div ng-show="balance" class="row">
|
||||
<div class="large-12 medium-12 columns">
|
||||
<div class="text-center m20b">
|
||||
<h4 class="text-bold" translate>Funds found</h4>
|
||||
<div class="size-24">
|
||||
{{paperWallet.balance}}
|
||||
{{balance}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
ng-disabled="paperWallet.sending || paperWallet.balanceSat <= 0"
|
||||
ng-disabled="sending || balanceSat <= 0"
|
||||
ng-style="{'background-color':index.backgroundColor}"
|
||||
class="button black round expand"
|
||||
ng-click="paperWallet.sweepWallet()"
|
||||
ng-click="sweepWallet()"
|
||||
translate>Sweep Wallet
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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