Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/chronik.js
Show First 20 Lines • Show All 674 Lines • ▼ Show 20 Lines | export const parseChronikTx = (BCH, tx, wallet, tokenInfoById) => { | ||||
// Convert from sats to XEC | // Convert from sats to XEC | ||||
xecAmount = xecAmount.shiftedBy(-1 * currency.cashDecimals); | xecAmount = xecAmount.shiftedBy(-1 * currency.cashDecimals); | ||||
// Convert from BigNumber to string | // Convert from BigNumber to string | ||||
xecAmount = xecAmount.toString(); | xecAmount = xecAmount.toString(); | ||||
// Get decimal info for correct etokenAmount | // Get decimal info for correct etokenAmount | ||||
let genesisInfo = {}; | |||||
if (isEtokenTx) { | if (isEtokenTx) { | ||||
// Get token genesis info from cache | // Get token genesis info from cache | ||||
let tokenGenesisInfo = {}; | |||||
let decimals = 0; | let decimals = 0; | ||||
try { | try { | ||||
tokenGenesisInfo = tokenInfoById[tx.slpTxData.slpMeta.tokenId]; | genesisInfo = tokenInfoById[tx.slpTxData.slpMeta.tokenId]; | ||||
genesisInfo.success = true; | |||||
// tokenGenesisInfo should be there for every tx in tx history, since it's already been cached for every utxo in the wallet | // tokenGenesisInfo should be there for every tx in tx history, since it's already been cached for every utxo in the wallet | ||||
// but try...catch just in case | // but try...catch just in case | ||||
decimals = tokenGenesisInfo.decimals; | decimals = genesisInfo.decimals; | ||||
etokenAmount = etokenAmount.shiftedBy(-1 * decimals); | etokenAmount = etokenAmount.shiftedBy(-1 * decimals); | ||||
} catch (err) { | } catch (err) { | ||||
console.log( | console.log( | ||||
`Error getting token info from cache in parseChronikTx`, | `Error getting token info from cache in parseChronikTx`, | ||||
err, | err, | ||||
); | ); | ||||
// To keep this function synchronous, do not get this info from the API if it is not in cache | |||||
// Instead, return a flag so that useWallet.js knows and can fetch this info + add it to cache | |||||
genesisInfo.success = false; | |||||
} | } | ||||
} | } | ||||
etokenAmount = etokenAmount.toString(); | etokenAmount = etokenAmount.toString(); | ||||
// Convert opReturnMessage to string | // Convert opReturnMessage to string | ||||
opReturnMessage = Buffer.from(opReturnMessage).toString(); | opReturnMessage = Buffer.from(opReturnMessage).toString(); | ||||
// Return eToken specific fields if eToken tx | // Return eToken specific fields if eToken tx | ||||
if (isEtokenTx) { | if (isEtokenTx) { | ||||
const { slpMeta } = tx.slpTxData; | const { slpMeta } = tx.slpTxData; | ||||
return { | return { | ||||
incoming, | incoming, | ||||
xecAmount, | xecAmount, | ||||
originatingHash160, | originatingHash160, | ||||
isEtokenTx, | isEtokenTx, | ||||
etokenAmount, | etokenAmount, | ||||
slpMeta, | slpMeta, | ||||
genesisInfo, | |||||
legacy: { | legacy: { | ||||
amountSent: incoming ? 0 : xecAmount, | amountSent: incoming ? 0 : xecAmount, | ||||
amountReceived: incoming ? xecAmount : 0, | amountReceived: incoming ? xecAmount : 0, | ||||
outgoingTx: !incoming, | outgoingTx: !incoming, | ||||
tokenTx: true, | tokenTx: true, | ||||
airdropFlag, | airdropFlag, | ||||
airdropTokenId, | airdropTokenId, | ||||
opReturnMessage: '', | opReturnMessage: '', | ||||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |