Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show All 24 Lines | const useWallet = () => { | ||||
}); | }); | ||||
const { | const { | ||||
getBCH, | getBCH, | ||||
getUtxos, | getUtxos, | ||||
getHydratedUtxoDetails, | getHydratedUtxoDetails, | ||||
getSlpBalancesAndUtxos, | getSlpBalancesAndUtxos, | ||||
getTxHistory, | getTxHistory, | ||||
getTxData, | getTxData, | ||||
addTokenTxData, | |||||
} = useBCH(); | } = useBCH(); | ||||
const [loading, setLoading] = useState(true); | const [loading, setLoading] = useState(true); | ||||
const [apiIndex, setApiIndex] = useState(0); | const [apiIndex, setApiIndex] = useState(0); | ||||
const [BCH, setBCH] = useState(getBCH(apiIndex)); | const [BCH, setBCH] = useState(getBCH(apiIndex)); | ||||
const [utxos, setUtxos] = useState(null); | const [utxos, setUtxos] = useState(null); | ||||
const { | const { | ||||
balances, | balances, | ||||
tokens, | tokens, | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | const update = async ({ wallet, setWalletState }) => { | ||||
utxos, | utxos, | ||||
); | ); | ||||
const slpBalancesAndUtxos = await getSlpBalancesAndUtxos( | const slpBalancesAndUtxos = await getSlpBalancesAndUtxos( | ||||
hydratedUtxoDetails, | hydratedUtxoDetails, | ||||
); | ); | ||||
const txHistory = await getTxHistory(BCH, cashAddresses); | const txHistory = await getTxHistory(BCH, cashAddresses); | ||||
const parsedTxHistory = await getTxData(BCH, txHistory); | const parsedTxHistory = await getTxData(BCH, txHistory); | ||||
console.log(`parsedTxHistory`, parsedTxHistory); | //console.log(`parsedTxHistory`, parsedTxHistory); | ||||
Fabien: dito | |||||
const parsedWithTokens = await addTokenTxData(BCH, parsedTxHistory); | |||||
//console.log(`parsedWithTokens`, parsedWithTokens); | |||||
FabienUnsubmitted Done Inline Actionsdito Fabien: dito | |||||
console.log(`slpBalancesAndUtxos`, slpBalancesAndUtxos); | console.log(`slpBalancesAndUtxos`, slpBalancesAndUtxos); | ||||
if (typeof slpBalancesAndUtxos === 'undefined') { | if (typeof slpBalancesAndUtxos === 'undefined') { | ||||
console.log(`slpBalancesAndUtxos is undefined`); | console.log(`slpBalancesAndUtxos is undefined`); | ||||
throw new Error('slpBalancesAndUtxos is undefined'); | throw new Error('slpBalancesAndUtxos is undefined'); | ||||
} | } | ||||
const { tokens } = slpBalancesAndUtxos; | const { tokens } = slpBalancesAndUtxos; | ||||
const newState = { | const newState = { | ||||
balances: {}, | balances: {}, | ||||
tokens: [], | tokens: [], | ||||
slpBalancesAndUtxos: [], | slpBalancesAndUtxos: [], | ||||
}; | }; | ||||
newState.slpBalancesAndUtxos = normalizeSlpBalancesAndUtxos( | newState.slpBalancesAndUtxos = normalizeSlpBalancesAndUtxos( | ||||
slpBalancesAndUtxos, | slpBalancesAndUtxos, | ||||
wallet, | wallet, | ||||
); | ); | ||||
newState.balances = normalizeBalance(slpBalancesAndUtxos); | newState.balances = normalizeBalance(slpBalancesAndUtxos); | ||||
newState.tokens = tokens; | newState.tokens = tokens; | ||||
newState.parsedTxHistory = parsedTxHistory; | newState.parsedTxHistory = parsedWithTokens; | ||||
setWalletState(newState); | setWalletState(newState); | ||||
// If everything executed correctly, remove apiError | // If everything executed correctly, remove apiError | ||||
setApiError(false); | setApiError(false); | ||||
} catch (error) { | } catch (error) { | ||||
console.log(`Error in update({wallet, setWalletState})`); | console.log(`Error in update({wallet, setWalletState})`); | ||||
console.log(error); | console.log(error); | ||||
▲ Show 20 Lines • Show All 1,013 Lines • Show Last 20 Lines |
dito