Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | const update = async ({ wallet }) => { | ||||
); | ); | ||||
const { preliminarySlpUtxos, nonSlpUtxos } = | const { preliminarySlpUtxos, nonSlpUtxos } = | ||||
organizeUtxosByType(chronikUtxos); | organizeUtxosByType(chronikUtxos); | ||||
const preliminaryTokensArray = | const preliminaryTokensArray = | ||||
getPreliminaryTokensArray(preliminarySlpUtxos); | getPreliminaryTokensArray(preliminarySlpUtxos); | ||||
const { finalTokenArray, updatedTokenInfoById, newTokensToCache } = | const { tokens, updatedTokenInfoById, newTokensToCache } = | ||||
await finalizeTokensArray( | await finalizeTokensArray( | ||||
chronik, | chronik, | ||||
preliminaryTokensArray, | preliminaryTokensArray, | ||||
cashtabCache.tokenInfoById, | cashtabCache.tokenInfoById, | ||||
); | ); | ||||
// If you have more token info now, write this to local storage | // If you have more token info now, write this to local storage | ||||
if (newTokensToCache) { | if (newTokensToCache) { | ||||
writeTokenInfoByIdToCache(updatedTokenInfoById); | writeTokenInfoByIdToCache(updatedTokenInfoById); | ||||
// Update the tokenInfoById key in cashtabCache | // Update the tokenInfoById key in cashtabCache | ||||
setCashtabCache({ | setCashtabCache({ | ||||
...cashtabCache, | ...cashtabCache, | ||||
tokenInfoById: updatedTokenInfoById, | tokenInfoById: updatedTokenInfoById, | ||||
}); | }); | ||||
} | } | ||||
const finalizedSlpUtxos = finalizeSlpUtxos( | const slpUtxos = finalizeSlpUtxos( | ||||
preliminarySlpUtxos, | preliminarySlpUtxos, | ||||
updatedTokenInfoById, | updatedTokenInfoById, | ||||
); | ); | ||||
const { | const { | ||||
chronikTxHistory, | parsedTxHistory, | ||||
txHistoryUpdatedTokenInfoById, | txHistoryUpdatedTokenInfoById, | ||||
txHistoryNewTokensToCache, | txHistoryNewTokensToCache, | ||||
} = await getTxHistoryChronik( | } = await getTxHistoryChronik( | ||||
chronik, | chronik, | ||||
BCH, | BCH, | ||||
wallet, | wallet, | ||||
updatedTokenInfoById, | updatedTokenInfoById, | ||||
); | ); | ||||
if (txHistoryNewTokensToCache) { | if (txHistoryNewTokensToCache) { | ||||
console.log( | console.log( | ||||
`Uncached token info found in tx history, adding to cache`, | `Uncached token info found in tx history, adding to cache`, | ||||
); | ); | ||||
writeTokenInfoByIdToCache(txHistoryUpdatedTokenInfoById); | writeTokenInfoByIdToCache(txHistoryUpdatedTokenInfoById); | ||||
// Update the tokenInfoById key in cashtabCache | // Update the tokenInfoById key in cashtabCache | ||||
setCashtabCache({ | setCashtabCache({ | ||||
...cashtabCache, | ...cashtabCache, | ||||
tokenInfoById: txHistoryUpdatedTokenInfoById, | tokenInfoById: txHistoryUpdatedTokenInfoById, | ||||
}); | }); | ||||
} | } | ||||
// If you were missing any token info for tokens in this tx history, get it | // If you were missing any token info for tokens in this tx history, get it | ||||
const newState = { | const newState = { | ||||
balances: getWalletBalanceFromUtxos(nonSlpUtxos), | balances: getWalletBalanceFromUtxos(nonSlpUtxos), | ||||
tokens: finalTokenArray, | slpUtxos, | ||||
slpUtxos: finalizedSlpUtxos, | |||||
nonSlpUtxos, | nonSlpUtxos, | ||||
parsedTxHistory: chronikTxHistory, | tokens, | ||||
parsedTxHistory, | |||||
}; | }; | ||||
const walletStateAfterThisStack = { | const walletStateAfterThisStack = { | ||||
balances: getWalletBalanceFromUtxos(nonSlpUtxos), | balances: getWalletBalanceFromUtxos(nonSlpUtxos), | ||||
slpUtxos: finalizedSlpUtxos, | slpUtxos, | ||||
nonSlpUtxos, | nonSlpUtxos, | ||||
tokens: finalTokenArray, | tokens, | ||||
parsedTxHistory: chronikTxHistory, | parsedTxHistory, | ||||
}; | }; | ||||
console.log(`walletStateAfterThisStack`, walletStateAfterThisStack); | console.log(`walletStateAfterThisStack`, walletStateAfterThisStack); | ||||
// Set wallet with new state field | // Set wallet with new state field | ||||
wallet.state = newState; | wallet.state = newState; | ||||
setWallet(wallet); | setWallet(wallet); | ||||
▲ Show 20 Lines • Show All 1,212 Lines • Show Last 20 Lines |