Skip to content

Commit

Permalink
Use getAddressesAddressTransactions in DW
Browse files Browse the repository at this point in the history
Related to #999
  • Loading branch information
nop33 committed Nov 25, 2024
1 parent d9b8e26 commit 7e34f26
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions apps/desktop-wallet/src/api/queries/transactionQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ export const addressLatestTransactionQuery = ({ addressHash, networkId, skip }:
queryFn:
!skip && networkId !== undefined
? async ({ queryKey }) => {
const transactions = await throttledClient.explorer.addresses.getAddressesAddressTransactions(addressHash, {
page: 1,
limit: 1
})
const latestTx = await throttledClient.explorer.addresses.getAddressesAddressLatestTransaction(addressHash)

const latestTx = transactions.length > 0 ? transactions[0] : undefined
const cachedData = queryClient.getQueryData(queryKey) as AddressLatestTransactionQueryFnData | undefined
const cachedLatestTx = cachedData?.latestTx

// The following block invalidates queries that need to refetch data if a new transaction hash has been
// detected. This way, we don't need to use the latest tx hash in the queryKey of each of those queries.
if (latestTx !== undefined && latestTx.hash !== cachedLatestTx?.hash) {
if (latestTx?.hash && latestTx.hash !== cachedLatestTx?.hash) {
queryClient.invalidateQueries({ queryKey: ['address', addressHash, 'balance'] })
queryClient.invalidateQueries({ queryKey: ['wallet', 'transactions', 'latest'] })
}
Expand Down

0 comments on commit 7e34f26

Please sign in to comment.