Skip to content

Conversation

kushagrasarathe
Copy link
Contributor

@kushagrasarathe kushagrasarathe commented Jun 13, 2025

contributes to TASK-11896 : now fetches usd value for a token and use it in the ui (i dont know what POL/ETH/blah...blah...blah is, show me dollars )

also fixes TASK-11613 : orientation for pwa

Copy link

vercel bot commented Jun 13, 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 Jun 13, 2025 3:27pm

Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

## Walkthrough

This change introduces logic to fetch, store, and display a USD equivalent amount for charges in the payment flow. It updates the Redux payment state, UI components, and related types to support and prioritize USD display when available, including new properties and conditional formatting in transaction and confirmation views.

## Changes

| Files/Paths                                                                 | Change Summary                                                                                                                           |
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| src/app/[...recipient]/client.tsx                                           | Adds logic to fetch/store USD amount for charges, updates hooks and memoization to use USD if available.                                 |
| src/components/Global/TokenSelector/TokenSelector.tsx                       | Ensures chain logo URI is set consistently when token and chain info are present, regardless of wallet connection.                       |
| src/components/Payment/PaymentForm/index.tsx                                | Dispatches USD amount to payment state during payment initiation if input USD value is provided.                                         |
| src/components/Payment/Views/Confirm.payment.view.tsx<br>src/components/Payment/Views/Status.payment.view.tsx | Adds and uses USD amount from payment store for display and transaction details, updates memoization dependencies.                       |
| src/components/TransactionDetails/TransactionDetailsDrawer.tsx               | Prefers displaying transaction amount from USD currency field if present.                                                                |
| src/redux/slices/payment-slice.ts<br>src/redux/types/payment.types.ts       | Adds `usdAmount` property to payment state and type, introduces `setUsdAmount` reducer.                                                  |
| src/services/services.types.ts                                              | Adds `currencyAmount` and `currencyCode` to `TRequestChargeResponse` interface.                                                          |
| src/app/manifest.ts                                                         | Adds `orientation: 'portrait'` property to the manifest return object.                                                                   |

## Possibly related PRs

- [peanutprotocol/peanut-ui#720](https://github.com/peanutprotocol/peanut-ui/pull/720): Both PRs modify payment form logic for handling USD amounts and token prices.
- [peanutprotocol/peanut-ui#852](https://github.com/peanutprotocol/peanut-ui/pull/852): Both PRs extend payment flow components to handle currency amounts, focusing on different currencies and approaches.

## Suggested reviewers

- jjramirezn

📜 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 7fb6466 and 078ad05.

📒 Files selected for processing (1)
  • src/app/manifest.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/app/manifest.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: prettier
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch fix/payment-usd-value
  • Post Copyable Unit Tests in Comment

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 auto-generate unit tests to generate unit tests for 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.

Copy link

@coderabbitai coderabbitai bot added the enhancement New feature or request label Jun 13, 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: 2

🧹 Nitpick comments (5)
src/services/services.types.ts (1)

202-204: Consider grouping currency data into a dedicated object

currencyAmount and currencyCode are added as loose, optional fields. We now have three separate ways to surface “amount” (tokenAmount, currencyAmount, and the nested payments[].paidAmountInRequestedToken). A small typed wrapper (e.g. currency?: { amount: string; code: string }) would:

  • keep related information together
  • avoid param-explosion if more currency attributes appear (symbol, rate, etc.)
  • make downstream discriminated-union checks simpler (if (charge.currency) …).

Refactoring is optional for this PR but will pay off as multi-currency handling grows.

src/components/TransactionDetails/TransactionDetailsDrawer.tsx (1)

135-137: Avoid Number() on unknown string — prefer parseFloat with fallback

Number(transaction.currency.amount) will return NaN for empty string/whitespace, producing "$ 0" after formatAmount, which can silently hide bad data. Consider:

-        : transaction.currency?.amount
-          ? `$ ${formatAmount(Number(transaction.currency.amount))}`
+        : transaction.currency?.amount
+          ? `$ ${formatAmount(parseFloat(transaction.currency.amount) || 0)}`

This still formats correctly but guards against non-numeric strings.

src/components/Payment/Views/Confirm.payment.view.tsx (2)

197-203: Redundant Number() conversion

formatAmount already accepts string | number. Wrapping with Number(...) is unnecessary and can silently coerce ''/null into 0.

-            return `$ ${formatAmount(Number(usdAmount))}`
+            return `$ ${formatAmount(usdAmount)}`

205-209: Return undefined instead of an empty string for optional symbol

Down-stream components can treat '' as a valid value and attempt to render it.
Returning undefined makes the “no-symbol” intent explicit and avoids awkward paddings/spacings.

-            return ''
+            return undefined
src/components/Payment/Views/Status.payment.view.tsx (1)

78-84: Same Number() coercion issue as in Confirm view

-        if (usdAmount) return `$ ${formatAmount(Number(usdAmount))}`
+        if (usdAmount) return `$ ${formatAmount(usdAmount)}`

Keeps behaviour consistent and avoids silent NaN on unexpected input.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e46e91 and 54ad66d.

📒 Files selected for processing (9)
  • src/app/[...recipient]/client.tsx (7 hunks)
  • src/components/Global/TokenSelector/TokenSelector.tsx (1 hunks)
  • src/components/Payment/PaymentForm/index.tsx (1 hunks)
  • src/components/Payment/Views/Confirm.payment.view.tsx (3 hunks)
  • src/components/Payment/Views/Status.payment.view.tsx (5 hunks)
  • src/components/TransactionDetails/TransactionDetailsDrawer.tsx (1 hunks)
  • src/redux/slices/payment-slice.ts (2 hunks)
  • src/redux/types/payment.types.ts (1 hunks)
  • src/services/services.types.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/components/Payment/Views/Confirm.payment.view.tsx (2)
src/redux/hooks.ts (1)
  • usePaymentStore (12-12)
src/utils/general.utils.ts (1)
  • formatAmount (300-340)
src/components/TransactionDetails/TransactionDetailsDrawer.tsx (1)
src/utils/general.utils.ts (1)
  • formatAmount (300-340)
src/components/Payment/Views/Status.payment.view.tsx (3)
src/redux/hooks.ts (1)
  • usePaymentStore (12-12)
src/utils/general.utils.ts (1)
  • formatAmount (300-340)
src/constants/zerodev.consts.ts (1)
  • PEANUT_WALLET_TOKEN_SYMBOL (21-21)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Deploy-Preview
🔇 Additional comments (5)
src/redux/types/payment.types.ts (1)

19-20: Double-check lifecycle of usdAmount

usdAmount is persisted in global state but there is no corresponding reset in paymentActions.reset() (or equivalent clear-flow). A stale USD value could leak into a next transaction if the user navigates back and starts another payment without refreshing.

Action items:

  1. Ensure any “reset / clear” reducer wipes usdAmount.
  2. When the token amount is edited back to zero, dispatch setUsdAmount(null).

Small but prevents subtle display bugs.

src/components/Global/TokenSelector/TokenSelector.tsx (1)

246-247: LGTM – logo now shown for connected-wallet path

Assigning buttonChainLogoURI inside the external-wallet branch fixes the missing chain badge. No issues spotted.

src/redux/slices/payment-slice.ts (1)

24-25: Prefer a numeric type for usdAmount to avoid repeated parsing

usdAmount is stored as a string, yet every consumer immediately converts it using Number(...).
Keeping it as number | null:

  1. Eliminates the double-parsing overhead (NumberformatAmount converts again).
  2. Prevents accidental string concatenation bugs elsewhere in the slice.

Diff illustrating the change in this file:

-    usdAmount: null,
+    usdAmount: null as number | null,
...
-        setUsdAmount: (state, action: PayloadAction<string | null>) => {
+        setUsdAmount: (state, action: PayloadAction<number | null>) => {
             state.usdAmount = action.payload
         },

Types in IPaymentState and every dispatch(paymentActions.setUsdAmount(...)) call would need the same update.
[ suggest_essential_refactor ]

Also applies to: 64-66

src/components/Payment/Views/Status.payment.view.tsx (1)

98-102: amount should mirror raw token amount, not the USD display value

TransactionDetails.amount is later used for analytics / maths.
Storing the fiat value there alters semantics. Consider:

-            amount: usdAmount ? Number(usdAmount) : parseFloat(amountValue),
+            amount: parseFloat(amountValue),

…and rely on the newly-added currency field for the USD representation.

src/app/[...recipient]/client.tsx (1)

282-301: Number(chargeDetails.tokenAmount) multiplied by price loses precision for large token values

tokenAmount is a string that may already be in wei-scaled units depending on upstream service. Consider using a big-number library (e.g. ethers.js’s formatUnits) before the multiplication to avoid precision loss.

(Request verification if the service already returns human-readable decimals).

kushagrasarathe and others added 2 commits June 13, 2025 20:43
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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

🔭 Outside diff range comments (1)
src/app/[...recipient]/client.tsx (1)

115-178: ⚠️ Potential issue

Nested useEffect causes a syntax error & invalid hook usage

useEffect is declared inside an existing useEffect callback (and even in the middle of a .get() call).
React hooks must be invoked at the top level of the component – never conditionally and never nested inside other callbacks.
Besides violating the Rules of Hooks, this leaves the outer chargesApi.get(chargeId) call unfinished, so the file no longer parses (see Biome / formatter failure).

-        if (chargeId) {
-            chargesApi
-                .get(chargeId)
-useEffect(() => {              // ❌ nested hook starts here
-    if (!chargeId) return
+// 1️⃣  Delete the obsolete outer logic (lines 118-178) completely.
+
+// 2️⃣  Keep a single top-level effect:
+
+useEffect(() => {
+    if (!chargeId) return
+
     let stale = false
     ;(async () => {
         try {
             const charge = await chargesApi.get(chargeId)
             dispatch(paymentActions.setChargeDetails(charge))
             …
             if (charge.payments?.length) {
                 const latest = charge.payments.at(-1)
                 if (latest.status !== 'NEW') dispatch(paymentActions.setView('STATUS'))
             }
         } catch (err) {
             if (!stale) setError(getDefaultError(!!user))
         }
     })()
     return () => {
         stale = true
     }
-}, [chargeId, dispatch, user])
-                    // check latest payment status if payments exist
-                    if (charge.payments && charge.payments.length > 0) {
-
-                })
-                .catch((_err) => {
-                    setError(getDefaultError(!!user))
-                })
-        }
-    }, [chargeId, dispatch, user])
+}, [chargeId, dispatch, user])

This restores valid syntax, avoids double-fetching the charge, and still handles the “latest payment status” logic.
Failing to fix this will keep CI red and the page from rendering at all.

🧰 Tools
🪛 Biome (1.9.4)

[error] 172-173: Expected a statement but instead found ')
.catch((_err) =>'.

Expected a statement here.

(parse)


[error] 175-175: Expected a statement but instead found ')'.

Expected a statement here.

(parse)


[error] 177-177: expected , but instead found }

Remove }

(parse)


[error] 173-175: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🪛 GitHub Actions: Code Formatting

[error] 172-172: SyntaxError: Declaration or statement expected at line 172, column 18.

🧹 Nitpick comments (2)
src/app/[...recipient]/client.tsx (2)

130-152: toFixed(2) returns a string – store a number instead

setUsdAmount is fed the string result of Number(...).toFixed(2).
Down-stream consumers treat usdAmount as a numeric quantity (e.g., arithmetic or sorting) this will coerce each time and may bite later.

-    paymentActions.setUsdAmount(Number(charge.currencyAmount).toFixed(2))
+    paymentActions.setUsdAmount(parseFloat(charge.currencyAmount.toString()))

Same change applies to the branch using usdValue.toFixed(2).
Prefer keeping raw numbers in state and format only at render time.


324-325: Minor: amount should remain numeric in currency payload

currency: { amount: usdAmount, code: 'USD' } passes the (string) usdAmount straight into the drawer component.
If you adopt the numeric advice above, wrap it here: amount: usdAmount.toFixed(2). Otherwise leave as is.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 54ad66d and edba34a.

📒 Files selected for processing (3)
  • src/app/[...recipient]/client.tsx (6 hunks)
  • src/components/Payment/Views/Status.payment.view.tsx (4 hunks)
  • src/services/services.types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/services/services.types.ts
  • src/components/Payment/Views/Status.payment.view.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/app/[...recipient]/client.tsx (4)
src/redux/hooks.ts (1)
  • usePaymentStore (12-12)
src/services/charges.ts (1)
  • chargesApi (6-91)
src/redux/slices/payment-slice.ts (1)
  • paymentActions (73-73)
src/app/actions/tokens.ts (1)
  • fetchTokenPrice (59-108)
🪛 Biome (1.9.4)
src/app/[...recipient]/client.tsx

[error] 177-177: expected , but instead found }

Remove }

(parse)


[error] 177-180: Expected a statement but instead found ', [chargeId, dispatch, user])

// fetch requests for the recipient only when id is not available in the URL
useEffect(() =>'.

Expected a statement here.

(parse)

🪛 GitHub Actions: Code Formatting
src/app/[...recipient]/client.tsx

[error] 172-172: SyntaxError: Declaration or statement expected at line 172, column 18.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Deploy-Preview

Copy link

@jjramirezn jjramirezn merged commit f175ce8 into peanut-wallet-dev Jun 16, 2025
5 checks passed
@jjramirezn jjramirezn deleted the fix/payment-usd-value branch June 16, 2025 14:29
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