Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show All 26 Lines | |||||
import { currency } from 'components/Common/Ticker'; | import { currency } from 'components/Common/Ticker'; | ||||
import isEmpty from 'lodash.isempty'; | import isEmpty from 'lodash.isempty'; | ||||
import isEqual from 'lodash.isequal'; | import isEqual from 'lodash.isequal'; | ||||
import { | import { | ||||
xecReceivedNotification, | xecReceivedNotification, | ||||
xecReceivedNotificationWebsocket, | xecReceivedNotificationWebsocket, | ||||
eTokenReceivedNotification, | eTokenReceivedNotification, | ||||
} from 'components/Common/Notifications'; | } from 'components/Common/Notifications'; | ||||
import { getUtxosChronik } from 'utils/chronik'; | |||||
import { ChronikClient } from 'chronik-client'; | import { ChronikClient } from 'chronik-client'; | ||||
// For XEC, eCash chain: | // For XEC, eCash chain: | ||||
const chronik = new ChronikClient(currency.chronikUrl); | const chronik = new ChronikClient(currency.chronikUrl); | ||||
const useWallet = () => { | const useWallet = () => { | ||||
const [walletRefreshInterval, setWalletRefreshInterval] = useState( | const [walletRefreshInterval, setWalletRefreshInterval] = useState( | ||||
currency.websocketDisconnectedRefreshInterval, | currency.websocketDisconnectedRefreshInterval, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 170 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,296 Lines • Show Last 20 Lines |