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';">
|
ng-init="titleSection='Sweep paper wallet'; goBackToState = 'preferencesAdvanced';">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content preferences" ng-controller="paperWalletController as paperWallet">
|
<div class="content preferences" ng-controller="paperWalletController">
|
||||||
<h4 ng-show="!paperWallet.error"></h4>
|
<h4 ng-show="!error"></h4>
|
||||||
<div class="box-notification m20b" ng-show="paperWallet.error">
|
<div class="box-notification m20b" ng-show="error">
|
||||||
<span class="text-warning">{{paperWallet.error|translate}}</span>
|
<span class="text-warning">{{error|translate}}</span>
|
||||||
</div>
|
</div>
|
||||||
<form ng-show="!paperWallet.balance" class="oh">
|
<form ng-show="!balance" class="oh">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-12 medium-12 columns">
|
<div class="large-12 medium-12 columns">
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<label for="inputData" translate>Paper Wallet Private Key</label>
|
<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">
|
<div class="qr-scanner-input">
|
||||||
<qr-scanner on-scan="paperWallet.onQrCodeScanned(data)"></qr-scanner>
|
<qr-scanner on-scan="onQrCodeScanned(data)"></qr-scanner>
|
||||||
</div>
|
</div>
|
||||||
<div ng-show="paperWallet.isPkEncrypted">
|
<div ng-show="isPkEncrypted">
|
||||||
<label for="passphrase">
|
<label for="passphrase">
|
||||||
<span translate>Password</span>
|
<span translate>Password</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
@ -28,30 +28,30 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
ng-disabled="paperWallet.scanning || !paperWallet.scannedKey"
|
ng-disabled="scanning || !scannedKey"
|
||||||
ng-style="{'background-color':index.backgroundColor}"
|
ng-style="{'background-color':index.backgroundColor}"
|
||||||
class="button black round expand"
|
class="button black round expand"
|
||||||
ng-click="paperWallet.scanFunds()"
|
ng-click="scanFunds()"
|
||||||
translate>Scan Wallet Funds
|
translate>Scan Wallet Funds
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div ng-show="paperWallet.balance" class="row">
|
<div ng-show="balance" class="row">
|
||||||
<div class="large-12 medium-12 columns">
|
<div class="large-12 medium-12 columns">
|
||||||
<div class="text-center m20b">
|
<div class="text-center m20b">
|
||||||
<h4 class="text-bold" translate>Funds found</h4>
|
<h4 class="text-bold" translate>Funds found</h4>
|
||||||
<div class="size-24">
|
<div class="size-24">
|
||||||
{{paperWallet.balance}}
|
{{balance}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
ng-disabled="paperWallet.sending || paperWallet.balanceSat <= 0"
|
ng-disabled="sending || balanceSat <= 0"
|
||||||
ng-style="{'background-color':index.backgroundColor}"
|
ng-style="{'background-color':index.backgroundColor}"
|
||||||
class="button black round expand"
|
class="button black round expand"
|
||||||
ng-click="paperWallet.sweepWallet()"
|
ng-click="sweepWallet()"
|
||||||
translate>Sweep Wallet
|
translate>Sweep Wallet
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,20 @@
|
||||||
angular.module('copayApp.controllers').controller('paperWalletController',
|
angular.module('copayApp.controllers').controller('paperWalletController',
|
||||||
function($scope, $http, $timeout, $log, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess) {
|
function($scope, $timeout, $log, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess) {
|
||||||
var self = this;
|
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
var rawTx;
|
var rawTx;
|
||||||
|
|
||||||
self.onQrCodeScanned = function(data) {
|
$scope.onQrCodeScanned = function(data) {
|
||||||
$scope.inputData = data;
|
$scope.inputData = data;
|
||||||
self.onData(data);
|
$scope.onData(data);
|
||||||
}
|
};
|
||||||
|
|
||||||
self.onData = function(data) {
|
$scope.onData = function(data) {
|
||||||
self.error = '';
|
$scope.error = null;
|
||||||
self.scannedKey = data;
|
$scope.scannedKey = data;
|
||||||
self.isPkEncrypted = (data.substring(0,2) == '6P');
|
$scope.isPkEncrypted = (data.substring(0, 2) == '6P');
|
||||||
}
|
};
|
||||||
|
|
||||||
self._scanFunds = function(cb) {
|
function _scanFunds(cb) {
|
||||||
function getPrivateKey(scannedKey, isPkEncrypted, passphrase, cb) {
|
function getPrivateKey(scannedKey, isPkEncrypted, passphrase, cb) {
|
||||||
if (!isPkEncrypted) return cb(null, scannedKey);
|
if (!isPkEncrypted) return cb(null, scannedKey);
|
||||||
fc.decryptBIP38PrivateKey(scannedKey, passphrase, null, cb);
|
fc.decryptBIP38PrivateKey(scannedKey, passphrase, null, cb);
|
||||||
|
|
@ -32,9 +31,9 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
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 (err) return cb(err);
|
||||||
if (!checkPrivateKey(privateKey)) return cb(new Error('Invalid private key'));
|
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);
|
return cb(null, privateKey, balance);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
self.scanFunds = function() {
|
$scope.scanFunds = function() {
|
||||||
self.privateKey = '';
|
$scope.privateKey = '';
|
||||||
self.balanceSat = 0;
|
$scope.balanceSat = 0;
|
||||||
self.error = '';
|
$scope.error = null;
|
||||||
|
|
||||||
ongoingProcess.set('scanning', true);
|
ongoingProcess.set('scanning', true);
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
self._scanFunds(function(err, privateKey, balance) {
|
_scanFunds(function(err, privateKey, balance) {
|
||||||
ongoingProcess.set('scanning', false);
|
ongoingProcess.set('scanning', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.error(err);
|
$log.error(err);
|
||||||
self.error = err.message || err.toString();
|
$scope.error = err.message || err.toString();
|
||||||
} else {
|
} else {
|
||||||
self.privateKey = privateKey;
|
$scope.privateKey = privateKey;
|
||||||
self.balanceSat = balance;
|
$scope.balanceSat = balance;
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
self.balance = profileService.formatAmount(balance) + ' ' + config.unitName;
|
$scope.balance = profileService.formatAmount(balance) + ' ' + config.unitName;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
};
|
||||||
|
|
||||||
self._sweepWallet = function(cb) {
|
function _sweepWallet(cb) {
|
||||||
addressService.getAddress(fc.credentials.walletId, true, function(err, destinationAddress) {
|
addressService.getAddress(fc.credentials.walletId, true, function(err, destinationAddress) {
|
||||||
if (err) return cb(err);
|
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);
|
if (err) return cb(err);
|
||||||
|
|
||||||
fc.broadcastRawTx({
|
fc.broadcastRawTx({
|
||||||
|
|
@ -87,17 +86,17 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.sweepWallet = function() {
|
$scope.sweepWallet = function() {
|
||||||
ongoingProcess.set('sweepingWallet', true);
|
ongoingProcess.set('sweepingWallet', true);
|
||||||
self.sending = true;
|
$scope.sending = true;
|
||||||
self.error = '';
|
$scope.error = null;
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
self._sweepWallet(function(err, destinationAddress, txid) {
|
_sweepWallet(function(err, destinationAddress, txid) {
|
||||||
ongoingProcess.set('sweepingWallet', false);
|
ongoingProcess.set('sweepingWallet', false);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err.message || err.toString();
|
$scope.error = err.message || err.toString();
|
||||||
$log.error(err);
|
$log.error(err);
|
||||||
} else {
|
} else {
|
||||||
txStatus.notify({
|
txStatus.notify({
|
||||||
|
|
@ -110,5 +109,5 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue