Skip to content

feat/PRO-3167/buy-button-token-atlas#284

Merged
RanaBug merged 2 commits intostagingfrom
feat/PRO-3167/buy-button-token-atlas
Apr 8, 2025
Merged

feat/PRO-3167/buy-button-token-atlas#284
RanaBug merged 2 commits intostagingfrom
feat/PRO-3167/buy-button-token-atlas

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented Apr 7, 2025

Description

  • Buy button on Token Atlas implementation
  • No apps animation if from apps to another

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 token display in the swapping interface by dynamically fetching token data based on URL inputs.
    • Introduced an interactive button in the token graph, allowing direct navigation to token purchase pages.
    • Improved app transitions with refined animation effects during navigation.
    • Updated default token settings for a more consistent user experience.
    • Added animation state management for a smoother user interface experience in the app.

@RanaBug RanaBug requested a review from IAmKio April 7, 2025 16:25
@RanaBug RanaBug self-assigned this Apr 7, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 7, 2025

Walkthrough

This pull request implements several new features and enhancements across the application. The changes include new token querying functionality in the SwapReceiveCard component, navigation improvements from the TokenGraphColumn, and animations managed via the allowed apps context. In tests, components are now wrapped with appropriate routing and context providers. Additionally, the default token state handling is refined, and the animation behavior across the app is conditionally managed.

Changes

File(s) Change Summary
src/apps/the-exchange/components/SwapReceiveCard/SwapReceiveCard.tsx Added token search functionality using useGetSearchTokensQuery, extracted URL query parameters, processed API responses via convertAPIResponseToTokens, and updated Redux state with setReceiveToken.
src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx Added navigation with useNavigate and integrated useAllowedApps; selected token retrieved from Redux to conditionally render a button that navigates to a token purchase page.
src/apps/token-atlas/components/TokenGraphColumn/test/TokenGraphColumn.test.tsx Wrapped TokenGraphColumn with MemoryRouter and AllowedAppsProvider to provide routing and context during tests.
src/apps/token-atlas/index.tsx Updated the defaultToken address and modified the selected token type to allow undefined. Introduced an effect hook to enforce default token state when needed.
src/components/AppsList.tsx,
src/pages/App/index.tsx,
src/providers/AllowedAppsProvider.tsx
Integrated allowed apps context to manage animation; components now use the isAnimated flag to adjust animation delays and trigger visual feedback using setIsAnimated.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant SRC as SwapReceiveCard Component
    participant API as useGetSearchTokensQuery (API)
    participant CONV as convertAPIResponseToTokens
    participant RS as Redux Store

    U->>SRC: Navigate with URL query parameters
    SRC->>SRC: Extract asset, contractAddress, chainId
    alt Valid token parameters
        SRC->>API: Trigger API call with token query
        API-->>SRC: Return token data
        SRC->>CONV: Convert API response
        CONV-->>SRC: Return formatted token(s)
        SRC->>RS: Dispatch setReceiveToken with first token
    else Missing parameters
        SRC->>SRC: Skip API call
    end
Loading
sequenceDiagram
    participant U as User
    participant AL as AppsList Component
    participant AA as AllowedApps Context
    participant APP as App Component
    participant NAV as useNavigate

    U->>AL: Click on AppListItem
    AL->>AA: Call setIsAnimated(true)
    AL->>APP: Trigger recordPresence action
    APP->>APP: Check isAnimated flag
    alt isAnimated true
        APP->>NAV: Navigate to AnimatedAppTitle with delay
    else
        APP->>NAV: Render component without delay
    end
Loading

Possibly related PRs

Suggested reviewers

  • IAmKio

Poem

I’m a happy little rabbit,
Dancing through the code,
With tokens leap and bounds,
Navigation set to go,
Animation lights all aglow,
Hop along in joyful mode,
CodeRabbit cheers as our code grows!


📜 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 b6b6550 and 758f975.

📒 Files selected for processing (3)
  • src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx (5 hunks)
  • src/apps/token-atlas/components/TokenGraphColumn/test/TokenGraphColumn.test.tsx (3 hunks)
  • src/apps/token-atlas/index.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx
  • src/apps/token-atlas/components/TokenGraphColumn/test/TokenGraphColumn.test.tsx
  • src/apps/token-atlas/index.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 7, 2025

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 758f975
Status: ✅  Deploy successful!
Preview URL: https://aa297ad7.x-e62.pages.dev
Branch Preview URL: https://feat-pro-3167-buy-button-tok.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: 0

🧹 Nitpick comments (3)
src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx (1)

173-186: Well-implemented buy button with proper navigation.

The buy button is conditionally rendered only when token data is available. The button's click handler correctly:

  1. Disables animation when navigating between apps
  2. Uses the selected token's properties to construct the target URL

One suggestion to consider:

Consider adding a loading state or disabling the button while navigation is in progress to prevent multiple clicks:

<button
  type="button"
  className="flex w-fit ml-2 py-3 px-6 text-sm font-semibold uppercase truncate rounded bg-green hover:bg-[#5DE000] text-dark_grey"
+ disabled={isNavigating}
  onClick={() => {
+   setIsNavigating(true);
    setIsAnimated(false);
    navigate(
      `/the-exchange?asset=${selectedToken?.name}&blockchain=${selectedToken?.chainId}&address=${selectedToken?.address}`
    );
  }}
>
  Buy {tokenDataInfo?.symbol}
+ {isNavigating && <span className="ml-2">...</span>}
</button>
src/apps/the-exchange/components/SwapReceiveCard/SwapReceiveCard.tsx (2)

56-62: Good API query implementation with skip condition.

The useGetSearchTokensQuery is well-implemented with:

  1. Appropriate parameters from URL
  2. Smart skip condition to prevent unnecessary API calls

The skip condition logic could be simplified for better readability:

- { skip: (!contractAddress || !asset) && !chainId }
+ { skip: !(contractAddress || asset) || !chainId }

64-75: Good use of useEffect for processing API results.

The effect hook correctly processes the API response and updates the Redux store when search data is available. The dependency array includes all necessary dependencies for proper reactivity.

Consider handling potential errors in the API response and providing a fallback:

useEffect(() => {
  if (!searchData) return;

  const result = convertAPIResponseToTokens(
    searchData?.result?.data as TokenAssetResponse[],
    contractAddress || asset || ''
  );

+ if (result.length === 0) {
+   console.warn('No matching tokens found for the provided criteria');
+   return;
+ }

  // This sets the token results list that will be displayed in the UI
  dispatch(setReceiveToken(result[0]));
  // eslint-disable-next-line react-hooks/exhaustive-deps
}, [asset, contractAddress, searchData]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between db4292f and b6b6550.

⛔ 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/token-atlas/components/TokenGraphColumn/test/__snapshots__/TokenGraphColumn.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • src/apps/the-exchange/components/SwapReceiveCard/SwapReceiveCard.tsx (3 hunks)
  • src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx (5 hunks)
  • src/apps/token-atlas/components/TokenGraphColumn/test/TokenGraphColumn.test.tsx (3 hunks)
  • src/apps/token-atlas/index.tsx (3 hunks)
  • src/components/AppsList.tsx (2 hunks)
  • src/pages/App/index.tsx (5 hunks)
  • src/providers/AllowedAppsProvider.tsx (3 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
src/apps/token-atlas/index.tsx (2)
src/apps/token-atlas/types/types.tsx (1)
  • SelectedTokenType (14-22)
src/apps/token-atlas/reducer/tokenAtlasSlice.ts (1)
  • setSelectedToken (73-78)
src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx (2)
src/apps/token-atlas/hooks/useReducerHooks.tsx (1)
  • useAppSelector (6-6)
src/apps/token-atlas/types/types.tsx (1)
  • SelectedTokenType (14-22)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (22)
src/pages/App/index.tsx (5)

7-8: Clean import organization.

The import for useAllowedApps hook is nicely organized in its own "hooks" section, maintaining code readability.


63-63: Well-implemented animation control.

The isAnimated flag from the useAllowedApps hook is properly destructured and used consistently throughout the component to control animation behavior.


80-80: Good conditional animation timing.

The animation delay is now conditionally set based on the isAnimated state, ensuring smooth transitions between apps when desired while eliminating delays when moving directly between applications.


89-89: Consistent animation timing control.

The timeout for the lazy-loaded component is now synchronized with the animation state, maintaining consistency with the spring animation delay.


100-102: Appropriate conditional rendering.

The AnimatedAppTitle fallback is now only rendered when animations are enabled, preventing unnecessary visual elements when animations are disabled.

src/components/AppsList.tsx (2)

30-30: Animation control implementation.

The setIsAnimated function is correctly destructured from the useAllowedApps hook, enabling animation state management from the AppsList component.


85-85: Animation enabled on explicit navigation.

Setting isAnimated to true when a user clicks on an app is the correct behavior - users expect visual feedback when explicitly navigating between applications.

src/apps/token-atlas/index.tsx (3)

39-39: Default token address specified.

Setting an explicit PLR token address in the defaultToken object improves functionality by ensuring the token has a valid Ethereum address rather than an empty string.


59-59: Type safety improvement.

The type assertion for selectedToken now properly handles undefined values, which aligns with how the token selector works in the Redux store.


168-174:

Details

❓ Verification inconclusive

Potential infinite loop risk in useEffect.

This useEffect hook might cause an infinite loop if reference equality checks don't work as expected. The condition selectedToken === defaultToken checks for reference equality, and dispatching setSelectedToken(defaultToken) could create a new reference in the Redux store.


🏁 Script executed:

#!/bin/bash
# Checking the implementation of setSelectedToken reducer to understand reference equality behavior

# First, look at the reducer implementation
rg -A 5 "setSelectedToken.*PayloadAction" --type ts

Length of output: 53


Verify Reducer Implementation for setSelectedToken

The useEffect hook at lines 168–174 could potentially trigger an infinite loop if dispatching setSelectedToken(defaultToken) creates a new reference rather than preserving the original one. The initial grep search for the reducer’s implementation was inconclusive. Please manually verify that the setSelectedToken reducer (likely defined in your token slice) returns the identical defaultToken reference. If a new reference is created on dispatch, consider one of these adjustments:

  • Use a deep equality check in the useEffect condition.
  • Modify the reducer to ensure the same reference is returned when setting the default token.
src/apps/token-atlas/components/TokenGraphColumn/test/TokenGraphColumn.test.tsx (2)

2-2: Test environment properly configured.

Adding MemoryRouter and AllowedAppsProvider imports ensures the test has access to the necessary context providers.

Also applies to: 9-10


74-78: Tests updated to match component dependencies.

The test renderer now properly wraps the TokenGraphColumn component with both MemoryRouter and AllowedAppsProvider, ensuring it has access to routing and animation context. This is essential for components that depend on these contexts to function correctly.

Also applies to: 89-93

src/providers/AllowedAppsProvider.tsx (4)

12-13: Good addition of animation control to the AllowedAppsContext.

The new properties isAnimated and setIsAnimated in the AllowedAppsContextProps interface are well-defined with appropriate types. This addition enables animation control across components that consume this context.


27-27: Proper state initialization.

The isAnimated state is correctly initialized with a default value of false. This is appropriate as animations should be opt-in rather than enabled by default.


72-73: Correctly exposing animation state through context.

Good job exposing both the isAnimated state and setIsAnimated function through the context. This allows consumer components to both read and modify the animation state.


75-75: Updated dependency array appropriately.

The dependency array for useMemo now includes isAnimated, ensuring that the context value will update whenever the animation state changes. This is essential for proper reactivity.

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

3-3: Good addition of necessary imports.

The imports for useNavigate and useAllowedApps are appropriate for implementing the new navigation functionality while controlling animation states between app transitions.

Also applies to: 6-6


44-45: Proper hook initialization.

The useNavigate hook is correctly initialized, and the setIsAnimated function is properly extracted from the useAllowedApps hook, following React's best practices for hooks usage.


56-58: Good Redux state selection.

The selectedToken selector is properly implemented to retrieve the current token information from Redux state, with appropriate type handling for possibly undefined values.

src/apps/the-exchange/components/SwapReceiveCard/SwapReceiveCard.tsx (3)

2-5: Good reorganization of imports.

The imports are properly organized with React hooks separated from services. The addition of useEffect is necessary for the new token query functionality.


13-14: Appropriate Redux imports.

The addition of setReceiveToken action creator and useAppDispatch hook is necessary for updating the Redux store with the token data fetched from the API.

Also applies to: 17-17


49-54: Well-implemented URL parameter parsing.

This code correctly extracts the query parameters from the URL which will enable the component to fetch and display the appropriate token when navigated from the Token Atlas page.

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-3167/buy-button-token-atlas) April 8, 2025 04:27 Inactive
@github-actions github-actions bot temporarily deployed to Preview (feat/PRO-3167/buy-button-token-atlas) April 8, 2025 08:16 Inactive
@github-actions github-actions bot temporarily deployed to Preview (feat/PRO-3167/buy-button-token-atlas) April 8, 2025 08:19 Inactive
@RanaBug RanaBug merged commit 470fea3 into staging Apr 8, 2025
7 checks passed
@coderabbitai coderabbitai bot mentioned this pull request May 5, 2025
3 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 19, 2025
3 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jan 7, 2026
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