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'; | |||||
export default function useBCH() { | export default function useBCH() { | ||||
const DUST = 0.000005; | 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, | ||||
▲ Show 20 Lines • Show All 517 Lines • ▼ Show 20 Lines | ) => { | ||||
) { | ) { | ||||
err.code = SEND_BCH_ERRORS.MAX_UNCONFIRMED_TXS; | err.code = SEND_BCH_ERRORS.MAX_UNCONFIRMED_TXS; | ||||
} | } | ||||
console.log(`error: `, err); | console.log(`error: `, err); | ||||
throw err; | throw err; | ||||
} | } | ||||
}; | }; | ||||
const getBCH = (apiIndex = 0, fromWindowObject = true) => { | const getBCH = (apiIndex = 0) => { | ||||
if (fromWindowObject && window.SlpWallet) { | let ConstructedSlpWallet; | ||||
const SlpWallet = new window.SlpWallet('', { | |||||
ConstructedSlpWallet = new SlpWallet('', { | |||||
restURL: getRestUrl(apiIndex), | restURL: getRestUrl(apiIndex), | ||||
}); | }); | ||||
return SlpWallet.bchjs; | return ConstructedSlpWallet.bchjs; | ||||
} | |||||
}; | }; | ||||
return { | return { | ||||
getBCH, | getBCH, | ||||
calcFee, | calcFee, | ||||
getUtxos, | getUtxos, | ||||
getSlpBalancesAndUtxos, | getSlpBalancesAndUtxos, | ||||
getTxHistory, | getTxHistory, | ||||
getRestUrl, | getRestUrl, | ||||
sendBch, | sendBch, | ||||
sendToken, | sendToken, | ||||
}; | }; | ||||
} | } |