Skip to content

token dropdown loading issues in Orders/Vaults list pages#2428

Open
findolor wants to merge 2 commits intomainfrom
fix/token-dropdown-chain-id-deserialization
Open

token dropdown loading issues in Orders/Vaults list pages#2428
findolor wants to merge 2 commits intomainfrom
fix/token-dropdown-chain-id-deserialization

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented Feb 3, 2026

Motivation

See issues:

The token selection dropdown in Orders and Vaults list pages had two issues:

  1. Deserialization error when a network was selected: Selecting a network then opening the token dropdown produced the error: "Cannot load tokens list: There was an error querying the local database: Deserialization failed: missing field chainId"

  2. Empty token list when no network selected: When no network filter was applied, the token dropdown showed no tokens because the code defaulted to querying only the subgraph (which returned nothing) instead of the local database.

Solution

SQL Query Fix: Added camelCase column aliases to the fetch_all_tokens SQL query to match the LocalDbToken struct's #[serde(rename_all = "camelCase")] attribute. The SQL was returning snake_case column names (chain_id, orderbook_address, token_address) but serde expected camelCase (chainId, orderbookAddress, tokenAddress).

Data Source Logic Fix: Simplified get_all_vault_tokens to follow the same pattern as get_vaults and get_orders - check local DB first, fall back to subgraph. The previous implementation had complex logic that defaulted to subgraph when no chain IDs were provided, even when local DB was available.

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

fix #2425

Summary by CodeRabbit

  • Performance
    • Deterministic ordering of token query results for more consistent responses
    • Simplified token retrieval logic to use a single source per call, improving efficiency and predictability
  • Refactor
    • Token fields now use camelCase names (e.g., chainId, orderbookAddress, tokenAddress)
  • Tests
    • Added tests ensuring local DB is used when available and validating SQL aliasing

- Add camelCase aliases to fetch_all_tokens SQL query to match
  LocalDbToken struct's serde rename_all configuration
- Simplify get_all_vault_tokens to use local DB first (consistent
  with get_vaults), fixing empty token list when no network selected
@findolor findolor self-assigned this Feb 3, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 3, 2026

Walkthrough

Token query changed to emit camelCase aliases and deterministic ORDER BY. Vault token retrieval was simplified to use a single-source fallback: return local DB results when available, otherwise query the subgraph. Added tests verifying SQL aliases and wasm tests for local-db short-circuiting.

Changes

Cohort / File(s) Summary
Token Query
crates/common/src/local_db/query/fetch_all_tokens/query.sql
Selects chain_id AS chainId, orderbook_address AS orderbookAddress, token_address AS tokenAddress; keeps name, symbol, decimals; adds ORDER BY chain_id, orderbook_address, token_address.
Vault Token Retrieval
crates/common/src/raindex_client/vaults.rs
Refactors get_all_vault_tokens to short-circuit and return LocalDbVaults::tokens_list(ids) when local DB is present; otherwise calls SubgraphVaults::tokens_list(ids). Removes previous batching/merge path. Adds wasm tests asserting local DB is used and SQL capture.
Fetch All Tokens Tests
crates/common/src/local_db/query/fetch_all_tokens/mod.rs
Adds unit test sql_uses_camel_case_aliases that asserts generated SQL contains camelCase aliases for core fields.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Vaults as RaindexClient::Vaults
  participant LocalDB as LocalDbVaults
  participant Subgraph as SubgraphVaults

  Caller->>Vaults: get_all_vault_tokens(chain_ids)
  Vaults-->>Vaults: compute ids from chain_ids
  alt local DB available
    Vaults->>LocalDB: tokens_list(ids)
    LocalDB-->>Vaults: tokens
    Vaults-->>Caller: return tokens
  else local DB not available
    Vaults->>Subgraph: tokens_list(ids)
    Subgraph-->>Vaults: tokens
    Vaults-->>Caller: return tokens
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

rust, bug, webapp

Suggested reviewers

  • 0xgleb
  • hardyjosh
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly addresses the main issue being fixed: token dropdown loading problems affecting Orders/Vaults list pages, matching the primary objective of resolving deserialization errors and data source logic issues.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #2425: fixed SQL deserialization errors via camelCase aliases, corrected data source logic to check local DB first, and added unit test coverage for the token dropdown fix.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to the linked issue: SQL query fixes for token serialization, data source logic simplification in vault token retrieval, and unit tests for verification; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/token-dropdown-chain-id-deserialization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@findolor findolor requested review from 0xgleb and hardyjosh February 3, 2026 07:07
@findolor findolor removed request for 0xgleb and hardyjosh April 15, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Token Selection Dropdown Loading Issues

1 participant