fix: rename argument for fee discount calculation

This commit is contained in:
José Oliveira 2021-09-24 19:32:42 +01:00
parent 32f79bc450
commit 8c948d08c7

View file

@ -57,25 +57,25 @@ function estimateFee () {
.catch(() => {})
}
function calculateFeeDiscount (feeDiscount) {
function calculateFeeDiscount (feeMultiplier) {
// 0 makes bitcoind do automatic fee selection
const AUTOMATIC_FEE = 0
if (!feeDiscount) return AUTOMATIC_FEE
if (!feeMultiplier) return AUTOMATIC_FEE
return estimateFee()
.then(estimatedFee => {
if (!estimatedFee) return AUTOMATIC_FEE
const newFee = estimatedFee.times(feeDiscount)
const newFee = estimatedFee.times(feeMultiplier)
if (newFee.lt(0.00001) || newFee.gt(0.1)) return AUTOMATIC_FEE
return newFee
})
}
function sendCoins (account, tx, settings, operatorId, feeDiscount) {
function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
const { toAddress, cryptoAtoms, cryptoCode } = tx
const coins = cryptoAtoms.shiftedBy(-unitScale).toFixed(8)
return checkCryptoCode(cryptoCode)
.then(() => calculateFeeDiscount(feeDiscount))
.then(() => calculateFeeDiscount(feeMultiplier))
.then(newFee => fetch('settxfee', [newFee]))
.then(() => fetch('sendtoaddress', [toAddress, coins]))
.then((txId) => fetch('gettransaction', [txId]))