Skip to content

fix: refetch account transaction history when pools resolve - #5796

Closed
cuzz-venus wants to merge 1 commit into
mainfrom
fix/transaction-history-pools-query-key
Closed

fix: refetch account transaction history when pools resolve#5796
cuzz-venus wants to merge 1 commit into
mainfrom
fix/transaction-history-pools-query-key

Conversation

@cuzz-venus

Copy link
Copy Markdown
Contributor

Problem

useGetAccountTransactionHistory built its react-query key from [FunctionKey.GET_ACCOUNT_TRANSACTION_HISTORY, { ...params, chainId }], while its query function closed over getPoolsData coming from its own useGetPools({ includeIsolatedPools: true }) call.

That pools call passes no accountAddress, so it is a cache entry nothing else on the page warms — pages/Dashboard/Transactions itself fetches useGetPools({ accountAddress, includeIsolatedPools: true }), a different key. The account-less entry is therefore cold at every first mount, by construction:

  1. the query function runs with getPoolsData === undefined;
  2. vTokenAssetMapping comes out {} (getAccountTransactionHistory/index.ts:64);
  3. formatToMarketTransaction hits its only early exit and returns undefined for every row (formatApiTransaction/formatToMarketTransaction/index.ts:31);
  4. the empty result is cached under a key that does not change when the pools resolve, so nothing ever refetches.

The API serves the rows; the dashboard Transactions tab renders "No transactions yet" for every wallet-connected account with history. It does not recover on reload or on a Markets↔Transactions tab round-trip — only a type-filter round-trip more than 10s later (a new key plus a stale entry) brings the rows back.

Fix

In useGetAccountTransactionHistory:

  • Derive the pools' vToken addresses (lowercased, to mirror the mapping the query builds out of them, and sorted so a reordered payload does not produce a new key) and include them in the query key. The history is now refetched whenever the pools resolve or the listed assets change.
  • Only run the query once the pools are actually available (enabled: isEnabled && !!getPoolsData), so it never fetches against an empty mapping — including on the pools-error path, where isLoading is false but the data is still undefined.
  • Keep reporting isLoading while the pools are pending, so consumers show their spinner instead of briefly flashing the empty-state placeholder. It is gated on the caller's enabled, so a disconnected wallet still gets the placeholder rather than an endless spinner, and on the pools error so a hard pools failure resolves instead of spinning.
  • Narrow the hook's enabled option to boolean. react-query v5 also accepts a (query) => boolean predicate, which cannot be resolved here and would have been silently dropped by the && above.

No change was needed in the API layer, the components, or the QA suite's mocks.

Files

File Change
apps/evm/src/clients/api/queries/getAccountTransactionHistory/useGetAccountTransactionHistory.ts modified — query key marker, enabled gate, isLoading composition, narrowed options type
apps/evm/src/clients/api/queries/getAccountTransactionHistory/__tests__/useGetAccountTransactionHistory.spec.ts added — 7 specs

Tests

New hook spec covering both halves of the fix. Each was verified to fail against the unfixed code:

  • does not fetch while the pools are loading, and reports a loading state
  • fetches with the pools once they have resolved
  • fetches once the pools resolve after an initial render without them
  • refetches when the assets of the pools change (fails if the key marker is removed)
  • does not refetch when the assets are returned in a different order (fails if the .sort() is removed)
  • does not fetch when the pools request failed, and does not spin forever
  • does not report a loading state, and does not fetch, when the caller disables the query

Gates

All four run end to end on this branch:

Gate Result
yarn tsc pass — 3/3 packages
yarn lint pass — 3/3 packages (16 pre-existing useLiteralEnumMembers warnings in @venusprotocol/chains, non-fatal)
yarn extract-translations pass — no translation-file changes (no new user-facing copy)
yarn test --coverage pass — evm 434 files / 1849 tests, chains 9 / 16. Coverage: statements 80.76, branches 86.05, functions 74.54, lines 80.76 (baseline 80.75 / 86.03 / 74.59 / 80.75)

Note: src/App/Routes/__tests__/index.spec.tsx flaked once on an intermediate coverage run (a findByText timeout on a route whose page component is mocked, so it cannot reach this change). It passes in isolation and the final full run is green at 1849/1849. This flake is pre-existing and was already recorded before this ticket.

Ticket

Multica VENUS-177 — Jira VPD-1580 cluster, 19 sub-tasks: VPD-1694, VPD-1733, VPD-1849, VPD-1872, VPD-1873, VPD-1874, VPD-1875, VPD-1876, VPD-1877, VPD-1883, VPD-1884, VPD-1885, VPD-1886, VPD-1887, VPD-1888, VPD-1889, VPD-1890, VPD-1891, VPD-1892 (TC-TXN-007 / 010–027).

Follow-ups (not in this PR)

  • This hook fetches useGetPools({ includeIsolatedPools: true }) while pages/Dashboard/Transactions fetches useGetPools({ accountAddress, includeIsolatedPools: true }) — two cache entries for what is nearly the same data, so the tab waits on a second pools round-trip. Consolidating them touches how pools are cached across the app and is out of scope here.
  • liquidityHubs is still imported into app code from __mocks__/models/liquidityHubs (pre-existing // TODO: fetch from API). Worth a ticket reference on that TODO.

useGetAccountTransactionHistory built its query key from the trimmed params
and the chain ID only, while its query function closed over the pools it
fetches through its own useGetPools({ includeIsolatedPools: true }) call.
Nothing else warms that account-less pools cache entry, so it is always cold
on first mount: the query function ran with getPoolsData undefined, the vToken
asset mapping came out empty, and formatToMarketTransaction discarded every
row. The empty result was then cached under a key that never changed when the
pools resolved, so the Transactions tab kept rendering its "no transactions"
placeholder for every connected account with history.

Derive the sorted vToken addresses from the pools and include them in the
query key, and only run the query once the pools are available, so the history
is fetched against a populated mapping and refetched whenever the listed
assets change.
@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 088f533

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dapp-preview Ready Ready Preview Aug 27, 2026 5:25am
dapp-testnet Ready Ready Preview Aug 27, 2026 5:25am
venus.io Ready Ready Preview Aug 27, 2026 5:25am

Request Review

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown

Greptile Summary

The PR delays account transaction-history fetching until pool data is available and adds the resolved vToken set to the React Query cache key.

  • Prevents initial transaction formatting against an empty pool mapping.
  • Refetches history when the set of pool assets changes while avoiding refetches caused only by ordering.
  • Preserves loading behavior while pools are pending and adds focused hook coverage.

Confidence Score: 5/5

The PR appears safe to merge with no actionable changed-code defects identified.

The revised query lifecycle prevents history from being cached before pool metadata resolves, and the new tests cover the relevant cache-key, loading, error, and disabled states.

Important Files Changed

Filename Overview
apps/evm/src/clients/api/queries/getAccountTransactionHistory/useGetAccountTransactionHistory.ts Gates history retrieval on pool availability, fingerprints pool vTokens in the cache key, and composes the dependency loading state without introducing a publishable regression.
apps/evm/src/clients/api/queries/getAccountTransactionHistory/tests/useGetAccountTransactionHistory.spec.ts Covers pending, resolved, changed, reordered, errored, and caller-disabled pool-query states.

Reviews (1): Last reviewed commit: "fix: refetch account transaction history..." | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report for ./apps/evm

Status Category Percentage Covered / Total
🔵 Lines 80.76% 52044 / 64439
🔵 Statements 80.76% 52044 / 64439
🔵 Functions 74.54% 1599 / 2145
🔵 Branches 86.05% 7670 / 8913
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/evm/src/clients/api/queries/getAccountTransactionHistory/useGetAccountTransactionHistory.ts 100% 100% 100% 100%
Generated in workflow #14171 for commit 088f533 by the Vitest Coverage Report Action

@cuzz-venus cuzz-venus closed this Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant