Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useBCH.js
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | const parseTxData = txData => { | ||||
} | } | ||||
} | } | ||||
] | ] | ||||
*/ | */ | ||||
const parsedTxHistory = []; | const parsedTxHistory = []; | ||||
for (let i = 0; i < txData.length; i += 1) { | for (let i = 0; i < txData.length; i += 1) { | ||||
const tx = txData[i]; | const tx = txData[i]; | ||||
// If this tx had too many inputs to be parsed by getTxDataWithPassThrough, skip it | |||||
// When this occurs, the tx will only have txid and height | |||||
// So, it will not have 'vin' | |||||
if (!Object.keys(tx).includes('vin')) { | |||||
// Do not include this tx in history as parsing will always hit rate limits | |||||
continue; | |||||
} | |||||
const parsedTx = {}; | const parsedTx = {}; | ||||
// Move over info that does not need to be calculated | // Move over info that does not need to be calculated | ||||
parsedTx.txid = tx.txid; | parsedTx.txid = tx.txid; | ||||
parsedTx.confirmations = tx.confirmations; | parsedTx.confirmations = tx.confirmations; | ||||
parsedTx.height = tx.height; | parsedTx.height = tx.height; | ||||
parsedTx.blocktime = tx.blocktime; | parsedTx.blocktime = tx.blocktime; | ||||
let amountSent = 0; | let amountSent = 0; | ||||
let amountReceived = 0; | let amountReceived = 0; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | const getTxHistory = async (BCH, addresses) => { | ||||
console.log(`Error in BCH.Electrumx.transactions(addresses):`); | console.log(`Error in BCH.Electrumx.transactions(addresses):`); | ||||
console.log(err); | console.log(err); | ||||
return err; | return err; | ||||
} | } | ||||
}; | }; | ||||
const getTxDataWithPassThrough = async (BCH, flatTx) => { | const getTxDataWithPassThrough = async (BCH, flatTx) => { | ||||
// necessary as BCH.RawTransactions.getTxData does not return address or blockheight | // necessary as BCH.RawTransactions.getTxData does not return address or blockheight | ||||
const txDataWithPassThrough = await BCH.RawTransactions.getTxData( | let txDataWithPassThrough = {}; | ||||
try { | |||||
txDataWithPassThrough = await BCH.RawTransactions.getTxData( | |||||
flatTx.txid, | flatTx.txid, | ||||
); | ); | ||||
} catch (err) { | |||||
console.log( | |||||
`Error in BCH.RawTransactions.getTxData(${flatTx.txid})`, | |||||
); | |||||
console.log(err); | |||||
} | |||||
txDataWithPassThrough.height = flatTx.height; | txDataWithPassThrough.height = flatTx.height; | ||||
txDataWithPassThrough.address = flatTx.address; | txDataWithPassThrough.address = flatTx.address; | ||||
return txDataWithPassThrough; | return txDataWithPassThrough; | ||||
}; | }; | ||||
const getTxData = async (BCH, txHistory) => { | const getTxData = async (BCH, txHistory) => { | ||||
// Flatten tx history | // Flatten tx history | ||||
let flatTxs = flattenTransactions(txHistory); | let flatTxs = flattenTransactions(txHistory); | ||||
▲ Show 20 Lines • Show All 822 Lines • Show Last 20 Lines |