Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show All 12 Lines | import { | ||||
addNewHydratedUtxos, | addNewHydratedUtxos, | ||||
removeConsumedUtxos, | removeConsumedUtxos, | ||||
areAllUtxosIncludedInIncrementallyHydratedUtxos, | areAllUtxosIncludedInIncrementallyHydratedUtxos, | ||||
getHashArrayFromWallet, | getHashArrayFromWallet, | ||||
parseChronikTx, | parseChronikTx, | ||||
checkWalletForTokenInfo, | checkWalletForTokenInfo, | ||||
isActiveWebsocket, | isActiveWebsocket, | ||||
} from 'utils/cashMethods'; | } from 'utils/cashMethods'; | ||||
import { getUtxosChronik } from 'utils/chronik'; | |||||
import { | import { | ||||
isValidCashtabSettings, | isValidCashtabSettings, | ||||
isValidContactList, | isValidContactList, | ||||
parseInvalidSettingsForMigration, | parseInvalidSettingsForMigration, | ||||
} from 'utils/validation'; | } from 'utils/validation'; | ||||
import localforage from 'localforage'; | import localforage from 'localforage'; | ||||
import { currency } from 'components/Common/Ticker'; | import { currency } from 'components/Common/Ticker'; | ||||
import isEmpty from 'lodash.isempty'; | import isEmpty from 'lodash.isempty'; | ||||
▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | const update = async ({ wallet }) => { | ||||
]; | ]; | ||||
const publicKeys = [ | const publicKeys = [ | ||||
wallet.Path145.publicKey, | wallet.Path145.publicKey, | ||||
wallet.Path245.publicKey, | wallet.Path245.publicKey, | ||||
wallet.Path1899.publicKey, | wallet.Path1899.publicKey, | ||||
]; | ]; | ||||
/* | |||||
This strange data structure is necessary because chronik requires the hash160 | |||||
of an address to tell you what utxos are at that address | |||||
*/ | |||||
const hash160AndAddressObjArray = [ | |||||
{ | |||||
address: wallet.Path145.cashAddress, | |||||
hash160: wallet.Path145.hash160, | |||||
}, | |||||
{ | |||||
address: wallet.Path245.cashAddress, | |||||
hash160: wallet.Path245.hash160, | |||||
}, | |||||
{ | |||||
address: wallet.Path1899.cashAddress, | |||||
hash160: wallet.Path1899.hash160, | |||||
}, | |||||
]; | |||||
const utxos = await getUtxos(BCH, cashAddresses); | const utxos = await getUtxos(BCH, cashAddresses); | ||||
console.log(`bchApiUtxos`, utxos); | |||||
const chronikUtxos = await getUtxosChronik( | |||||
chronik, | |||||
hash160AndAddressObjArray, | |||||
); | |||||
console.log(`chronikUtxos`, chronikUtxos); | |||||
// If an error is returned or utxos from only 1 address are returned | // If an error is returned or utxos from only 1 address are returned | ||||
if ( | if ( | ||||
!utxos || | !utxos || | ||||
!Array.isArray(utxos) || | !Array.isArray(utxos) || | ||||
isEmpty(utxos) || | isEmpty(utxos) || | ||||
utxos.error || | utxos.error || | ||||
utxos.length < 2 | utxos.length < 2 | ||||
▲ Show 20 Lines • Show All 1,252 Lines • Show Last 20 Lines |