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 { | import { | ||||
toSmallestDenomination, | toSmallestDenomination, | ||||
batchArray, | batchArray, | ||||
flattenBatchedHydratedUtxos, | flattenBatchedHydratedUtxos, | ||||
} from '@utils/cashMethods'; | } from '@utils/cashMethods'; | ||||
export default function useBCH() { | export default function useBCH() { | ||||
▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | const getHydratedUtxoDetails = async (BCH, utxos) => { | ||||
const batchedUtxos = batchArray( | const batchedUtxos = batchArray( | ||||
theseUtxos, | theseUtxos, | ||||
currency.hydrateUtxoBatchSize, | currency.hydrateUtxoBatchSize, | ||||
); | ); | ||||
// Iterate over each utxo in this address field | // Iterate over each utxo in this address field | ||||
for (let j = 0; j < batchedUtxos.length; j += 1) { | for (let j = 0; j < batchedUtxos.length; j += 1) { | ||||
const utxoSetForThisPromise = [ | const utxoSetForThisPromise = [ | ||||
{ utxos: batchedUtxos[j], address: thisAddress }, | { | ||||
utxos: batchedUtxos[j], | |||||
address: thisAddress, | |||||
}, | |||||
]; | ]; | ||||
const thisPromise = BCH.SLP.Utils.hydrateUtxos( | const thisPromise = BCH.SLP.Utils.hydrateUtxos( | ||||
utxoSetForThisPromise, | utxoSetForThisPromise, | ||||
); | ); | ||||
hydrateUtxosPromises.push(thisPromise); | hydrateUtxosPromises.push(thisPromise); | ||||
} | } | ||||
} | } | ||||
let hydratedUtxoDetails; | let hydratedUtxoDetails; | ||||
▲ Show 20 Lines • Show All 489 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) => { | const getBCH = (apiIndex = 0, fromWindowObject = true) => { | ||||
let ConstructedSlpWallet; | if (fromWindowObject && window.SlpWallet) { | ||||
const SlpWallet = new window.SlpWallet('', { | |||||
ConstructedSlpWallet = new SlpWallet('', { | |||||
restURL: getRestUrl(apiIndex), | restURL: getRestUrl(apiIndex), | ||||
}); | }); | ||||
return ConstructedSlpWallet.bchjs; | return SlpWallet.bchjs; | ||||
} | |||||
}; | }; | ||||
return { | return { | ||||
getBCH, | getBCH, | ||||
calcFee, | calcFee, | ||||
getUtxos, | getUtxos, | ||||
getHydratedUtxoDetails, | getHydratedUtxoDetails, | ||||
getSlpBalancesAndUtxos, | getSlpBalancesAndUtxos, | ||||
Show All 11 Lines |