Skip to content

feat: add redirect logic on landing page#1323

Merged
Zishan-7 merged 1 commit intopeanut-wallet-devfrom
fix/exchange-widget-lp
Oct 14, 2025
Merged

feat: add redirect logic on landing page#1323
Zishan-7 merged 1 commit intopeanut-wallet-devfrom
fix/exchange-widget-lp

Conversation

@Zishan-7
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Oct 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
peanut-wallet Ready Ready Preview Comment Oct 14, 2025 7:41am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Refactors exchange-rate CTA navigation: replaces inline multi-branch logic in two components with a shared utility getExchangeRateWidgetRedirectRoute, integrates wallet balance formatting and auth checks in LandingPage NoFees component, and adds a new routing utility that computes redirect routes based on currency pairs and balance.

Changes

Cohort / File(s) Summary of changes
Exchange-rate CTA refactor (mobile UI)
src/app/(mobile-ui)/profile/exchange-rate/page.tsx
Replaced conditional redirect branches with getExchangeRateWidgetRedirectRoute and a single router.push; added formatted balance computation and utility import.
LandingPage NoFees: auth/balance-driven CTA
src/components/LandingPage/noFees.tsx
Added wallet/auth context usage, balance fetch effect, and handleCtaAction that formats balance and routes via getExchangeRateWidgetRedirectRoute; updated CTA to use new handler.
Routing utility for exchange-rate widget
src/utils/exchangeRateWidget.utils.ts
Added getExchangeRateWidgetRedirectRoute to compute redirect route based on currency pair and balance using countryCurrencyMappings; handles multiple USD/non-USD cases and assembles final route.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • kushagrasarathe
  • Hugo0

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning No pull request description was provided, so there is no contextual information about the goals or rationale behind the changes beyond the diff itself. Please add a description summarizing the purpose of these changes and how they affect the landing page behavior as well as the new redirect utility to help reviewers understand the intent.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title concisely states that redirect logic is being added to the landing page, which aligns with a significant aspect of the changeset involving handleCtaAction updates in noFees.tsx and the new redirect utility; it is clear and focused without unnecessary detail.
✨ 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/exchange-widget-lp

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.

@coderabbitai coderabbitai bot added the enhancement New feature or request label Oct 14, 2025
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

♻️ Duplicate comments (1)
src/components/LandingPage/noFees.tsx (1)

27-27: Inefficient balance conversion chain.

Same issue as in the profile page: converting bigint → string → number via parseFloat(printableUsdc(...)) is inefficient.

Apply the same refactor suggested for src/app/(mobile-ui)/profile/exchange-rate/page.tsx at line 17: create a dedicated conversion utility to convert bigint directly to number without the intermediate string formatting.

🧹 Nitpick comments (4)
src/utils/exchangeRateWidget.utils.ts (2)

11-41: Refactor to use if-else-if chain and remove redundant assignments.

The current implementation has several issues:

  • All conditions are evaluated sequentially even though they're mutually exclusive
  • Cases 1 and 3 redundantly reassign route = '/add-money' when it's already the default
  • The logic would be clearer and more efficient with an if-else-if chain

Apply this diff to improve the control flow:

     // Case 1: source currency is not usd and destination currency is usd -> redirect to add-money/sourceCurrencyCountry page
     if (sourceCurrency !== 'USD' && destinationCurrency === 'USD') {
         countryPath = countryCurrencyMappings.find((currency) => currency.currencyCode === sourceCurrency)?.path
-        route = '/add-money'
-    }
-
-    // Case 2: source currency is usd and destination currency is not usd -> redirect to withdraw/destinationCurrencyCountry page
-    if (sourceCurrency === 'USD' && destinationCurrency !== 'USD') {
+    } else if (sourceCurrency === 'USD' && destinationCurrency !== 'USD') {
+        // Case 2: source currency is usd and destination currency is not usd -> redirect to withdraw/destinationCurrencyCountry page
         // if there is no balance, redirect to add-money
         if (userBalance <= 0) {
             countryPath = countryCurrencyMappings.find((currency) => currency.currencyCode === sourceCurrency)?.path
-            route = '/add-money'
         } else {
             countryPath = countryCurrencyMappings.find(
                 (currency) => currency.currencyCode === destinationCurrency
             )?.path
             route = '/withdraw'
         }
-    }
-
-    // Case 3: source currency is not usd and destination currency is not usd -> redirect to add-money/sourceCurrencyCountry page
-    if (sourceCurrency !== 'USD' && destinationCurrency !== 'USD') {
+    } else if (sourceCurrency !== 'USD' && destinationCurrency !== 'USD') {
+        // Case 3: source currency is not usd and destination currency is not usd -> redirect to add-money/sourceCurrencyCountry page
         countryPath = countryCurrencyMappings.find((currency) => currency.currencyCode === sourceCurrency)?.path
-        route = '/add-money'
-    }
-
-    // Case 4: source currency is usd and destination currency is usd
-    if (sourceCurrency === 'USD' && destinationCurrency === 'USD') {
+    } else {
+        // Case 4: source currency is usd and destination currency is usd
         countryPath = countryCurrencyMappings.find((currency) => currency.currencyCode === 'USD')?.path
         route = userBalance <= 0 ? '/add-money' : '/withdraw'
     }

43-49: Simplify route construction and fix falsy check.

The current code has unnecessary intermediate variables and doesn't properly handle the empty string case for countryPath.

Apply this diff to simplify:

-    if (!countryPath) {
-        const redirectRoute = `${route}?currencyCode=EUR`
-        return redirectRoute
-    } else {
-        const redirectRoute = `${route}/${countryPath}`
-        return redirectRoute
-    }
+    return countryPath ? `${route}/${countryPath}` : `${route}?currencyCode=EUR`
src/app/(mobile-ui)/profile/exchange-rate/page.tsx (1)

17-17: Inefficient balance conversion chain.

Converting bigint → string → number via parseFloat(printableUsdc(...)) is inefficient and can introduce precision issues. The printableUsdc function formats the number to 2 decimal places as a string, then parseFloat converts it back to a number.

Consider creating a dedicated conversion utility or directly converting bigint to number:

const formattedBalance = Number(formatUnits(balance ?? 0n, PEANUT_WALLET_TOKEN_DECIMALS))

Or add a new utility in balance.utils.ts:

export const balanceToNumber = (balance: bigint): number => {
    return Number(formatUnits(balance, PEANUT_WALLET_TOKEN_DECIMALS))
}

Then use:

const formattedBalance = balanceToNumber(balance ?? 0n)
src/components/LandingPage/noFees.tsx (1)

43-47: Add fetchBalance to the dependency array.

The fetchBalance function should be included in the dependency array to satisfy React's exhaustive-deps rule, even though it's likely stable from the hook.

Apply this diff:

     useEffect(() => {
         if (user) {
             fetchBalance()
         }
-    }, [user])
+    }, [user, fetchBalance])
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06dc5c0 and 6c28cff.

📒 Files selected for processing (3)
  • src/app/(mobile-ui)/profile/exchange-rate/page.tsx (2 hunks)
  • src/components/LandingPage/noFees.tsx (3 hunks)
  • src/utils/exchangeRateWidget.utils.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/app/(mobile-ui)/profile/exchange-rate/page.tsx (2)
src/utils/balance.utils.ts (1)
  • printableUsdc (32-38)
src/utils/exchangeRateWidget.utils.ts (1)
  • getExchangeRateWidgetRedirectRoute (3-50)
src/components/LandingPage/noFees.tsx (4)
src/hooks/wallet/useWallet.ts (1)
  • useWallet (14-98)
src/context/authContext.tsx (1)
  • useAuth (191-197)
src/utils/balance.utils.ts (1)
  • printableUsdc (32-38)
src/utils/exchangeRateWidget.utils.ts (1)
  • getExchangeRateWidgetRedirectRoute (3-50)
src/utils/exchangeRateWidget.utils.ts (1)
src/constants/countryCurrencyMapping.ts (1)
  • countryCurrencyMappings (10-48)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Deploy-Preview
🔇 Additional comments (1)
src/components/LandingPage/noFees.tsx (1)

22-31: LGTM! Auth check prevents unauthorized access.

The authentication check before routing is a good practice, ensuring unauthenticated users are redirected to setup.

@Zishan-7 Zishan-7 merged commit 971e702 into peanut-wallet-dev Oct 14, 2025
5 checks passed
@Zishan-7 Zishan-7 deleted the fix/exchange-widget-lp branch October 14, 2025 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants