Skip to content

fix: claim cta changes on navigation b/w intial and confirm view#696

Merged
jjramirezn merged 1 commit intodevelopfrom
fix/claim-cta-on-navigation
Feb 19, 2025
Merged

fix: claim cta changes on navigation b/w intial and confirm view#696
jjramirezn merged 1 commit intodevelopfrom
fix/claim-cta-on-navigation

Conversation

@kushagrasarathe
Copy link
Copy Markdown
Contributor

@kushagrasarathe kushagrasarathe commented Feb 18, 2025

fixes TASK-8847 where claim cta would change when navigating b/w views in claim flow, now fixed it to be consitent

Summary by CodeRabbit

  • New Features
    • Introduced enhanced support for cross-chain transactions, providing dynamic UI feedback and updated route information based on user selections.
    • Improved back navigation to reset selections and ensure accurate display of transaction details.
  • Refactor
    • Streamlined the decision logic for managing transaction states, resulting in smoother user interactions and more consistent state transitions.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
peanut-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 18, 2025 10:50am

@notion-workspace
Copy link
Copy Markdown

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 18, 2025

Walkthrough

This pull request introduces updates to two claim link components. In the InitialClaimLinkView, a new constant isCrossChainTransaction is added to determine if the transaction is cross-chain by comparing the selected chain and token with the claim link data. The component’s logic is refactored to use this constant for route fetching and UI updates. Meanwhile, the ConfirmClaimLinkView now accepts additional props (setSelectedRoute and setHasFetchedRoute) and includes a dedicated function to handle back navigation by resetting related states before invoking the previous action.

Changes

File(s) Change Summary
src/components/Claim/Link/Initial.view.tsx Added a new constant isCrossChainTransaction to check chain/token differences, refactored UI rendering and state/reset logic, and adjusted error/loading state management.
src/components/Claim/Link/Onchain/Confirm.view.tsx Extended component props to include setSelectedRoute and setHasFetchedRoute, added handleGoBack for back navigation (resetting state and invoking onPrev), updating click logic.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant ICV as InitialClaimLinkView
    participant Router as Route Manager

    User->>ICV: Select chain & token
    ICV->>ICV: Evaluate isCrossChainTransaction
    alt Cross-chain transaction
        ICV->>Router: Reset selected route & update state
    else Same-chain transaction
        ICV->>Router: Maintain current route
    end
    User->>ICV: Click claim button
Loading
sequenceDiagram
    participant User as User
    participant CCV as ConfirmClaimLinkView
    participant State as App State

    User->>CCV: Click "Go Back" button
    CCV->>CCV: Execute handleGoBack (reset selectedRoute, setHasFetchedRoute false)
    CCV->>State: Invoke onPrev callback
Loading

Possibly related PRs

Suggested reviewers

  • Hugo0
  • jjramirezn

Poem

Hop along, I'm a coding rabbit so spry,
With cross-chain checks that catch the eye.
Routes reset with a gentle bounce,
Back navigation makes the logic pounce.
Here's to clear code in every line—
A happy hop on updates divine! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Beta)
  • @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.

Copy link
Copy Markdown
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/components/Claim/Link/Initial.view.tsx (3)

398-403: Consider reusing the existing chain and token comparison.

The isCrossChainTransaction logic duplicates the inverse of isSameChainAndToken. Consider refactoring to reuse the existing comparison:

-const isCrossChainTransaction = useMemo(() => {
-    return (
-        selectedChainID !== claimLinkData.chainId ||
-        !areTokenAddressesEqual(selectedTokenAddress, claimLinkData.tokenAddress)
-    )
-}, [selectedChainID, selectedTokenAddress, claimLinkData.chainId, claimLinkData.tokenAddress])
+const isCrossChainTransaction = useMemo(() => !isSameChainAndToken, [isSameChainAndToken])

406-418: Add error handling for route fetching.

While the effect correctly manages states, it should handle potential errors from fetchRoute:

useEffect(() => {
    if (isCrossChainTransaction && !selectedRoute && !isXchainLoading) {
        setIsXchainLoading(true)
        setLoadingState('Fetching route')
        setHasFetchedRoute(true)
        setErrorState({
            showError: false,
            errorMessage: '',
        })

-        fetchRoute()
+        fetchRoute().catch((error) => {
+            console.error('Error fetching route:', error)
+            setErrorState({
+                showError: true,
+                errorMessage: 'Failed to fetch route. Please try again.',
+            })
+        })
    }
}, [isCrossChainTransaction])

495-529: Consider extracting route display into a separate component.

The route display logic is complex and could benefit from being extracted into a reusable component:

// RouteDisplay.tsx
interface RouteDisplayProps {
    selectedRoute: any
    isXchainLoading: boolean
    claimLinkData: any
    supportedSquidChainsAndTokens: any
    supportedPeanutChains: any
}

const RouteDisplay: React.FC<RouteDisplayProps> = ({
    selectedRoute,
    isXchainLoading,
    claimLinkData,
    supportedSquidChainsAndTokens,
    supportedPeanutChains,
}) => {
    if (isXchainLoading || !selectedRoute) {
        return <div className="h-2 w-12 animate-colorPulse rounded bg-slate-700"></div>
    }

    const fromChain = supportedPeanutChains.find(
        (chain) => chain.chainId === selectedRoute.route.params.fromChain
    )?.name
    const toChain = supportedSquidChainsAndTokens[selectedRoute.route.params.toChain]?.axelarChainName

    return (
        <>
            {fromChain}
            <Icon name={'arrow-next'} className="h-4 fill-gray-1" />
            {toChain}
            <MoreInfo
                text={`You are bridging ${claimLinkData.tokenSymbol.toLowerCase()} on ${fromChain} to ${selectedRoute.route.estimate.toToken.symbol.toLowerCase()} on ${toChain}.`}
            />
        </>
    )
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 671715d and 4f12270.

📒 Files selected for processing (2)
  • src/components/Claim/Link/Initial.view.tsx (6 hunks)
  • src/components/Claim/Link/Onchain/Confirm.view.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: prettier
🔇 Additional comments (5)
src/components/Claim/Link/Onchain/Confirm.view.tsx (3)

28-29: LGTM! Props addition for route state management.

The new props setSelectedRoute and setHasFetchedRoute are correctly added to manage route state during back navigation.


102-108: LGTM! Clean implementation of back navigation logic.

The handleGoBack function follows the single responsibility principle by encapsulating the route state reset logic. It correctly checks for selectedRoute existence before resetting the state, preventing potential issues with stale route data.


261-264: LGTM! Button implementation with proper state handling.

The back button correctly uses the new handleGoBack function while maintaining loading state handling and dark mode styling.

src/components/Claim/Link/Initial.view.tsx (2)

295-308: LGTM! Clear and maintainable chain and token comparison.

The refactored code improves readability by using a descriptive variable name isSameChainAndToken. The reset logic is correctly applied with helpful comments.


572-572: LGTM! Button logic correctly handles cross-chain scenarios.

The button logic correctly uses isCrossChainTransaction for navigation and properly disables the button when a route is required but not available.

Also applies to: 586-586

Copy link
Copy Markdown
Contributor

@jjramirezn jjramirezn left a comment

Choose a reason for hiding this comment

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

Looks good

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