Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useBCH.js
Show First 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | ) => { | ||||
return link; | return link; | ||||
}; | }; | ||||
const sendBch = async ( | const sendBch = async ( | ||||
BCH, | BCH, | ||||
wallet, | wallet, | ||||
utxos, | utxos, | ||||
{ addresses, values, encodedOpReturn }, | { addresses, values, encodedOpReturn }, | ||||
feeInSatsPerByte, | |||||
callbackTxId, | callbackTxId, | ||||
) => { | ) => { | ||||
// Note: callbackTxId is a callback function that accepts a txid as its only parameter | // Note: callbackTxId is a callback function that accepts a txid as its only parameter | ||||
try { | try { | ||||
if (!values || values.length === 0) { | if (!values || values.length === 0) { | ||||
return null; | return null; | ||||
} | } | ||||
Show All 25 Lines | ) => { | ||||
originalAmount = originalAmount.plus(utxo.value); | originalAmount = originalAmount.plus(utxo.value); | ||||
const vout = utxo.vout; | const vout = utxo.vout; | ||||
const txid = utxo.txid; | const txid = utxo.txid; | ||||
// add input with txid and index of vout | // add input with txid and index of vout | ||||
transactionBuilder.addInput(txid, vout); | transactionBuilder.addInput(txid, vout); | ||||
inputUtxos.push(utxo); | inputUtxos.push(utxo); | ||||
txFee = encodedOpReturn | txFee = encodedOpReturn | ||||
? calcFee(BCH, inputUtxos, addresses.length + 2) | ? calcFee( | ||||
: calcFee(BCH, inputUtxos, addresses.length + 1); | BCH, | ||||
inputUtxos, | |||||
addresses.length + 2, | |||||
feeInSatsPerByte, | |||||
) | |||||
: calcFee( | |||||
BCH, | |||||
inputUtxos, | |||||
addresses.length + 1, | |||||
feeInSatsPerByte, | |||||
); | |||||
if (originalAmount.minus(satoshisToSend).minus(txFee).gte(0)) { | if (originalAmount.minus(satoshisToSend).minus(txFee).gte(0)) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// amount to send back to the remainder address. | // amount to send back to the remainder address. | ||||
const remainder = Math.floor( | const remainder = Math.floor( | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |