Skip to content

fix: refetch wallet balance after claim/req-pay/send flow completion#665

Merged
kushagrasarathe merged 4 commits intopeanut-walletfrom
fix/refetch-balance
Feb 5, 2025
Merged

fix: refetch wallet balance after claim/req-pay/send flow completion#665
kushagrasarathe merged 4 commits intopeanut-walletfrom
fix/refetch-balance

Conversation

@kushagrasarathe
Copy link
Copy Markdown
Contributor

@kushagrasarathe kushagrasarathe commented Feb 4, 2025

  • fixes TASK-8586
  • request pay, claim funds and send funds flow now properly updates wallet balances

Summary by CodeRabbit

  • New Features

    • Wallet balance now refreshes automatically after completing transactions (claims, link creation, and payments), ensuring your account always shows the latest information.
  • Bug Fixes

    • Improved how the correct wallet address is used during balance updates.
    • Removed an unnecessary loading screen in the payment success view for a smoother transaction experience.
    • Adjusted loading state management in the InitialView component for better user experience.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 4, 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 5, 2025 10:31am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

This pull request enhances wallet balance updating across several components. The changes integrate a refetchBalances function from the wallet hook into the claim, create, and payment flows. In the claim and create hooks, the function is invoked post-transaction to refresh the wallet balance, with an update to the argument in the create hook. In the initial payment view, the function is used to update balances after a successful transaction, and the success view removes a redundant loading state block.

Changes

File(s) Change Summary
src/components/Claim/useClaimLink.tsx Added refetchBalances from useWallet and called it after a successful claim transaction.
src/components/Create/useCreateLink.tsx Updated createLinkWrapper to pass `selectedWallet?.address
src/components/Request/Pay/Views/Initial.view.tsx Integrated refetchBalances from useWallet in the payment flow to refresh balance post-transaction; removed unused open and signInModal props.
src/components/Request/Pay/Views/Success.view.tsx Removed the conditional loading state block and added a comment regarding loading state management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ClaimComponent
    participant WalletHook

    User->>ClaimComponent: Initiate claim transaction
    ClaimComponent->>WalletHook: Call claimLink()
    Note over ClaimComponent, WalletHook: Transaction succeeds
    ClaimComponent->>WalletHook: Call refetchBalances(address)
    WalletHook-->>ClaimComponent: Return updated balance
Loading
sequenceDiagram
    participant User
    participant CreateComponent
    participant WalletHook

    User->>CreateComponent: Start link creation
    CreateComponent->>WalletHook: Call createLinkWrapper()
    Note over CreateComponent, WalletHook: Transaction succeeds
    CreateComponent->>WalletHook: Call refetchBalances(selectedWallet?.address || '')
    WalletHook-->>CreateComponent: Return updated balance
Loading
sequenceDiagram
    participant User
    participant PaymentComponent
    participant WalletHook

    User->>PaymentComponent: Initiate payment request
    PaymentComponent->>PaymentComponent: Process transaction
    Note over PaymentComponent: Transaction successful
    PaymentComponent->>WalletHook: Call refetchBalances(address)
    WalletHook-->>PaymentComponent: Return updated wallet balance
Loading

Possibly related PRs

  • Release #451: Changes related to the refetchBalances function in the useWallet hook, utilized in the InitialView component for refreshing wallet balances.
  • fix: render token details for peanut wallet #653: Direct connection with the addition of the refetchBalances property to the useWallet hook, impacting balance updates in related components.
  • Fix build #377: Shared focus on the refetchBalances function modifications in both useClaimLink and useCreateLink hooks for wallet balance refetching.

Suggested reviewers

  • jjramirezn

Poem

I'm a rabbit coding through the night,
Hopping on changes with all my might.
I refreshed balances with a swift new hop,
Ensuring your wallet stays right on top.
With each little tweak, I dance in delight!
🐰 Happy coding, keep the bugs out of sight!


📜 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 78a4f08 and de1c3b1.

📒 Files selected for processing (3)
  • src/components/Claim/useClaimLink.tsx (2 hunks)
  • src/components/Create/useCreateLink.tsx (1 hunks)
  • src/components/Request/Pay/Views/Initial.view.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/components/Claim/useClaimLink.tsx
  • src/components/Create/useCreateLink.tsx
  • src/components/Request/Pay/Views/Initial.view.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

@kushagrasarathe kushagrasarathe requested a review from Hugo0 February 4, 2025 14:27
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: 1

🧹 Nitpick comments (1)
src/components/Request/Pay/Views/Success.view.tsx (1)

31-80: Optimize useEffect dependencies and consolidate state management.

Based on previous learnings, transactionHash should not be in dependency arrays as it remains constant in success view. Additionally, the component has complex state management spread across multiple effects.

Consider these improvements:

  1. Remove transactionHash from dependency arrays:
- }, [explorerUrlDestChainWithTxHash, requestLinkData, address])
+ }, [explorerUrlDestChainWithTxHash, requestLinkData, address])

- }, [isXChain, requestLinkData, transactionHash, address, selectedTokenAddress])
+ }, [isXChain, requestLinkData, address, selectedTokenAddress])
  1. Consolidate the transaction submission logic into a single effect or custom hook to improve maintainability:
const useTransactionSubmission = (params) => {
  useEffect(() => {
    const submitTransaction = async () => {
      if (shouldSubmit) {
        await peanut.submitRequestLinkFulfillment(/* ... */);
        await utils.saveRequestLinkFulfillmentToLocalStorage(/* ... */);
      }
    };
    submitTransaction();
  }, [/* dependencies */]);
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6918676 and 78a4f08.

📒 Files selected for processing (4)
  • src/components/Claim/useClaimLink.tsx (2 hunks)
  • src/components/Create/useCreateLink.tsx (1 hunks)
  • src/components/Request/Pay/Views/Initial.view.tsx (2 hunks)
  • src/components/Request/Pay/Views/Success.view.tsx (1 hunks)
🧰 Additional context used
📓 Learnings (2)
src/components/Request/Pay/Views/Success.view.tsx (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#409
File: src/components/Request/Pay/Views/Success.view.tsx:23-23
Timestamp: 2024-11-12T09:39:20.720Z
Learning: In the `SuccessView` component, `transactionHash` remains constant because we are in a success view, so it's unnecessary to include it in the dependency array of `useEffect` hooks.
src/components/Request/Pay/Views/Initial.view.tsx (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#410
File: src/components/Request/Pay/Views/Initial.view.tsx:87-93
Timestamp: 2024-11-12T09:39:20.720Z
Learning: When refactoring to eliminate code duplication, prioritize readability and consider whether the change significantly improves the code. If it doesn't enhance readability or maintainability, it's acceptable to keep the existing code structure.
🔇 Additional comments (3)
src/components/Claim/useClaimLink.tsx (1)

14-14: LGTM! Wallet balance is now properly refreshed after claiming.

The integration of refetchBalances and its placement after the successful claim transaction ensures that the wallet balance stays up-to-date.

Also applies to: 29-30

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

83-83: LGTM! Wallet balance is now properly refreshed after payment request.

The integration of refetchBalances and its placement after the successful payment transaction ensures that the wallet balance stays up-to-date.

Also applies to: 337-338

src/components/Create/useCreateLink.tsx (1)

764-765: LGTM! Improved clarity in wallet balance refresh after link creation.

The change to use selectedWallet?.address is more explicit and clearer than using the generic address variable, making the code's intent more obvious.

})

// refetch wallet balance after successful claim
await refetchBalances(address)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Q: do we need await here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, probably not, removed it


await refetchBalances(address ?? '')
// refetch wallet balance after successful link creation
await refetchBalances(selectedWallet?.address || '')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same

onNext()

// update wallet balance after successful req payment
await refetchBalances(address)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • same
  • flag: repetitive code. Would be good to at least evaluate a more holistic approach (even if actually implementing it is high effort and we go with the more hacky short term solution)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure what you mean by repetitive code here, but we are already reusing the refetchBalances fn from wallet hook, and these are three different actions that are being done where refetchBalances is used, create/pay/claim flows, where we need to refetch the balance

</div>
)
}
// todo: manage loading state properly, currently it keeps loading forever
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is pending on request v2?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the loading state was buggy, it kept loading forever, so to smoothen the ux, removed it for a while, yes, in req v2 will have it improved

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