Fix feeRate, sendMax

This commit is contained in:
Gustavo Maximiliano Cortez 2017-08-28 17:17:32 -03:00
commit ac5a5a9bdc
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
7 changed files with 13 additions and 17 deletions

View file

@ -18,14 +18,14 @@ angular.module('copayApp.controllers').controller('feeLevelsController', functio
var value = lodash.find($scope.feeLevels[$scope.network], { var value = lodash.find($scope.feeLevels[$scope.network], {
level: 'superEconomy' level: 'superEconomy'
}); });
return parseInt((value.feePerKB / 1000).toFixed()); return parseInt((value.feePerKb / 1000).toFixed());
}; };
var getMaxRecommended = function() { var getMaxRecommended = function() {
var value = lodash.find($scope.feeLevels[$scope.network], { var value = lodash.find($scope.feeLevels[$scope.network], {
level: 'urgent' level: 'urgent'
}); });
return parseInt((value.feePerKB / 1000).toFixed()); return parseInt((value.feePerKb / 1000).toFixed());
}; };
$scope.ok = function() { $scope.ok = function() {
@ -61,7 +61,7 @@ angular.module('copayApp.controllers').controller('feeLevelsController', functio
// If no custom fee // If no custom fee
if (value) { if (value) {
$scope.customFeePerKB = null; $scope.customFeePerKB = null;
$scope.feePerSatByte = (value.feePerKB / 1000).toFixed(); $scope.feePerSatByte = (value.feePerKb / 1000).toFixed();
$scope.avgConfirmationTime = value.nbBlocks * 10; $scope.avgConfirmationTime = value.nbBlocks * 10;
} else { } else {
$scope.avgConfirmationTime = null; $scope.avgConfirmationTime = null;

View file

@ -59,9 +59,9 @@ angular.module('copayApp.controllers').controller('paperWalletController',
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, testTx) { $scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, testTx) {
if (err) return cb(err); if (err) return cb(err);
var rawTxLength = testTx.serialize().length; var rawTxLength = testTx.serialize().length;
feeService.getCurrentFeeRate('livenet', function(err, feePerKB) { feeService.getCurrentFeeRate('livenet', function(err, feePerKb) {
var opts = {}; var opts = {};
opts.fee = Math.round((feePerKB * rawTxLength) / 2000); opts.fee = Math.round((feePerKb * rawTxLength) / 2000);
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, opts, function(err, tx) { $scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, opts, function(err, tx) {
if (err) return cb(err); if (err) return cb(err);
$scope.wallet.broadcastRawTx({ $scope.wallet.broadcastRawTx({

View file

@ -66,7 +66,7 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
return; return;
} }
$scope.feePerSatByte = (value.feePerKB / 1000).toFixed(); $scope.feePerSatByte = (value.feePerKb / 1000).toFixed();
$scope.avgConfirmationTime = value.nbBlocks * 10; $scope.avgConfirmationTime = value.nbBlocks * 10;
$scope.invalidCustomFeeEntered = false; $scope.invalidCustomFeeEntered = false;
setMinWarning(); setMinWarning();
@ -97,7 +97,7 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
var value = lodash.find($scope.feeLevels[$scope.network], { var value = lodash.find($scope.feeLevels[$scope.network], {
level: 'superEconomy' level: 'superEconomy'
}); });
return parseInt((value.feePerKB / 1000).toFixed()); return parseInt((value.feePerKb / 1000).toFixed());
}; };
var setMinWarning = function() { var setMinWarning = function() {

View file

@ -170,9 +170,9 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
var _getNetAmount = function(amount, cb) { var _getNetAmount = function(amount, cb) {
// Fee Normal for a single transaction (450 bytes) // Fee Normal for a single transaction (450 bytes)
var txNormalFeeKB = 450 / 1000; var txNormalFeeKB = 450 / 1000;
feeService.getFeeRate(null, 'normal', function(err, feePerKB) { feeService.getFeeRate(null, 'normal', function(err, feePerKb) {
if (err) return cb(err); if (err) return cb(err);
var feeBTC = (feePerKB * txNormalFeeKB / 100000000).toFixed(8); var feeBTC = (feePerKb * txNormalFeeKB / 100000000).toFixed(8);
return cb(null, amount - feeBTC, feeBTC); return cb(null, amount - feeBTC, feeBTC);
}); });

View file

@ -37,7 +37,7 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
level: feeLevel level: feeLevel
}); });
if (!feeLevelRate || !feeLevelRate.feePerKB) { if (!feeLevelRate || !feeLevelRate.feePerKb) {
return cb({ return cb({
message: gettextCatalog.getString("Could not get dynamic fee for level: {{feeLevel}}", { message: gettextCatalog.getString("Could not get dynamic fee for level: {{feeLevel}}", {
feeLevel: feeLevel feeLevel: feeLevel
@ -45,9 +45,9 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
}); });
} }
var feeRate = feeLevelRate.feePerKB; var feeRate = feeLevelRate.feePerKb;
if (!fromCache) $log.debug('Dynamic fee: ' + feeLevel + '/' + network + ' ' + (feeLevelRate.feePerKB / 1000).toFixed() + ' SAT/B'); if (!fromCache) $log.debug('Dynamic fee: ' + feeLevel + '/' + network + ' ' + (feeLevelRate.feePerKb / 1000).toFixed() + ' SAT/B');
return cb(null, feeRate); return cb(null, feeRate);
}); });

View file

@ -90,10 +90,6 @@ angular.module('copayApp.services')
wallet.m = wallet.credentials.m; wallet.m = wallet.credentials.m;
wallet.n = wallet.credentials.n; wallet.n = wallet.credentials.n;
wallet.coin = wallet.credentials.coin ? wallet.credentials.coin : 'btc'; wallet.coin = wallet.credentials.coin ? wallet.credentials.coin : 'btc';
console.log('[profileService.js:92]',wallet); //TODO/
// TODO: Should return "coin" = "btc" or "bch"
//client.credentials.coin = 'btc';
root.updateWalletSettings(wallet); root.updateWalletSettings(wallet);
root.wallet[walletId] = wallet; root.wallet[walletId] = wallet;

View file

@ -922,7 +922,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.getMinFee = function(wallet, feeLevels, nbOutputs) { root.getMinFee = function(wallet, feeLevels, nbOutputs) {
var lowLevelRate = (lodash.find(feeLevels[wallet.network], { var lowLevelRate = (lodash.find(feeLevels[wallet.network], {
level: 'normal', level: 'normal',
}).feePerKB / 1000).toFixed(0); }).feePerKb / 1000).toFixed(0);
var size = root.getEstimatedTxSize(wallet, nbOutputs); var size = root.getEstimatedTxSize(wallet, nbOutputs);
return size * lowLevelRate; return size * lowLevelRate;