Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/qr modal and chain source #78

Merged
merged 3 commits into from
Sep 11, 2024
Merged

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Sep 11, 2024

  • fixes wagmi connect modal opening again and again
  • Changes the retrieval of chain object from useChainId to useAccount, as that provides the correct chain info.

PR-Codex overview

This PR updates multiple files to replace the useChainId hook with useAccount in the wagmi package, improving code consistency and simplifying access to chain information.

Detailed summary

  • Replaced useChainId with useAccount in multiple files
  • Updated functions to use chain object from useAccount
  • Removed unnecessary imports and unused variables

The following files were skipped due to too many changes: web/src/layout/Header/DesktopHeader.tsx

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Streamlined account and chain information retrieval by consolidating logic to use the useAccount hook across various components.
    • Enhanced performance and maintainability by removing the useChainId hook and related functions.
  • Bug Fixes

    • Improved robustness of components by ensuring chain ID checks are performed safely with nullish checks.
  • Documentation

    • Updated component logic descriptions to reflect changes in state management and data retrieval processes.

Copy link

netlify bot commented Sep 11, 2024

Deploy Preview for kleros-escrow-v2 ready!

Name Link
🔨 Latest commit a60a59a
🔍 Latest deploy log https://app.netlify.com/sites/kleros-escrow-v2/deploys/66e1abc6296cb10008776036
😎 Deploy Preview https://deploy-preview-78--kleros-escrow-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The changes involve a significant refactoring of the codebase to replace the useChainId hook with the useAccount hook across multiple components. This transition consolidates the retrieval of blockchain chain information, simplifying the logic and reducing dependencies. The modifications span various files, including components, hooks, and constants, enhancing the overall efficiency of the application while maintaining the same functionality.

Changes

Files Change Summary
web/src/components/ConnectWallet/AccountDisplay.tsx, web/src/components/ConnectWallet/index.tsx, web/src/components/EnsureAuth.tsx, web/src/hooks/useNativeTokenSymbol.ts, web/src/hooks/useTokenMetadata.ts, web/src/pages/MyTransactions/index.tsx, web/src/pages/NewTransaction/NavigationButtons/DepositPaymentButton.tsx, web/src/pages/NewTransaction/Terms/Payment/GeneralTransaction/TokenAndAmount/TokenSelector/index.tsx, web/src/pages/NewTransaction/index.tsx Removed useChainId and replaced it with useAccount, updating logic to access chain directly.
web/src/consts/chains.ts Removed getChain function and associated imports, simplifying chain extraction.
web/src/context/Web3Provider.tsx Modified wagmiConfig to disable QR modal display in wallet connection.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConnectWallet
    participant EnsureAuth
    participant TokenMetadata
    User->>ConnectWallet: Connect Wallet
    ConnectWallet->>EnsureAuth: Verify Authentication
    EnsureAuth->>TokenMetadata: Fetch Token Metadata
    TokenMetadata->>ConnectWallet: Return Metadata
    ConnectWallet->>User: Display Wallet Information
Loading

🐇 "In the code, a change was made,
To simplify the paths we laid.
From chains we once did seek,
Now accounts are what we speak.
With fewer hooks, we hop along,
A smoother flow, where we belong!" 🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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 or @coderabbitai title 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
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 and nitpick comments (1)
web/src/pages/NewTransaction/index.tsx (1)

45-45: LGTM, but consider adding a type guard for the chain object.

The isOnSupportedChain variable changes are approved. Using chain?.id instead of chainId to compare with the DEFAULT_CHAIN aligns with the updated method of retrieving the chain information from the useAccount hook.

However, consider adding a type guard for the chain object to improve type safety and readability:

-const isOnSupportedChain = chain?.id === DEFAULT_CHAIN;
+const isOnSupportedChain = chain && chain.id === DEFAULT_CHAIN;

This explicitly checks if the chain object exists before accessing its id property.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66b8c6e and a60a59a.

Files selected for processing (12)
  • web/src/components/ConnectWallet/AccountDisplay.tsx (2 hunks)
  • web/src/components/ConnectWallet/index.tsx (3 hunks)
  • web/src/components/EnsureAuth.tsx (3 hunks)
  • web/src/consts/chains.ts (2 hunks)
  • web/src/context/Web3Provider.tsx (2 hunks)
  • web/src/hooks/useNativeTokenSymbol.ts (1 hunks)
  • web/src/hooks/useTokenMetadata.ts (2 hunks)
  • web/src/layout/Header/DesktopHeader.tsx (5 hunks)
  • web/src/pages/MyTransactions/index.tsx (2 hunks)
  • web/src/pages/NewTransaction/NavigationButtons/DepositPaymentButton.tsx (4 hunks)
  • web/src/pages/NewTransaction/Terms/Payment/GeneralTransaction/TokenAndAmount/TokenSelector/index.tsx (2 hunks)
  • web/src/pages/NewTransaction/index.tsx (2 hunks)
Files skipped from review due to trivial changes (1)
  • web/src/consts/chains.ts
Additional comments not posted (28)
web/src/hooks/useNativeTokenSymbol.ts (1)

1-6: LGTM! The refactoring improves the reliability of the chain information.

The changes in this hook are approved.

The transition from useChainId to useAccount is a significant refactoring that improves the reliability of the chain information. The useAccount hook provides the correct chain information based on the user's account, which is more reliable than deriving it from the chain ID.

The hook is correctly accessing the nativeCurrency.symbol property from the chain object and using optional chaining (?.) to handle the case when the chain object is not available, which is a good practice.

web/src/hooks/useTokenMetadata.ts (4)

3-3: LGTM!

The code change is approved.


7-7: LGTM!

The code change is approved.


12-13: LGTM!

The code changes are approved.


24-24: LGTM!

The code change is approved.

web/src/components/ConnectWallet/index.tsx (2)

2-2: LGTM!

The changes to the import statements are approved. Removing the useChainId import and destructuring chain from useAccount is a valid approach to retrieve the chain information.


47-49: LGTM!

The changes to the useAccount hook and the conditional check are approved. Destructuring chain from useAccount and comparing chain?.id to DEFAULT_CHAIN is a correct way to retrieve and verify the chain information.

web/src/context/Web3Provider.tsx (2)

27-27: LGTM!

The change enhances readability without altering the underlying functionality.


42-42: Verify the impact of disabling the QR modal.

Disabling the QR modal could potentially limit the options for users to connect their wallets, especially those who rely on QR code scanning.

Please ensure that this change aligns with the desired user experience and that alternative connection methods are sufficiently provided.

To verify the impact, consider the following:

  1. Test the wallet connection flow without the QR modal to ensure a smooth user experience.
  2. Confirm that alternative connection methods, such as manually entering the wallet address or using other authentication mechanisms, are available and prominently displayed to users.
  3. Consider gathering user feedback or conducting usability testing to assess the impact of disabling the QR modal on the overall user experience.

If disabling the QR modal is indeed the intended behavior and alternative connection methods are adequately provided, feel free to disregard this comment.

web/src/pages/MyTransactions/index.tsx (2)

4-4: LGTM!

The code segment is approved.


30-31: LGTM!

The code segment is approved.

web/src/pages/NewTransaction/Terms/Payment/GeneralTransaction/TokenAndAmount/TokenSelector/index.tsx (4)

5-5: LGTM!

The import of the useAccount hook from wagmi is approved.


21-21: LGTM!

The usage of the useAccount hook to get the address and chain values is approved.


28-28: LGTM!

The creation of the alchemyInstance using the chain?.id and the usage of the useMemo hook are approved.


33-33: LGTM!

The changes to the useEffect hook, including the conditional check, the usage of chain.id, and the addition of alchemyInstance to the dependency array, are approved.

Also applies to: 35-35, 37-37

web/src/pages/NewTransaction/index.tsx (2)

16-16: LGTM!

The import statement changes are approved. Removing the useChainId import and adding the useAccount import aligns with the PR objective of modifying the method of retrieving the chain object.


42-42: LGTM!

The useAccount hook usage changes are approved. Destructuring the chain object from the useAccount hook aligns with the PR objective of retrieving the chain information from useAccount instead of useChainId.

web/src/components/EnsureAuth.tsx (3)

5-5: LGTM!

The change to replace the useChainId hook with the useAccount hook is approved. This consolidates the retrieval of account-related information into a single hook, simplifying the logic and reducing dependencies.


40-40: LGTM!

The change to destructure the chain property from the useAccount hook is approved. This provides the chain information needed for the createSiweMessage function call.


60-60: LGTM!

The change to use chain.id instead of chainId in the createSiweMessage function call is approved. This reflects the new structure of the data returned from the useAccount hook, ensuring that the correct chain ID is passed to the message creation function.

web/src/components/ConnectWallet/AccountDisplay.tsx (1)

7-7: LGTM!

The changes in the ChainDisplay component are approved for the following reasons:

  • The useChainId hook and getChain function have been removed, simplifying the logic.
  • The useAccount hook is now used to obtain the chain object directly, consolidating the retrieval of the chain information into a single hook.
  • The component now relies solely on the useAccount hook to access the chain data, which may streamline the component's performance and reduce unnecessary dependencies.

The AI-generated summary is consistent with the code changes.

Also applies to: 146-147

web/src/layout/Header/DesktopHeader.tsx (4)

6-6: LGTM!

The code segment is approved.


78-79: LGTM!

The code segment is approved.


93-95: LGTM!

The code segment is approved.


116-118: LGTM!

The code segment is approved.

web/src/pages/NewTransaction/NavigationButtons/DepositPaymentButton.tsx (3)

49-49: LGTM!

The code changes are approved.


63-63: LGTM!

The code changes are approved.

Also applies to: 67-67


102-102: LGTM!

The code changes are approved.

Also applies to: 106-106

@kemuru kemuru merged commit 7fce0f1 into master Sep 11, 2024
7 checks passed
@kemuru kemuru deleted the fix/qr-modal-and-chain-source branch September 11, 2024 15:03
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