Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useBCH.js
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
import { currency } from '@components/Common/Ticker'; | import { currency } from '@components/Common/Ticker'; | ||||
import SlpWallet from 'minimal-slp-wallet'; | import SlpWallet from 'minimal-slp-wallet'; | ||||
export default function useBCH() { | export default function useBCH() { | ||||
const DUST = 0.000005; | |||||
const SEND_BCH_ERRORS = { | const SEND_BCH_ERRORS = { | ||||
INSUFICIENT_FUNDS: 0, | INSUFICIENT_FUNDS: 0, | ||||
NETWORK_ERROR: 1, | NETWORK_ERROR: 1, | ||||
INSUFFICIENT_PRIORITY: 66, // ~insufficient fee | INSUFFICIENT_PRIORITY: 66, // ~insufficient fee | ||||
DOUBLE_SPENDING: 18, | DOUBLE_SPENDING: 18, | ||||
MAX_UNCONFIRMED_TXS: 64, | MAX_UNCONFIRMED_TXS: 64, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 475 Lines • ▼ Show 20 Lines | ) => { | ||||
for (let i = 0; i < addresses.length; i++) { | for (let i = 0; i < addresses.length; i++) { | ||||
const address = addresses[i]; | const address = addresses[i]; | ||||
transactionBuilder.addOutput( | transactionBuilder.addOutput( | ||||
BCH.Address.toCashAddress(address), | BCH.Address.toCashAddress(address), | ||||
BCH.BitcoinCash.toSatoshi(Number(values[i]).toFixed(8)), | BCH.BitcoinCash.toSatoshi(Number(values[i]).toFixed(8)), | ||||
); | ); | ||||
} | } | ||||
if (remainder >= BCH.BitcoinCash.toSatoshi(DUST)) { | if ( | ||||
remainder >= | |||||
BCH.BitcoinCash.toSatoshi( | |||||
parseFloat(new BigNumber(currency.dust).toFixed(8)), | |||||
) | |||||
) { | |||||
transactionBuilder.addOutput(REMAINDER_ADDR, remainder); | transactionBuilder.addOutput(REMAINDER_ADDR, remainder); | ||||
} | } | ||||
// Sign the transactions with the HD node. | // Sign the transactions with the HD node. | ||||
for (let i = 0; i < inputUtxos.length; i++) { | for (let i = 0; i < inputUtxos.length; i++) { | ||||
const utxo = inputUtxos[i]; | const utxo = inputUtxos[i]; | ||||
transactionBuilder.sign( | transactionBuilder.sign( | ||||
i, | i, | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |