Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useBCH.js
Show First 20 Lines • Show All 310 Lines • ▼ Show 20 Lines | const getUtxos = async (BCH, addresses) => { | ||||
//console.log(`BCH.Electrumx.utxo(addresses) succeeded`); | //console.log(`BCH.Electrumx.utxo(addresses) succeeded`); | ||||
//console.log(`utxosResponse`, utxosResponse); | //console.log(`utxosResponse`, utxosResponse); | ||||
return utxosResponse.utxos; | return utxosResponse.utxos; | ||||
} catch (err) { | } catch (err) { | ||||
console.log(`Error in BCH.Electrumx.utxo(addresses):`); | console.log(`Error in BCH.Electrumx.utxo(addresses):`); | ||||
return err; | return err; | ||||
} | } | ||||
}; | }; | ||||
const hydrateParsedChangedUtxos = async ( | |||||
hydratedUtxoDetails, | |||||
parsedChangedUtxos, | |||||
) => { | |||||
// Accept array of utxos that have changed and must be hydrated from parseChangedUtxos from cashMethods.js and existing hydratedUtxoDetails | |||||
// Return updated full hydratedUtxo details | |||||
/* | |||||
const hydratedUtxoDetails = await getHydratedUtxoDetails( | |||||
BCH, | |||||
utxos, | |||||
); | |||||
const slpBalancesAndUtxos = await getSlpBalancesAndUtxos( | |||||
hydratedUtxoDetails, | |||||
); | |||||
*/ | |||||
// So, first, do a parsed hydrateutxo call on just the changed utxos | |||||
// 2) Add these results to the hydratedUtxos result you have in state, then flatten them | |||||
// 3) Determine slpBalancesAndUtxos | |||||
// Get hydrated utxo details of only this set | |||||
// actually this should be done in useWallet | |||||
//const hydratedUtxoDetailsOfChangedUtxos = await getHydratedUtxoDetails(BCH, parsedChangedUtxos); | |||||
}; | |||||
const getHydratedUtxoDetails = async (BCH, utxos) => { | const getHydratedUtxoDetails = async (BCH, utxos) => { | ||||
const hydrateUtxosPromises = []; | const hydrateUtxosPromises = []; | ||||
for (let i = 0; i < utxos.length; i += 1) { | for (let i = 0; i < utxos.length; i += 1) { | ||||
let thisAddress = utxos[i].address; | let thisAddress = utxos[i].address; | ||||
let theseUtxos = utxos[i].utxos; | let theseUtxos = utxos[i].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 665 Lines • Show Last 20 Lines |