Skip to content

fix: cashout on peanut wallet#646

Merged
jjramirezn merged 2 commits intopeanut-walletfrom
fix/wallet-cashout
Jan 27, 2025
Merged

fix: cashout on peanut wallet#646
jjramirezn merged 2 commits intopeanut-walletfrom
fix/wallet-cashout

Conversation

@kushagrasarathe
Copy link
Copy Markdown
Contributor

@kushagrasarathe kushagrasarathe commented Jan 24, 2025

  • updated cashout kyc flow to work on peanut wallet
  • updated wallet header component to handle wallet selection if no external wallet is connected
  • some minor ui fxies in kyc flow

fixes TASK-8306
fixes TASK-8305

Summary by CodeRabbit

Release Notes

  • New Features

    • Added optional fullName property to user update functionality.
    • Introduced new KYC status type with more granular status tracking.
  • User Experience Improvements

    • Streamlined KYC and user registration process by replacing registration components with update functionality.
    • Updated wallet selection and connection logic to ensure valid wallet selection.
    • Enhanced error handling for offramp and user interactions, providing clearer feedback.
  • Bug Fixes

    • Improved validation for wallet connection status.
  • Refactoring

    • Removed deprecated registration components.
    • Updated component naming and import structures.
    • Simplified state management in various components.

- updated cashout kyc flow
- updated wallet header component to handle wallet selection if no external wallet is connected
- some minor ui fxies in kyc flow
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 24, 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 Jan 24, 2025 11:17am

@kushagrasarathe kushagrasarathe requested a review from Hugo0 January 24, 2025 11:06
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

This pull request introduces several changes across multiple components and utilities, primarily focusing on user data management, KYC status handling, and component restructuring. The changes involve updating user-related interfaces, modifying component rendering logic, and refining type definitions. Key modifications include introducing a fullName property, replacing registration components with update user components, and standardizing KYC status handling across different parts of the application.

Changes

File Change Summary
src/app/api/peanut/user/update-user/route.ts Added optional fullName to UserPayload type
src/components/Cashout/Components/Initial.view.tsx Renamed web3modalOpen to appkitModal
src/components/Global/IframeWrapper/index.tsx Added KYCStatus import and typed kycStatus
src/components/Global/KYCComponent/index.tsx Replaced GlobalRegisterComponent with UpdateUserComponent
src/components/Global/LinkAccountComponent/index.tsx Added KYCComponent import
src/components/Global/UpdateUserComponent/index.tsx Refactored component for user detail updates
src/components/Global/WalletHeader/index.tsx Added IDBWallet interface
src/components/Kyc/index.tsx Simplified component logic and navigation
src/components/Profile/Components/SkeletonPage.tsx Replaced GlobalRegisterComponent with UpdateUserComponent
Removed files src/components/Register/index.tsx, removed export from src/components/index.ts
src/constants/index.ts Updated exports
src/interfaces/interfaces.ts Updated User interface with KYCStatus
src/utils/cashout.utils.ts Added KYCStatus type and fetchRouteRaw function

Sequence Diagram

sequenceDiagram
    participant User
    participant UpdateUserComponent
    participant API
    
    User->>UpdateUserComponent: Provide user details
    UpdateUserComponent->>API: Submit user update request
    alt Successful Update
        API-->>UpdateUserComponent: Update confirmed
        UpdateUserComponent-->>User: Display success message
    else Update Failed
        API-->>UpdateUserComponent: Return error
        UpdateUserComponent-->>User: Display error message
    end
Loading

Possibly related PRs

Suggested reviewers

  • jjramirezn

Poem

🐰 A Rabbit's Tale of Code Delight

Refactoring users with all my might,
Components dance, types take flight,
KYC status shines so bright,
From register to update, we set things right!

Hop, hop, hooray! 🎉


📜 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 0602a6b and 663add5.

📒 Files selected for processing (1)
  • src/components/Kyc/index.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Kyc/index.tsx

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.

@notion-workspace
Copy link
Copy Markdown

@notion-workspace
Copy link
Copy Markdown

@kushagrasarathe kushagrasarathe requested review from jjramirezn and removed request for Hugo0 January 24, 2025 11:06
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: 2

🔭 Outside diff range comments (1)
src/utils/cashout.utils.ts (1)

Line range hint 324-351: Watch out for potential precision loss
Using Number(tokenAmount) might introduce floating-point inaccuracies for large values. Consider a library like decimal.js to handle big number arithmetic more reliably or parse the string carefully to avoid precision loss.

🧹 Nitpick comments (5)
src/components/Kyc/index.tsx (1)

10-10: Ensure robust handling of null or incomplete user objects.
While this hook usage looks simple, consider adding a fallback or defensive checks for edges cases (e.g., user object is undefined).

src/app/api/peanut/user/update-user/route.ts (1)

17-17: Check for consistent naming convention.
You are mixing bridge_customer_id with pushSubscriptionId and fullName. Consider staying consistent (e.g., always snake_case or camelCase) for better clarity.

src/components/Global/UpdateUserComponent/index.tsx (2)

6-13: Consider removing the unused password property.
It appears the password field is no longer part of the form. If you are no longer collecting or using passwords, removing the optional password property would simplify the interface.

 interface IUpdateUserComponentProps {
     userId?: string
     name?: string
     email?: string
-    password?: string
     onSubmit?: ({ status, message }: { status: 'success' | 'error' | 'login'; message: string }) => void
 }

40-78: Handle response data or confirm no data usage.
The API response JSON is parsed but not used for any logic beyond status checks. Ensure there is no relevant data you might need to handle or display (e.g., updated user details).

 const handleOnSubmit = async (data: IForm) => {
    try {
        setLoadingState('Submitting details')
        const response = await fetch('/api/peanut/user/update-user', {
            ...
        })
-       await response.json()
+       const responseData = await response.json()
+       // If needed, handle responseData to confirm that the updated user data was saved
        ...
    } catch (error) {
        ...
    }
}
src/components/Global/LinkAccountComponent/index.tsx (1)

112-112: Simplify conditional check
You can unify the condition to if (user?.user?.kycStatus !== 'approved') for a more concise approach.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66fee2d and 0602a6b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • src/app/api/peanut/user/update-user/route.ts (2 hunks)
  • src/components/Cashout/Components/Initial.view.tsx (4 hunks)
  • src/components/Global/IframeWrapper/index.tsx (2 hunks)
  • src/components/Global/KYCComponent/index.tsx (5 hunks)
  • src/components/Global/LinkAccountComponent/index.tsx (3 hunks)
  • src/components/Global/UpdateUserComponent/index.tsx (2 hunks)
  • src/components/Global/WalletHeader/index.tsx (2 hunks)
  • src/components/Kyc/index.tsx (2 hunks)
  • src/components/LinkAccount/index.tsx (1 hunks)
  • src/components/Offramp/Confirm.view.tsx (1 hunks)
  • src/components/Profile/Components/SkeletonPage.tsx (2 hunks)
  • src/components/Register/index.tsx (0 hunks)
  • src/components/index.ts (0 hunks)
  • src/constants/index.ts (1 hunks)
  • src/hooks/wallet/useWallet.ts (1 hunks)
  • src/interfaces/interfaces.ts (2 hunks)
  • src/utils/cashout.utils.ts (2 hunks)
💤 Files with no reviewable changes (2)
  • src/components/index.ts
  • src/components/Register/index.tsx
🔇 Additional comments (33)
src/constants/index.ts (2)

4-4: Good addition of loadingStates.consts export.
Consolidating loading states under a single export can simplify state tracking across the application.


1-1: Confirm usage of cashout.consts export.
Please verify that cashout.consts is still needed, as it may conflict with the PR's goal of deprecating or revising old cashout constants.

✅ Verification successful

cashout.consts exports are actively used and maintained
The constants defined in this file are currently used across multiple components (Cashout, Claim, KYC) and contain up-to-date configurations for modern chains and tokens. These exports should be retained.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search the codebase for references to cashout.consts
rg "cashout\.consts" -A 5

Length of output: 312


Script:

#!/bin/bash
# View content of cashout.consts
cat src/constants/cashout.consts.ts

Length of output: 2343


Script:

#!/bin/bash
# Search for usage of the exported constants
rg "supportedBridgeChainsDictionary|supportedBridgeTokensDictionary|IOfframpForm" -l

Length of output: 375

src/components/Kyc/index.tsx (2)

31-32: Looks good.
Linking to the /cashout route after successful KYC is intuitive for the user.


23-23: Verify consistent usage of 'approved' across the codebase.
Previously, many components relied on 'verified'. Confirm all references match the new KYC status to avoid inconsistent flows.

src/app/api/peanut/user/update-user/route.ts (1)

13-13: Optional fullName field is a useful addition.
This adds flexibility to storing user data. Make sure you're handling undefined cases gracefully in the downstream code.

src/components/LinkAccount/index.tsx (1)

58-58: Confirm fallback KYC statuses.
If the user’s status can be something other than 'approved' or 'rejected', ensure all statuses are handled. Enumerating them in a constant or type guard will reduce confusion.

src/components/Global/UpdateUserComponent/index.tsx (3)

14-18: Confirm if userId should be required in the form.
The userId prop is optional in IUpdateUserComponentProps, but here, the form captures only name and email. If updating requires a user identifier, consider adding it to IForm, or make userId required to ensure clarity.


19-39: Great rename reflecting updated functionality.
Renaming to UpdateUserComponent aligns with the shift from registration to user updates. The new component structure is clear and coherent.


124-124: Button label consistency.
“Submit details” is clear and reflects the update operation. This is consistent with the new purpose of the component.

src/components/Global/IframeWrapper/index.tsx (2)

1-2: Explicit import is correct.
Importing KYCStatus clarifies intended usage and improves type safety.


55-55: Good addition of strong typing.
Typing kycStatus as KYCStatus helps enforce valid status values and reduces runtime errors.

src/hooks/wallet/useWallet.ts (1)

44-44: Enhanced check for wallet presence.
This additional check ensures the logic only proceeds when both wagmiAddress and wallet are defined, preventing potential runtime errors.

src/interfaces/interfaces.ts (1)

1-1: Consistent KYC status typing.
Importing KYCStatus and assigning it to kycStatus in the User interface promotes uniformity and reliability across the codebase.

Also applies to: 352-352

src/components/Global/WalletHeader/index.tsx (3)

8-8: New interface import looks consistent

This import introduces IDBWallet for specialized wallet usage. Ensure type overlaps with IWallet are kept minimal to avoid confusion.


43-46: Validating wallet selection logic

Restricting selected wallets to Peanut or connected external wallets is a good safeguard, preventing the user from unknowingly selecting an unconnected wallet.


49-71: Ensures a valid default wallet selection

The fallback logic to automatically select a connected external wallet, or a Peanut wallet if no external wallet is connected, is well-structured to maintain a valid wallet state at all times. Consider adding tests to confirm that no infinite re-render cycles occur when the selected wallet changes rapidly.

src/components/Profile/Components/SkeletonPage.tsx (2)

4-4: Properly replacing registration import

UpdateUserComponent import aligns with the shift to user updates. Looks good.


161-161: Successful transition from registration to update user flow

Replacing the old registration component with UpdateUserComponent streamlines the UI. Ensure that any underlying registration logic is updated or removed where necessary around this integration.

src/components/Global/KYCComponent/index.tsx (5)

17-17: Introducing the new user update component

Importing UpdateUserComponent for KYC flow is consistent with the broader refactor.


326-326: Seamless user data submission within KYC

UpdateUserComponent is invoked correctly for collecting user info before stepping through KYC. The callback logic for handling success or errors is straightforward.


391-391: KYC process step logic looks fine

The button to open or reopen KYC is clearly presented. Consider verifying whether repeated KYC submissions or partial completions can cause any race conditions.


412-415: Clear UI text for KYC process

Outlining the KYC purpose and regulatory requirements provides a good user experience.


440-440: Decoupled rendering container

Wrapping {renderComponent()} inside a dedicated container helps keep styling consistent and maintainable.

src/components/Cashout/Components/Initial.view.tsx (4)

82-82: Refined modal management with appkit

Renaming to appkitModal clarifies the source of the modal, improving overall readability. Confirm that older signInModal references are either removed or replaced where appropriate.


279-279: Graceful fallback to appkit modal

Using appkitModal() for unconnected states simplifies your logic. Consider verifying that the user is prompted with the correct flow once the modal is closed.


295-295: User prompt for buying tokens

appkitModal() triggers the wallet connection before token purchase—this helps ensure a consistent user experience.


428-428: Consolidated connection handling

If an external wallet is not connected but the user is on a Peanut wallet, triggers a different login flow before proceeding. This is a logical approach to unify all connection states.

src/utils/cashout.utils.ts (3)

2-2: Looks Good
No issues with these import changes.

Also applies to: 4-4


134-135: Strong typing for KYC
Using a union type for KYC phases enhances clarity and maintainability.


143-143: Refined type usage
Switching kyc_status to use the KYCStatus type ensures consistency throughout the codebase.

src/components/Global/LinkAccountComponent/index.tsx (2)

5-5: Import statement
Importing KYCComponent directly is straightforward and aligns with the file’s usage.


625-625: Streamlined KYC flow
Displaying the <KYCComponent /> directly when KYC is not yet approved simplifies the user experience.

src/components/Offramp/Confirm.view.tsx (1)

686-686: Padding enhancement
Adding p-6 makes the content layout more spacious and consistent.

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.

Good PR, finally letting go of email/password

@jjramirezn jjramirezn merged commit db46723 into peanut-wallet Jan 27, 2025
@jjramirezn jjramirezn deleted the fix/wallet-cashout branch January 27, 2025 11:07
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