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 SEND_BCH_ERRORS = { | const SEND_BCH_ERRORS = { | ||||
INSUFICIENT_FUNDS: 0, | INSUFFICIENT_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, | ||||
}; | }; | ||||
const getRestUrl = (apiIndex = 0) => { | const getRestUrl = (apiIndex = 0) => { | ||||
const apiString = | const apiString = | ||||
▲ Show 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | ) => { | ||||
} | } | ||||
// amount to send back to the remainder address. | // amount to send back to the remainder address. | ||||
const remainder = Math.floor( | const remainder = Math.floor( | ||||
originalAmount.minus(satoshisToSend).minus(txFee), | originalAmount.minus(satoshisToSend).minus(txFee), | ||||
); | ); | ||||
if (remainder < 0) { | if (remainder < 0) { | ||||
const error = new Error(`Insufficient funds`); | const error = new Error(`Insufficient funds`); | ||||
error.code = SEND_BCH_ERRORS.INSUFICIENT_FUNDS; | error.code = SEND_BCH_ERRORS.INSUFFICIENT_FUNDS; | ||||
throw error; | throw error; | ||||
} | } | ||||
if (encodedOpReturn) { | if (encodedOpReturn) { | ||||
transactionBuilder.addOutput(encodedOpReturn, 0); | transactionBuilder.addOutput(encodedOpReturn, 0); | ||||
} | } | ||||
// add output w/ address and amount to send | // add output w/ address and amount to send | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |