Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | const haveUtxosChanged = (wallet, utxos, previousUtxos) => { | ||||
// then assume utxos have changed | // then assume utxos have changed | ||||
return true; | return true; | ||||
} | } | ||||
// return true for empty array, since this means you definitely do not want to skip the next API call | // return true for empty array, since this means you definitely do not want to skip the next API call | ||||
if (utxos && utxos.length === 0) { | if (utxos && utxos.length === 0) { | ||||
return true; | return true; | ||||
} | } | ||||
// If utxo set is in wallet object, use that to compare instead of previousUtxos | |||||
let previousUtxosToCompare; | |||||
if (wallet.state && wallet.state.utxos) { | |||||
previousUtxosToCompare = wallet.state.utxos; | |||||
} else { | |||||
previousUtxosToCompare = previousUtxos; | |||||
} | |||||
// Compare utxo sets | // Compare utxo sets | ||||
const utxoArraysUnchanged = isEqual(utxos, previousUtxosToCompare); | return !isEqual(utxos, previousUtxos); | ||||
// If utxos are not the same as previousUtxos | |||||
if (utxoArraysUnchanged) { | |||||
// then utxos have not changed | |||||
return false; | |||||
// otherwise, | |||||
} else { | |||||
// utxos have changed | |||||
return true; | |||||
} | |||||
}; | }; | ||||
const update = async ({ wallet, setWalletState }) => { | const update = async ({ wallet, setWalletState }) => { | ||||
//console.log(`tick()`); | //console.log(`tick()`); | ||||
//console.time("update"); | //console.time("update"); | ||||
try { | try { | ||||
if (!wallet) { | if (!wallet) { | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 1,129 Lines • Show Last 20 Lines |