Skip to content

Fix filters Mobula search API#281

Merged
RanaBug merged 2 commits intostagingfrom
feat/mobula-search-api
Apr 3, 2025
Merged

Fix filters Mobula search API#281
RanaBug merged 2 commits intostagingfrom
feat/mobula-search-api

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented Apr 2, 2025

Description

  • Fix of the blockchains filters of the Mobula Search API
  • Remove local token list as a default token list on Token Atlas and Exchange

How Has This Been Tested?

  • Unit tests and manual testing

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • New Features

    • Enhanced the token search experience by providing clearer prompts (e.g., "Start searching for tokens") when no selection is made.
    • Improved feedback during token searches by combining loading indicators for a more responsive UI.
  • Refactor

    • Streamlined token selection and display across exchange and search interfaces for more consistent and intuitive user interactions.
    • Simplified state management for token data, consolidating multiple states into a single source of truth.

@RanaBug RanaBug requested a review from IAmKio April 2, 2025 15:45
@RanaBug RanaBug self-assigned this Apr 2, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Walkthrough

The changes consolidate token state management by removing separate dispatch actions for swap and receive token data in favor of a single action—setSearchTokenResult—with an updated type allowing undefined. Component logic and tests across both the exchange and token atlas modules have been updated accordingly. Additionally, the API call in the token search service has been refactored to adjust query parameter construction, and components now incorporate a combined loading status using the new isFetching variable.

Changes

Files Change Summary
CardsSwap Component & Test
src/apps/the-exchange/components/CardsSwap/CardsSwap.tsx
src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx
Removed dispatch actions setReceiveTokenData and setSwapTokenData; replaced with setSearchTokenResult(undefined). Removed the queryTokenData call and updated test assertions to check for “Start searching for tokens.”
DropdownTokensList Component & Test
src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx
src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx
Removed state selectors and dispatches for swapTokenData and receiveTokenData; now uses searchTokenResult (typed as `Token[]
Additional Exchange Tests
src/apps/the-exchange/components/EnterAmount/test/EnterAmount.test.tsx
src/apps/the-exchange/components/ExchangeAction/test/ExchangeAction.test.tsx
src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx
Removed dispatches for swap/receive token data and updated initialization to use setSearchTokenResult(undefined), with corresponding assertion changes.
Token Search Components (Exchange & Atlas)
src/apps/the-exchange/components/TokenSearchInput/TokenSearchInput.tsx
src/apps/token-atlas/components/TokensSearchInput/TokensSearchInput.tsx
Introduced the isFetching variable from the token query hook; combined with isLoading for improved loading state handling; updated dependency arrays (e.g., using selectedChain.chainName).
Token Atlas UI & Tests
src/apps/token-atlas/components/HeaderSearch/HeaderSeach.tsx
src/apps/token-atlas/components/SearchTokenModal/SearchTokenModal.tsx
src/apps/token-atlas/components/SearchTokenModal/test/SearchTokenModal.test.tsx
src/apps/token-atlas/components/TokensSearchResult/TokensSearchResult.tsx
src/apps/token-atlas/components/TokensSearchResult/test/TokensSearchResult.test.tsx
Removed token data imports and logic (e.g. setTokenListData, token type, and chain mapping function); simplified token selection using CompatibleChains; dispatch calls now pass undefined for searchTokenResult; tests adjusted to reflect these changes.
Reducers
src/apps/the-exchange/reducer/theExchangeSlice.ts
src/apps/token-atlas/reducer/tokenAtlasSlice.ts
Removed properties and reducers for swapTokenData, receiveTokenData, and tokenListData; updated searchTokenResult type from Token[] to `Token[]
API Service
src/services/pillarXApiSearchTokens.ts
Modified query URL construction by formatting chainIds into the query string and adjusting filter parameters based on the presence of filterBlockchains.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CSC as Token Search Component
    participant QH as Query Hook (useGetSearchTokensQuery)
    participant API as PillarX API
    participant RS as Redux Store

    U->>CSC: Enters token search query
    CSC->>QH: Initiates token search (with chain ID filters)
    QH->>API: Sends API request with formatted query parameters
    API-->>QH: Returns token search results
    QH-->>CSC: Provides results with isLoading & isFetching status
    CSC->>RS: Dispatches setSearchTokenResult(results)
Loading

Possibly related PRs

Suggested reviewers

  • IAmKio

Poem

I'm a hopper with code so spry,
Trimming dispatches as I skip by.
Two actions gone, one now in sight,
Simplifying tokens with all my might.
With carrot dreams and bugs set free,
CodeRabbit cheers this PR in glee!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2987e6a and d6dc5ec.

📒 Files selected for processing (1)
  • src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 2, 2025

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: d6dc5ec
Status: ✅  Deploy successful!
Preview URL: https://ad32b588.x-e62.pages.dev
Branch Preview URL: https://feat-mobula-search-api.x-e62.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ddaedef and 2987e6a.

⛔ Files ignored due to path filters (3)
  • src/apps/pillarx-app/components/MediaGridCollection/tests/__snapshots__/DisplayCollectionImage.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/PointsTile/test/__snapshots__/PointsTile.test.tsx.snap is excluded by !**/*.snap
  • src/apps/the-exchange/components/DropdownTokensList/test/__snapshots__/DropdownTokensList.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (17)
  • src/apps/the-exchange/components/CardsSwap/CardsSwap.tsx (2 hunks)
  • src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx (2 hunks)
  • src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx (9 hunks)
  • src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx (5 hunks)
  • src/apps/the-exchange/components/EnterAmount/test/EnterAmount.test.tsx (1 hunks)
  • src/apps/the-exchange/components/ExchangeAction/test/ExchangeAction.test.tsx (1 hunks)
  • src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx (1 hunks)
  • src/apps/the-exchange/components/TokenSearchInput/TokenSearchInput.tsx (2 hunks)
  • src/apps/the-exchange/reducer/theExchangeSlice.ts (3 hunks)
  • src/apps/token-atlas/components/HeaderSearch/HeaderSeach.tsx (1 hunks)
  • src/apps/token-atlas/components/SearchTokenModal/SearchTokenModal.tsx (2 hunks)
  • src/apps/token-atlas/components/SearchTokenModal/test/SearchTokenModal.test.tsx (4 hunks)
  • src/apps/token-atlas/components/TokensSearchInput/TokensSearchInput.tsx (3 hunks)
  • src/apps/token-atlas/components/TokensSearchResult/TokensSearchResult.tsx (4 hunks)
  • src/apps/token-atlas/components/TokensSearchResult/test/TokensSearchResult.test.tsx (3 hunks)
  • src/apps/token-atlas/reducer/tokenAtlasSlice.ts (3 hunks)
  • src/services/pillarXApiSearchTokens.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (4)
src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx (1)
Learnt from: RanaBug
PR: pillarwallet/x#275
File: src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx:180-195
Timestamp: 2025-03-28T09:22:22.712Z
Learning: In the Exchange app, `swapTokenList` and `receiveTokenList` are derived from `searchTokenResult` when search is active, so including `searchToken` in the useEffect dependency array that uses these lists would be redundant as the lists will update when search results change.
src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx (1)
Learnt from: RanaBug
PR: pillarwallet/x#275
File: src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx:180-195
Timestamp: 2025-03-28T09:22:22.712Z
Learning: In the Exchange app, `swapTokenList` and `receiveTokenList` are derived from `searchTokenResult` when search is active, so including `searchToken` in the useEffect dependency array that uses these lists would be redundant as the lists will update when search results change.
src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx (1)
Learnt from: RanaBug
PR: pillarwallet/x#275
File: src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx:180-195
Timestamp: 2025-03-28T09:22:22.712Z
Learning: In the Exchange app, `swapTokenList` and `receiveTokenList` are derived from `searchTokenResult` when search is active, so including `searchToken` in the useEffect dependency array that uses these lists would be redundant as the lists will update when search results change.
src/apps/the-exchange/components/CardsSwap/CardsSwap.tsx (1)
Learnt from: RanaBug
PR: pillarwallet/x#275
File: src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx:180-195
Timestamp: 2025-03-28T09:22:22.712Z
Learning: In the Exchange app, `swapTokenList` and `receiveTokenList` are derived from `searchTokenResult` when search is active, so including `searchToken` in the useEffect dependency array that uses these lists would be redundant as the lists will update when search results change.
🧬 Code Definitions (8)
src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx (2)
src/apps/the-exchange/reducer/theExchangeSlice.ts (1)
  • setSearchTokenResult (83-85)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
  • setSearchTokenResult (70-72)
src/apps/token-atlas/components/SearchTokenModal/SearchTokenModal.tsx (3)
src/utils/blockchain.ts (1)
  • CompatibleChains (260-289)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
  • setSearchTokenResult (70-72)
src/apps/the-exchange/reducer/theExchangeSlice.ts (1)
  • setSearchTokenResult (83-85)
src/apps/the-exchange/components/TokenSearchInput/TokenSearchInput.tsx (2)
src/apps/the-exchange/reducer/theExchangeSlice.ts (1)
  • setIsTokenSearchLoading (98-100)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
  • setIsTokenSearchLoading (112-114)
src/apps/token-atlas/components/TokensSearchInput/TokensSearchInput.tsx (2)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
  • setIsTokenSearchLoading (112-114)
src/apps/the-exchange/reducer/theExchangeSlice.ts (1)
  • setIsTokenSearchLoading (98-100)
src/services/pillarXApiSearchTokens.ts (1)
src/services/tokensData.ts (1)
  • chainIdToChainNameTokensData (211-232)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
src/services/tokensData.ts (1)
  • Token (11-19)
src/apps/token-atlas/components/SearchTokenModal/test/SearchTokenModal.test.tsx (2)
src/apps/the-exchange/reducer/theExchangeSlice.ts (1)
  • setSearchTokenResult (83-85)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
  • setSearchTokenResult (70-72)
src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx (4)
src/services/tokensData.ts (1)
  • Token (11-19)
src/utils/blockchain.ts (1)
  • CompatibleChains (260-289)
src/apps/the-exchange/reducer/theExchangeSlice.ts (1)
  • setSearchTokenResult (83-85)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
  • setSearchTokenResult (70-72)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (45)
src/apps/the-exchange/components/TokenSearchInput/TokenSearchInput.tsx (2)

80-80: Enhanced loading state tracking with isFetching

Adding the isFetching variable from the useGetSearchTokensQuery hook provides more complete information about the API call state.


93-93: Improved loading state detection with combined conditions

Using the logical OR operation to combine isLoading and isFetching ensures that the UI accurately reflects when a search operation is in progress, regardless of whether it's the initial load or a subsequent fetch.

src/apps/token-atlas/components/HeaderSearch/HeaderSeach.tsx (1)

10-10: Removed setTokenListData import to align with PR objectives

The removal of the setTokenListData import aligns with the PR objective of removing the local token list that was previously set as the default token list. This simplifies the state management by eliminating an unnecessary data fetch when opening the search modal.

src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx (1)

84-84: Updated searchTokenResult initialization to use undefined

Using undefined instead of an empty array for the initial state of searchTokenResult aligns with the updated Redux state type and provides a clearer representation of the "no search performed yet" state.

src/apps/token-atlas/components/TokensSearchInput/TokensSearchInput.tsx (3)

67-67: Enhanced loading state tracking with isFetching

Adding the isFetching variable from the useGetSearchTokensQuery hook provides more complete information about the API call state.


78-78: Improved loading state detection with combined conditions

Using the logical OR operation to combine isLoading and isFetching ensures that the UI accurately reflects when a search operation is in progress, regardless of whether it's the initial load or a subsequent fetch.


104-104: Optimized effect dependency array to use chainName instead of the entire object

Using selectedChain.chainName instead of the entire selectedChain object in the dependency array is more efficient. This change prevents unnecessary effect executions when other properties of selectedChain change but the chainName remains the same.

src/apps/token-atlas/components/SearchTokenModal/SearchTokenModal.tsx (3)

13-14: Simplified chain data source.

Good refactoring to use CompatibleChains from the blockchain utils instead of relying on token list data. This creates a more centralized approach to chain management.


35-35: Improved chain ID extraction.

The change from using token list data to directly mapping over CompatibleChains makes the code more predictable and removes an unnecessary dependency on runtime data.


40-40:

Details

✅ Verification successful

Uniform state cleanup with undefined.

Using undefined instead of an empty array aligns with the broader refactoring approach. This ensures consistent state management when closing the modal.


🏁 Script executed:

#!/bin/bash
# Verify that all components handle undefined searchTokenResult properly
rg -A 2 -B 2 'searchTokenResult\s*\?{1,2}|searchTokenResult\s*&&|searchTokenResult\s*!==\s*undefined'

Length of output: 4369


Uniform state cleanup using undefined is confirmed

After running the verification script, it's clear that all components—including TokensSearchResult.tsx and DropdownTokenList.tsx—handle searchTokenResult reliably when it is set to undefined. The conditional checks in these files (e.g., !searchTokenResult or searchTokenResult && ...) ensure that the UI behaves as intended (displaying the "Start searching for tokens" message when appropriate). This aligns with the broader refactoring approach for consistent state management upon modal closure.

src/apps/the-exchange/components/EnterAmount/test/EnterAmount.test.tsx (1)

107-107: Updated test initialization to match implementation changes.

Good update to the test setup to use undefined for search token results instead of mock token data, consistent with the application-wide refactoring of token state management.

src/services/pillarXApiSearchTokens.ts (3)

38-38: Improved query parameter construction.

Good implementation of query string construction for chain IDs. This creates a properly formatted URL parameter string.


41-41: Moved parameters from body to URL query string.

Shifting chainIds and testnets from the request body to URL parameters is a good approach if the API expects these parameters in the URL rather than the body.


47-57:

Details

❓ Verification inconclusive

Enhanced filter construction logic.

The updated implementation properly handles both specific and default filter cases. This should fix the blockchain filters issue mentioned in the PR title.


🏁 Script executed:

#!/bin/bash
# Verify that chain names are correctly formatted for the API
echo "Testing chainIdToChainNameTokensData output format:"
rg -A 10 'chainIdToChainNameTokensData' src/services/tokensData.ts

# Check if the filter format in the API call matches what the API expects
echo "Searching for other API usages for consistency:"
rg -A 3 'filters: JSON.stringify\(' --glob '!src/services/pillarXApiSearchTokens.ts'

Length of output: 1572


Enhanced filter construction validated – please verify API filter consistency manually.

The updated implementation correctly distinguishes between custom filter logic (using filterBlockchains) and the default construction via mapping CompatibleChains with chainIdToChainNameTokensData. The chain formatting output in src/services/tokensData.ts matches the expected structure. However, our search for similar filter construction in other API calls did not return any results, so it is advisable to manually verify that the API correctly interprets the filters payload generated here.

  • Location: src/services/pillarXApiSearchTokens.ts (Lines 47-57)
  • Recommendation: Ensure that the API’s filter processing aligns with the constructed JSON string, especially in contexts outside this service.
src/apps/token-atlas/components/SearchTokenModal/test/SearchTokenModal.test.tsx (4)

23-23: Updated initial state to use undefined.

Good alignment with the implementation changes by initializing the search token result with undefined instead of an empty array.


53-53: Updated UI assertion to check for placeholder text.

The test now checks for the presence of "Start searching for tokens." instead of specific token names, reflecting the UI changes after removing the local token list.


68-70: Consistent validation for closed modal state.

The test correctly checks that the placeholder text is not present when the modal is closed, maintaining good test coverage.


93-93: Updated state assertion to expect undefined.

Good update to expect undefined instead of an empty array for searchTokenResult after closing the modal, ensuring the test matches the actual implementation.

src/apps/the-exchange/components/ExchangeAction/test/ExchangeAction.test.tsx (1)

103-103: State initialization aligned with consolidated token state pattern.

The test now initializes searchTokenResult with undefined rather than an empty array, reflecting the underlying implementation change of consolidating separate swap and receive token data actions into a single setSearchTokenResult action.

src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx (2)

200-200: State initialization aligned with updated token state management.

The test now initializes searchTokenResult with undefined rather than an empty array, matching the changes in the implementation code's state management approach.


273-273: Test assertion updated to match new UI behavior.

The test now correctly checks for the presence of the "Start searching for tokens" message that appears when no token results are available, rather than checking for token data presence as was done previously.

src/apps/token-atlas/components/TokensSearchResult/test/TokensSearchResult.test.tsx (3)

76-76: Test case name updated to reflect new behavior.

The test description now accurately indicates that we're testing the "no results" scenario rather than checking for token list data availability.


89-91: Test assertions updated to check for empty state messaging.

The test now verifies that:

  1. Token list items are not present in the document (using queryByText with negation)
  2. The "no tokens found" message is displayed

This correctly tests the component's updated behavior when no search results are available.


133-133: Updated state expectation to match new implementation.

The test now expects searchTokenResult to be undefined after token selection, aligning with the updated implementation where token results are cleared rather than set to an empty array.

src/apps/the-exchange/components/CardsSwap/CardsSwap.tsx (2)

8-8: Import updated to include the necessary dispatch action.

Added import for setSearchTokenResult to replace the removed token data actions.


56-56:

Details

❓ Verification inconclusive

Token state management consolidated.

The implementation now uses a single dispatch action setSearchTokenResult(undefined) instead of separate actions for swap and receive token data, simplifying the token state management approach. This aligns with the broader pattern change mentioned in the retrieved learning.


🏁 Script executed:

#!/bin/bash
# Verify that all references to the removed token data actions have been updated

# Check for any remaining usages of removed token data actions in the codebase
echo "Checking for remaining references to the removed token data actions..."
rg "setReceiveTokenData|setSwapTokenData" --type ts

Length of output: 204


Token state management successfully consolidated – please verify remaining references manually.

The updated implementation now relies solely on:

  • Using dispatch(setSearchTokenResult(undefined)) at src/apps/the-exchange/components/CardsSwap/CardsSwap.tsx:56
  • Removing the previously separate actions for swap/receive token data

Our automated search for setReceiveTokenData and setSwapTokenData using the provided script produced no output, suggesting that references to these removed actions have been cleared. However, since the output was minimal, please double-check across all relevant file types (including TSX files) to ensure that no lingering references remain.

src/apps/token-atlas/components/TokensSearchResult/TokensSearchResult.tsx (4)

35-35: Updated type annotation for searchTokenResult

The type for searchTokenResult has been updated to support undefined values, which aligns with the broader changes in token state management throughout the application.


61-61: Changed reset behavior to use undefined instead of empty array

This change ensures consistency with the new state management approach by setting searchTokenResult to undefined rather than an empty array when a token is selected.


70-77: Improved auto-selection condition checks

The useEffect condition now properly checks if searchTokenResult is defined before attempting to access its properties, preventing potential runtime errors. The dependency array has also been updated to only include the necessary dependency.


87-110: Improved rendering logic with better undefined handling

The updated rendering conditions properly handle the various states of searchTokenResult (undefined, empty array, or populated array), improving the user experience by showing appropriate messages based on the current state.

src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx (4)

1-1: Added screen import for improved test readability

Added import of screen from @testing-library/react to use the modern approach for querying rendered elements, which improves test readability and maintainability.


121-121: Updated test setup to match new state management approach

The test setup now initializes searchTokenResult to undefined rather than using separate token data actions, which aligns with the consolidated state management approach.


161-176: Simplified test rendering and element selection

The test now uses screen.getAllByTestId() instead of destructuring from render result, which is a more modern approach and improves readability.


220-220: Updated assertion to check for undefined instead of empty array

The assertion has been updated to check that searchTokenResult is undefined rather than an empty array, which is consistent with the new approach to reset state.

src/apps/token-atlas/reducer/tokenAtlasSlice.ts (3)

22-22: Updated state type to support undefined values

The type for searchTokenResult has been updated to Token[] | undefined, allowing for proper handling of the initial and reset states.


40-40: Updated initial state to undefined

Changed the initial state for searchTokenResult from an empty array to undefined, which better represents the absence of search results before any search is performed.


70-70: Updated action payload type to match state type

The action payload type for setSearchTokenResult now accepts Token[] | undefined, ensuring type safety when updating the state.

src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx (5)

67-67: Updated state selector type to support undefined values

The type for searchTokenResult has been updated to Token[] | undefined, consistent with the changes in the slice files and allowing for proper handling of the initial and reset states.


87-87: Simplified chain selection logic

The chain selection logic has been simplified to use CompatibleChains directly instead of filtering tokens, making the code more maintainable and easier to understand.


108-108: Standardized state reset behavior

The dispatch calls to setSearchTokenResult have been updated to consistently set it to undefined instead of an empty array when a token is selected or the dropdown is closed, aligning with the new state management approach.

Also applies to: 128-128, 168-168


135-151: Improved auto-selection logic with proper null checks

The useEffect conditions now properly check if searchTokenResult is defined before attempting to access its properties, preventing potential runtime errors. The dependency array has also been simplified to include only the necessary dependencies.

This change aligns with our previous learning that in the Exchange app, the token lists are derived from searchTokenResult when search is active, so the dependency array only needs these critical values.


205-234: Improved rendering logic with null-safe checks

The rendering logic now properly handles all states of searchTokenResult (undefined, empty, or populated), improving the user experience with appropriate messages and preventing potential runtime errors.

src/apps/the-exchange/reducer/theExchangeSlice.ts (3)

18-18: Type improvement for search token state

Updating the searchTokenResult type to accept undefined is a good change that more accurately represents the token search state. This distinction between "no results" (empty array) and "not searched yet" (undefined) provides better semantic clarity.


43-43: Initial state now properly reflects unsearched state

Initializing searchTokenResult to undefined instead of an empty array is consistent with the updated type definition and better represents the initial state before any search is performed.


83-83:

Details

❓ Verification inconclusive

Reducer update aligns with state management consolidation

The updated reducer signature now accepts undefined as a valid payload type, which supports the consolidated state management approach mentioned in the PR. This change allows components to explicitly reset the search state when needed.


🏁 Script executed:

#!/bin/bash
# Verify that all components now use the updated reducer signature
# and no references to removed state properties remain

echo "Checking for any remaining references to swapTokenData or receiveTokenData..."
rg -l "swapTokenData|receiveTokenData" --type ts --type tsx

echo "Checking components that use setSearchTokenResult to ensure they pass undefined when appropriate..."
rg -A 2 "setSearchTokenResult\(" --type ts --type tsx

Length of output: 547


Action Required: Pending Manual Verification of File Searches in TS/TSX Files

The revised reducer signature now correctly accepts undefined as a valid payload, supporting state reset as intended. However, the initial automated checks using rg --type tsx failed due to an unrecognized file type. To re-verify that there are no lingering references to removed state properties and that components properly pass undefined, please re-run the following updated shell script:

#!/bin/bash
echo "Checking for any remaining references to swapTokenData or receiveTokenData in TS/TSX files..."
rg -l "swapTokenData|receiveTokenData" -g "*.{ts,tsx}"

echo "Checking components that use setSearchTokenResult to ensure they pass undefined when appropriate..."
rg -A 2 "setSearchTokenResult\(" -g "*.{ts,tsx}"

Once you confirm that these searches return no undesired references and that the usage in components is correct, this will validate the changes.

@github-actions github-actions bot temporarily deployed to Preview (feat/mobula-search-api) April 3, 2025 08:47 Inactive
Copy link
Collaborator

@IAmKio IAmKio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RanaBug RanaBug merged commit 2c9665b into staging Apr 3, 2025
7 checks passed
@coderabbitai coderabbitai bot mentioned this pull request May 5, 2025
3 tasks
@coderabbitai coderabbitai bot mentioned this pull request Aug 12, 2025
3 tasks
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.

2 participants