diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js index b1541ce5a..32e584e8b 100644 --- a/src/js/controllers/paperWallet.js +++ b/src/js/controllers/paperWallet.js @@ -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); + }); + }); }); }); }); diff --git a/src/js/services/feeService.js b/src/js/services/feeService.js index 5142edf66..be1a57160 100644 --- a/src/js/services/feeService.js +++ b/src/js/services/feeService.js @@ -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) {