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: autoconnect & argent mobile connection #856

Merged
merged 8 commits into from
Jul 16, 2024
Merged

Conversation

irisdv
Copy link
Collaborator

@irisdv irisdv commented Jul 16, 2024

Summary by CodeRabbit

  • New Features

    • Improved compatibility for the WalletConnect component in the Argent Mobile app browser.
  • Bug Fixes

    • Refined the logic in the Navbar component to ensure state updates run correctly and efficiently.

Copy link

vercel bot commented Jul 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app-starknet-id ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2024 8:54am
sepolia-app-starknet-id ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2024 8:54am

Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Warning

Rate limit exceeded

@irisdv has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 36 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 166748c and 7ac694d.

Walkthrough

The changes primarily focus on improving the Navbar and WalletConnect components by refining the use of React hooks and browser detection logic. The Navbar now uses a cleaner dependency array in its useEffect hook, and the WalletConnect component includes a new state and effect hook to detect if it's being accessed from the Argent Mobile app browser. Additionally, a utility function for this browser detection has been introduced.

Changes

File Change Summary
components/UI/navbar.tsx Adjusted the useEffect hook dependency array and refined the isConnected state logic.
components/UI/walletConnect.tsx Added state and effect for detecting Argent Mobile browser, and adjusted filterConnectors.
utils/connectorWrapper.ts Introduced isInArgentMobileAppBrowser function for Argent Mobile app browser detection.

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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bd658e6 and 457c190.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (3)
  • components/UI/navbar.tsx (1 hunks)
  • components/UI/walletConnect.tsx (3 hunks)
  • utils/connectorWrapper.ts (2 hunks)
Additional context used
Biome
utils/connectorWrapper.ts

[error] 94-94: Invalid typeof comparison value: this expression is not a string literal

not a string literal
Unsafe fix: Compare the result of typeof with a valid type name

(lint/suspicious/useValidTypeof)

Additional comments not posted (4)
components/UI/walletConnect.tsx (3)

1-1: Review of imports and state initialization:

  • The imports for useEffect and useState are correctly added as these hooks are used in the component.
  • The import of isInArgentMobileAppBrowser is appropriate as it's used within the useEffect hook to set the isArgentMobile state.
  • The state isArgentMobile is correctly initialized to false, which is a safe default value.

Everything looks good here.

Also applies to: 11-11, 29-29


36-39: Review of useEffect hook for setting isArgentMobile:

  • The hook correctly checks for the window object before calling isInArgentMobileAppBrowser, which ensures it only runs in a browser environment.
  • The empty dependency array ([]) ensures that this effect runs only once after the initial render, which is appropriate for setting the initial state based on the browser type.

This implementation is correct and efficient.


40-44: Review of modifications to filterConnectors function:

  • The function now filters connectors to only include those with id equal to "argentMobile" if isArgentMobile is true. This is a straightforward and efficient way to filter based on the state.
  • The function falls back to the previous behavior if isArgentMobile is false, which maintains backward compatibility.

The changes are logical and well-implemented.

components/UI/navbar.tsx (1)

86-86: Review of useEffect dependency modification:

  • The change to include only connectors in the dependency array of the useEffect hook that handles autoconnect is appropriate. This ensures that the hook only re-runs when connectors changes, which is likely the intended behavior to re-establish connections when available connectors change.

This change is a good practice for optimizing component re-renders.

Comment on lines 93 to 104
export const isInArgentMobileAppBrowser = (): boolean => {
if (typeof window === undefined || !window?.starknet_argentX) {
return false;
}

const starknetMobile =
window?.starknet_argentX as unknown as StarknetWindowObject & {
isInAppBrowser: boolean;
};

return starknetMobile?.isInAppBrowser;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue with typeof comparison in isInArgentMobileAppBrowser:

  • The static analysis tool flagged an issue with the typeof comparison on line 94. The correct usage should compare against a string literal. The current implementation might lead to unexpected behavior.

Here's a proposed fix:

-  if (typeof window === undefined || !window?.starknet_argentX) {
+  if (typeof window === "undefined" || !window?.starknet_argentX) {
    return false;
  }

This change ensures that the comparison checks if window is undefined correctly.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const isInArgentMobileAppBrowser = (): boolean => {
if (typeof window === undefined || !window?.starknet_argentX) {
return false;
}
const starknetMobile =
window?.starknet_argentX as unknown as StarknetWindowObject & {
isInAppBrowser: boolean;
};
return starknetMobile?.isInAppBrowser;
};
export const isInArgentMobileAppBrowser = (): boolean => {
if (typeof window === "undefined" || !window?.starknet_argentX) {
return false;
}
const starknetMobile =
window?.starknet_argentX as unknown as StarknetWindowObject & {
isInAppBrowser: boolean;
};
return starknetMobile?.isInAppBrowser;
};
Tools
Biome

[error] 94-94: Invalid typeof comparison value: this expression is not a string literal

not a string literal
Unsafe fix: Compare the result of typeof with a valid type name

(lint/suspicious/useValidTypeof)

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: 1

Outside diff range, codebase verification and nitpick comments (2)
components/UI/navbar.tsx (2)

Line range hint 89-91: Simplify the isConnected state update.

The useEffect for updating isConnected based on address is straightforward. Consider simplifying the ternary operation for clarity.

-    address ? setIsConnected(true) : setIsConnected(false);
+    setIsConnected(!!address);
Tools
Biome

[error] 83-83: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 93-102: Check network conditions for potential simplification.

The network check logic in useEffect is complex. Consider simplifying the condition to improve readability and possibly performance.

-      const isWrongNetwork =
-        (chainId === bigintToStringHex(sepolia.id) && network === "mainnet") ||
-        (chainId === bigintToStringHex(mainnet.id) && network === "testnet");
+      const expectedChainId = network === "mainnet" ? mainnet.id : sepolia.id;
+      const isWrongNetwork = chainId !== bigintToStringHex(expectedChainId);
Tools
Biome

[error] 83-83: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 457c190 and 166748c.

Files selected for processing (1)
  • components/UI/navbar.tsx (1 hunks)
Additional context used
Biome
components/UI/navbar.tsx

[error] 83-83: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (1)
components/UI/navbar.tsx (1)

Line range hint 104-106: Approve the update to lastConnector.

The useEffect for updating lastConnector is appropriately using isConnected as a dependency, ensuring it updates only when necessary.

Tools
Biome

[error] 83-83: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

components/UI/navbar.tsx Outdated Show resolved Hide resolved
@fricoben fricoben merged commit 2cbcc66 into testnet Jul 16, 2024
4 checks passed
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