Merge pull request #5107 from gabrielbazan7/fix/sweepPaper01

Calculate fee level when sweeping paper wallet
This commit is contained in:
Javier Donadío 2016-11-25 11:06:39 -03:00 committed by GitHub
commit 93b759ffca
2 changed files with 17 additions and 13 deletions

View file

@ -1,5 +1,5 @@
angular.module('copayApp.controllers').controller('paperWalletController',
function($scope, $timeout, $log, $ionicModal, $ionicHistory, popupService, gettextCatalog, platformInfo, configService, profileService, $state, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) {
function($scope, $timeout, $log, $ionicModal, $ionicHistory, feeService, popupService, gettextCatalog, platformInfo, configService, profileService, $state, bitcore, ongoingProcess, txFormatService, $stateParams, walletService) {
function _scanFunds(cb) {
function getPrivateKey(scannedKey, isPkEncrypted, passphrase, cb) {
@ -57,15 +57,22 @@ angular.module('copayApp.controllers').controller('paperWalletController',
walletService.getAddress($scope.wallet, true, function(err, destinationAddress) {
if (err) return cb(err);
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, tx) {
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, testTx) {
if (err) return cb(err);
$scope.wallet.broadcastRawTx({
rawTx: tx.serialize(),
network: 'livenet'
}, function(err, txid) {
if (err) return cb(err);
return cb(null, destinationAddress, txid);
var rawTxLength = testTx.serialize().length;
feeService.getCurrentFeeValue($scope.wallet, function(err, feePerKB) {
var opts = {};
opts.fee = Math.round((feePerKB * rawTxLength) / 2000);
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, opts, function(err, tx) {
if (err) return cb(err);
$scope.wallet.broadcastRawTx({
rawTx: tx.serialize(),
network: 'livenet'
}, function(err, txid) {
if (err) return cb(err);
return cb(null, destinationAddress, txid);
});
});
});
});
});

View file

@ -15,10 +15,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $stateP
return configService.getSync().wallet.settings.feeLevel || 'normal';
};
root.getCurrentFeeValue = function(cb) {
console.log('[feeService.js.18:getCurrentFeeValue:] TODO TODO TODO'); //TODO
// TODO TODO TODO
var wallet = profileService.getWallet($stateParams.walletId);
root.getCurrentFeeValue = function(wallet, cb) {
var feeLevel = root.getCurrentFeeLevel();
wallet.getFeeLevels(wallet.credentials.network, function(err, levels) {