Skip to content

fix to not allow auto token select if already selected#296

Merged
RanaBug merged 3 commits intostagingfrom
feat/PRO-3162/The-Exchange-changes
May 1, 2025
Merged

fix to not allow auto token select if already selected#296
RanaBug merged 3 commits intostagingfrom
feat/PRO-3162/The-Exchange-changes

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented May 1, 2025

Description

  • fix to not allow auto token select if already selected

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

  • Bug Fixes
    • Improved token selection behavior to prevent automatically selecting a token if it matches the currently selected token in swap or receive mode. This avoids accidental selection of the same token on both sides during swaps.
  • Tests
    • Added a mock for localStorage in the AssetsList test suite to ensure consistent and isolated testing behavior.

@RanaBug RanaBug requested a review from IAmKio May 1, 2025 11:22
@RanaBug RanaBug self-assigned this May 1, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 1, 2025

Walkthrough

This change updates the logic in the DropdownTokenList.tsx component to refine the automatic selection of tokens when there is exactly one search result. The new logic ensures that a token will not be auto-selected if it matches the currently selected opposite token, depending on whether the swap or receive mode is active. This prevents users from inadvertently selecting the same token for both sides of a swap or receive operation.

Additionally, a beforeAll hook was added to the <AssetsList /> test suite to mock the window.localStorage object, ensuring consistent and isolated localStorage behavior during tests.

Changes

File(s) Change Summary
src/apps/the-exchange/components/DropdownTokensList/DropdownTokenList.tsx Refined the conditional logic in a useEffect to prevent auto-selecting a token if it matches the opposite selected token in swap/receive modes.
src/apps/deposit/components/AssetsList/test/AssetsList.test.tsx Added a beforeAll hook to mock window.localStorage with an in-memory implementation for consistent testing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DropdownTokenList
    participant State

    User->>DropdownTokenList: Search for token
    DropdownTokenList->>State: Get search results
    State-->>DropdownTokenList: Return searchResults
    DropdownTokenList->>DropdownTokenList: useEffect checks searchResults
    alt Only one search result
        alt isSwapOpen and receiveToken exists and result ≠ receiveToken
            DropdownTokenList->>DropdownTokenList: Call handleClick(result)
        else isSwapOpen is false and swapToken exists and result ≠ swapToken
            DropdownTokenList->>DropdownTokenList: Call handleClick(result)
        else
            DropdownTokenList->>DropdownTokenList: Do not auto-select
        end
    end
Loading

Possibly related PRs

Suggested reviewers

  • IAmKio
  • vignesha22

Poem

In the dropdown where tokens hop and play,
A clever check keeps twins at bay.
No more swaps with the same old friend,
Each selection now makes better sense.
With logic refined and bugs out of sight,
The exchange grows smarter, hop by byte! 🐇✨


📜 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 7c198f1 and b986020.

⛔ Files ignored due to path filters (1)
  • src/apps/pillarx-app/components/PointsTile/test/__snapshots__/PointsTile.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/apps/deposit/components/AssetsList/test/AssetsList.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint
  • GitHub Check: unit-tests
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
src/apps/deposit/components/AssetsList/test/AssetsList.test.tsx (1)

12-35: Good implementation of localStorage mock for testing!

The localStorage mock implementation is well-structured and correctly implements all required methods of the Storage interface. This will ensure consistent test behavior that doesn't depend on the browser's actual localStorage state.

A few minor suggestions:

  1. Consider adding an afterAll hook to restore the original localStorage implementation to avoid potential side effects on other tests
  2. You might want to add error simulation for quota exceeded scenarios if your app handles those edge cases
// After line 35, you could add:
+ afterAll(() => {
+   // Restore original localStorage if needed
+   jest.restoreAllMocks();
+ });
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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 May 1, 2025

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: b986020
Status: ✅  Deploy successful!
Preview URL: https://c6c7d37a.x-e62.pages.dev
Branch Preview URL: https://feat-pro-3162-the-exchange-c.x-e62.pages.dev

View logs

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

@github-actions github-actions bot temporarily deployed to Preview (feat/PRO-3162/The-Exchange-changes) May 1, 2025 11:45 Inactive
@RanaBug RanaBug merged commit 784cb25 into staging May 1, 2025
7 checks passed
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