Skip to content

fix: req pay for guest flow#655

Merged
jjramirezn merged 2 commits intopeanut-walletfrom
fix/req-guest-flow
Feb 3, 2025
Merged

fix: req pay for guest flow#655
jjramirezn merged 2 commits intopeanut-walletfrom
fix/req-guest-flow

Conversation

@kushagrasarathe
Copy link
Copy Markdown
Contributor

@kushagrasarathe kushagrasarathe commented Jan 31, 2025

  • also fixes scroll issue on mobile devices
  • also fixes weird cut-off of wallet cards on home screen
  • fixes typo in sign-in modal

fixes TASK-8582
fixes TASK-8456
fixes TASK-8585
fixes TASK-8080

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced wallet connection and transaction handling logic
    • Improved error messaging for wallet and transaction-related issues
  • Bug Fixes

    • Refined wallet address detection and connection status checks
    • Updated network switching and transaction validation processes
  • UI/UX Improvements

    • Adjusted layout and spacing in mobile UI components
    • Updated header rendering for authenticated users
    • Improved visual styling of payment and request views
  • Performance

    • Optimized wallet processing and connection logic
    • Enhanced error handling mechanisms

- also fixes scroll issue on mobile devices
- also fixes weird cut-off of wallet cards on home screen
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 31, 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 31, 2025 3:32pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 31, 2025

Walkthrough

This pull request encompasses modifications across multiple files in the mobile UI and wallet management components. The changes primarily focus on improving layout, styling, and error handling. Key updates include adjusting vertical and horizontal padding in components, refining wallet connection logic, enhancing authentication-based rendering, and introducing more robust error handling mechanisms for transactions and network interactions.

Changes

File Change Summary
src/app/(mobile-ui)/home/page.tsx Adjusted layout classes, modified vertical and horizontal padding for components
src/app/(mobile-ui)/layout.tsx Updated viewport height calculation, added conditional padding for home path
src/components/Global/FlowHeader/index.tsx Added authentication check to prevent rendering without a user
src/components/Request/Pay/Views/GeneralViews/AlreadyPaid.view.tsx Minor styling adjustments to label and token display
src/components/Request/Pay/Views/Initial.view.tsx Enhanced wallet connection logic, improved error handling, added new constants
src/hooks/wallet/useWallet.ts Refined wallet processing logic, expanded wallet address handling
src/utils/sdkErrorHandler.utils.tsx Added specific error handling for gas fee and estimation issues

Possibly related PRs

Suggested reviewers

  • jjramirezn

Poem

🐰 A Rabbit's Ode to Code Refinement 🛠️
Padding here, a class just there,
Wallets dancing with utmost care,
Authentication's watchful eye,
Error messages flying high,
Code evolves with rabbit's might! 🚀


📜 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 3d00e96 and 55e4216.

📒 Files selected for processing (1)
  • src/utils/sdkErrorHandler.utils.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils/sdkErrorHandler.utils.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

@notion-workspace
Copy link
Copy Markdown

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/Global/FlowHeader/index.tsx (1)

2-2: LGTM! Consider adding error boundaries.

The authentication-based rendering control is a good addition. However, since this is a global component, consider wrapping it with error boundaries to gracefully handle any authentication-related errors.

+import { ErrorBoundary } from '@/components/ErrorBoundary'
 import { useAuth } from '@/context/authContext'
 
 const FlowHeader = ({ onPrev, disableBackBtn, disableWalletHeader = false }: FlowHeaderProps) => {
     const { user } = useAuth()
 
     if (!user) return null
 
     return (
+        <ErrorBoundary>
         <div className="flex w-full flex-row items-center justify-between pb-3">
             {/* ... rest of the component ... */}
         </div>
+        </ErrorBoundary>
     )
 }

Also applies to: 13-15

src/components/Request/Pay/Views/Initial.view.tsx (2)

Line range hint 274-289: Enhance error handling in network switching.

The network switching implementation could be improved to provide more specific error information.

Consider this enhancement:

 const switchNetwork = async (chainId: string): Promise<boolean> => {
     try {
         await switchNetworkUtil({
             chainId,
             currentChainId: String(currentChain?.id),
             setLoadingState,
             switchChainAsync: async ({ chainId }) => {
                 await switchChainAsync({ chainId: chainId as number })
             },
         })
         console.log(`Switched to chain ${chainId}`)
         return true
     } catch (error) {
-        console.error('Failed to switch network:', error)
-        throw new Error(`Failed to switch to network ${chainId}`)
+        const errorMessage = error instanceof Error ? error.message : 'Unknown error'
+        console.error('Failed to switch network:', errorMessage)
+        throw new Error(`Failed to switch to network ${chainId}: ${errorMessage}`)
     }
 }

474-485: Clear user guidance based on wallet type.

The conditional messaging provides clear instructions for both Peanut wallet and external wallet users.

However, consider extracting these messages to constants to maintain consistency and enable easier updates:

+const WALLET_MESSAGES = {
+    PEANUT: (tokenName: string, chainName: string) =>
+        `You can only fulfill this payment request with ${tokenName} on ${chainName}. If you wish to use a different token or chain, please switch to an external wallet.`,
+    EXTERNAL:
+        'You can fulfill this payment request with any token on any chain. Pick the token and chain that you want to fulfill this request with.',
+}

 {isPeanutWallet ? (
     <label className="text-start text-h9 font-light">
-        You can only fulfill this payment request with {PEANUT_WALLET_TOKEN_NAME} on{' '}
-        {PEANUT_WALLET_CHAIN.name}. If you wish to use a different token or chain, please
-        switch to an external wallet.
+        {WALLET_MESSAGES.PEANUT(PEANUT_WALLET_TOKEN_NAME, PEANUT_WALLET_CHAIN.name)}
     </label>
 ) : (
     <label className="text-start text-h9 font-light">
-        You can fulfill this payment request with any token on any chain. Pick the token and
-        chain that you want to fulfill this request with.
+        {WALLET_MESSAGES.EXTERNAL}
     </label>
 )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd9af54 and 3d00e96.

📒 Files selected for processing (7)
  • src/app/(mobile-ui)/home/page.tsx (1 hunks)
  • src/app/(mobile-ui)/layout.tsx (3 hunks)
  • src/components/Global/FlowHeader/index.tsx (2 hunks)
  • src/components/Request/Pay/Views/GeneralViews/AlreadyPaid.view.tsx (1 hunks)
  • src/components/Request/Pay/Views/Initial.view.tsx (13 hunks)
  • src/hooks/wallet/useWallet.ts (5 hunks)
  • src/utils/sdkErrorHandler.utils.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/components/Request/Pay/Views/GeneralViews/AlreadyPaid.view.tsx
  • src/app/(mobile-ui)/home/page.tsx
🧰 Additional context used
📓 Learnings (1)
src/components/Request/Pay/Views/Initial.view.tsx (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#551
File: src/components/Request/Create/Views/Initial.view.tsx:151-156
Timestamp: 2024-12-02T17:19:18.532Z
Learning: In the `InitialView` component at `src/components/Request/Create/Views/Initial.view.tsx`, when setting the default chain and token in the `useEffect` triggered by `isPeanutWallet`, it's acceptable to omit the setters from the dependency array and not include additional error handling for invalid defaults.
🔇 Additional comments (12)
src/app/(mobile-ui)/layout.tsx (3)

50-50: Great use of dynamic viewport height!

Using h-[100dvh] instead of h-screen is a good choice as it handles mobile browser chrome better, particularly addressing the scrolling issue mentioned in the PR objectives.


76-77: LGTM! Consistent padding handling.

The conditional padding for support and home pages improves the mobile layout, which aligns with the PR objective of fixing mobile UI issues.


131-131: LGTM! Consistent branding.

The capitalization of "Peanut" in the wallet link text maintains brand consistency.

src/utils/sdkErrorHandler.utils.tsx (1)

64-70: LGTM! Enhanced error handling for gas-related issues.

The new error cases provide clear, actionable messages for users encountering gas-related issues:

  1. Fee cap and gas fee errors now suggest checking fund availability
  2. Gas estimation errors now suggest network switching as a solution
src/hooks/wallet/useWallet.ts (3)

42-47: LGTM! Enhanced wallet account handling.

Good improvement in destructuring the useAccount hook to include external wallet address and connection status.


232-232: LGTM! Improved connection status handling.

Good enhancement to:

  1. Fallback to external wallet address when selected wallet is undefined
  2. Consider both selected wallet and wagmi connection status

Also applies to: 234-234


139-145: Verify the filter condition logic.

The current implementation might have an edge case where a user's wallet could be filtered out if they log in after connecting their wallet.

src/components/Request/Pay/Views/Initial.view.tsx (5)

10-16: LGTM! Clean import organization.

The new imports from constants are well-organized and follow a consistent pattern.


84-90: Improved wallet connection logic.

The refactored wallet connection logic now correctly handles both external and Peanut wallets through a unified isConnected check.


296-304: LGTM! Robust validation checks.

The validation checks for wallet address and transaction data are well-placed and provide clear error messages.


339-346: LGTM! Comprehensive cross-chain validation.

The cross-chain transaction validation checks are thorough and provide clear error messages.


382-421: Well-structured button click handler.

The handleSubmit function effectively manages different wallet states and error scenarios.

@notion-workspace
Copy link
Copy Markdown

@notion-workspace
Copy link
Copy Markdown

2 similar comments
@notion-workspace
Copy link
Copy Markdown

@notion-workspace
Copy link
Copy Markdown

@jjramirezn jjramirezn merged commit 6918676 into peanut-wallet Feb 3, 2025
@jjramirezn jjramirezn deleted the fix/req-guest-flow branch February 3, 2025 11:42
@coderabbitai coderabbitai bot mentioned this pull request Mar 26, 2025
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