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

feat: switch network instead of disconnect #929

Merged
merged 5 commits into from
Nov 30, 2024
Merged

Conversation

irisdv
Copy link
Collaborator

@irisdv irisdv commented Nov 28, 2024

Close #127

Summary by CodeRabbit

  • New Features

    • Introduced network switching functionality in the Navbar, allowing users to switch between blockchain networks seamlessly.
    • Added a specific check for Argent wallet types to enhance wallet identification.
  • Bug Fixes

    • Enhanced account checks in the network validation logic to prevent unnecessary checks when no account is present.
  • Documentation

    • Updated import statements to reflect the addition of new hooks and variables related to network switching.

Copy link

vercel bot commented Nov 28, 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 Nov 29, 2024 3:58pm
sepolia-app-starknet-id ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 29, 2024 3:58pm

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes made in this pull request enhance the Navbar component and the useIsWrongNetwork hook to support network-switching functionality using the useSwitchChain hook from the @starknet-react/core package. The Navbar now includes a method to switch networks instead of disconnecting, updating the UI accordingly. The useIsWrongNetwork hook has been modified to improve its control flow by incorporating checks for the user's account, ensuring that network validation is only performed when an account is present.

Changes

File Change Summary
components/UI/navbar.tsx Added useSwitchChain hook, switchNetwork method, updated imports, and modified UI logic.
hooks/isWrongNetwork.tsx Updated useIsWrongNetwork hook to include account checks and adjusted control flow.
utils/connectorWrapper.ts Added supportSwitchNetwork function to check for Argent wallet types.

Assessment against linked issues

Objective Addressed Explanation
Ask the user to change network instead of asking him to disconnect (#127)

Possibly related PRs

  • fix: paymaster #907: The modifications in the usePaymaster hook may relate to the network-switching functionality in the main PR, as both involve handling wallet interactions and network conditions.
  • Fix: argent mobile connection #925: The changes in the Argent mobile connection logic could be relevant to the network-switching functionality, as both PRs deal with wallet connectivity and network validation.

Suggested labels

🔥 Ready for review

Suggested reviewers

  • Marchand-Nicolas

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

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

🧹 Outside diff range and nitpick comments (4)
hooks/isWrongNetwork.tsx (2)

17-23: Consider adding custom network mismatch messages

To better align with the PR's UX improvement goals, consider adding custom error messages that clearly indicate which network the user should switch to.

    setIsWrongNetwork(
      process.env.NEXT_PUBLIC_IS_TESTNET === "true"
        ? bigintToStringHex(chain.id) === bigintToStringHex(mainnet.id)
        : bigintToStringHex(chain.id) === bigintToStringHex(sepolia.id)
    );
+   // Consider adding:
+   const targetNetwork = process.env.NEXT_PUBLIC_IS_TESTNET === "true" ? sepolia : mainnet;
+   setNetworkMessage(`Please switch to ${targetNetwork.name}`);

Line range hint 1-32: Consider adding error handling for network switching failures

To ensure a robust user experience, consider implementing error handling for cases where network switching fails (e.g., user rejection, RPC errors). This could be done by:

  1. Adding an error state to track switching failures
  2. Providing feedback to users when switching fails
  3. Implementing retry logic if needed

Would you like me to provide a detailed implementation suggestion for the error handling?

components/UI/navbar.tsx (2)

393-394: Enhance UX with loading state during network switch

Consider adding a loading state to provide feedback while the network switch is in progress.

+ const [isSwitching, setIsSwitching] = useState(false);

+ const handleNetworkSwitch = async () => {
+   setIsSwitching(true);
+   try {
+     await switchNetwork();
+   } finally {
+     setIsSwitching(false);
+   }
+ };

- <Button onClick={() => switchNetwork(network)}>
+ <Button 
+   onClick={handleNetworkSwitch}
+   disabled={isSwitching}
+ >
+   {isSwitching ? 'Switching...' : `Switch to ${network}`}
  </Button>

62-69: Consider extracting network switching logic to a custom hook

The network switching logic could be extracted into a custom hook (e.g., useNetworkSwitch) to:

  1. Improve reusability across components
  2. Centralize error handling and loading states
  3. Separate concerns from the UI component

Example implementation:

// hooks/useNetworkSwitch.ts
export const useNetworkSwitch = () => {
  const [isSwitching, setIsSwitching] = useState(false);
  const network = process.env.NEXT_PUBLIC_IS_TESTNET === "true" ? "testnet" : "mainnet";
  
  const { switchChainAsync } = useSwitchChain({
    params: {
      chainId: network === "testnet" ? StarknetChainId.SN_SEPOLIA : StarknetChainId.SN_MAIN,
    },
  });

  const switchNetwork = async () => {
    setIsSwitching(true);
    try {
      const res = await switchChainAsync();
      return res;
    } catch (error) {
      console.error('Failed to switch network:', error);
      throw error;
    } finally {
      setIsSwitching(false);
    }
  };

  return { switchNetwork, isSwitching, network };
};

Also applies to: 148-151

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 32e55ae and dad2936.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • components/UI/navbar.tsx (5 hunks)
  • hooks/isWrongNetwork.tsx (1 hunks)
🔇 Additional comments (4)
hooks/isWrongNetwork.tsx (3)

4-4: LGTM: Import addition aligns with new functionality

The addition of useAccount import is appropriate for the new account-aware network switching functionality.


9-9: LGTM: Account state management added

Good addition of account state tracking to prevent unnecessary network validation when no account is connected.


13-16: Verify account switching behavior

The early return logic is well implemented, but let's verify the behavior during account switches to ensure proper state updates.

✅ Verification successful

Early return logic is correctly implemented and safe for account switching

The implementation is correct and properly handles account switching scenarios:

  • The hook correctly updates isWrongNetwork state when accounts change through the dependency array [account, chain]
  • The early return with isWrongNetwork set to false when no account is present is the desired behavior
  • Components using this hook (navbar.tsx and freeRegisterCheckout.tsx) properly handle the network status changes
  • The state updates are synchronized with account changes through React's useEffect
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for proper handling of account switching scenarios
# Look for other components that might depend on this hook's behavior during account switches

# Search for components using this hook
rg -l "useIsWrongNetwork" --type tsx --type ts

# Look for account switching logic that might interact with this hook
ast-grep --pattern 'useAccount()' -l

Length of output: 219


Script:

#!/bin/bash
# Search for components using this hook
rg -l "useIsWrongNetwork"

# Look for account switching logic that might interact with this hook
rg -l "useAccount"

# Get the implementation details of the hook
cat hooks/isWrongNetwork.tsx

# Look for components that might be affected by network status
rg "isWrongNetwork" -A 3

Length of output: 5447

components/UI/navbar.tsx (1)

13-18: LGTM: Import statements are properly organized

The addition of useSwitchChain and StarknetChainId imports aligns well with the PR's objective of implementing network switching functionality.

Also applies to: 29-29

components/UI/navbar.tsx Show resolved Hide resolved
Comment on lines 148 to 151
const switchNetwork = async (network: string) => {
const res = await switchChainAsync();
if (res) setIsWrongNetwork(false);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve switchNetwork function implementation

The function has a few areas for improvement:

  1. The network parameter is unused
  2. Missing error handling for failed network switches
-  const switchNetwork = async (network: string) => {
+  const switchNetwork = async () => {
+    try {
       const res = await switchChainAsync();
       if (res) setIsWrongNetwork(false);
+    } catch (error) {
+      console.error('Failed to switch network:', error);
+      // Consider showing an error message to the user
+    }
   };
📝 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
const switchNetwork = async (network: string) => {
const res = await switchChainAsync();
if (res) setIsWrongNetwork(false);
};
const switchNetwork = async () => {
try {
const res = await switchChainAsync();
if (res) setIsWrongNetwork(false);
} catch (error) {
console.error('Failed to switch network:', error);
// Consider showing an error message to the user
}
};

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

E2E Test

On Braavos, I have this when I switch

Capture d’écran 2024-11-29 à 10 13 34

Same for Keplr ... I'm not sure they support this feature

@fricoben fricoben added ❌ Change request Change requested from reviewer and removed 🔥 Ready for review This pull request needs a review labels Nov 29, 2024
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 and nitpick comments (1)
utils/connectorWrapper.ts (1)

94-94: Add JSDoc documentation for better code maintainability.

Consider adding documentation to explain the function's purpose and parameters:

+/**
+ * Checks if the given connector is an Argent wallet
+ * @param connector - Optional StarknetReactConnector instance
+ * @returns true if the connector is an Argent wallet, false otherwise
+ */
export const isArgentWallet = (connector?: StarknetReactConnector) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dad2936 and d4c67ee.

📒 Files selected for processing (2)
  • components/UI/navbar.tsx (6 hunks)
  • utils/connectorWrapper.ts (2 hunks)
🔇 Additional comments (6)
components/UI/navbar.tsx (3)

13-18: LGTM: Import statements are properly organized

The new imports for network switching functionality are correctly added and organized.

Also applies to: 29-29, 35-35


63-70: Add error handling for switchChainAsync

While the chain configuration is correct, consider adding error handling for cases where the network switch fails.


149-155: 🛠️ Refactor suggestion

Enhance network switching implementation

The implementation needs improvements in several areas:

  1. Add error handling for network switching
  2. Add loading state during network switch
  3. Add TypeScript return type annotation
- const switchNetwork = async () => {
+ const switchNetwork = async (): Promise<void> => {
+   try {
      if (isArgentWallet(connector)) disconnectByClick();
      else {
+       setIsWrongNetwork(true); // Show loading state
        const res = await switchChainAsync();
        if (res) setIsWrongNetwork(false);
      }
+   } catch (error) {
+     console.error('Network switch failed:', error);
+     // Consider showing an error message to the user
+   } finally {
+     setIsWrongNetwork(false); // Reset loading state
+   }
  };

Likely invalid or redundant comment.

utils/connectorWrapper.ts (3)

7-7: LGTM!

The import of StarknetReactConnector is necessary for type safety in the new isArgentWallet function.


94-101: LGTM! Implementation is correct and aligns with PR objectives.

The function correctly identifies Argent wallets by checking the connector's ID against all known Argent wallet types.


94-101: Verify the network switching implementation.

Let's verify that the network switching logic correctly uses this function for all Argent wallet types.

✅ Verification successful

Let me try a different search strategy to verify the network switching implementation.


Based on the search results, I can now provide a final response:

Network switching implementation is correctly handling Argent wallets

The implementation in components/UI/navbar.tsx shows that the isArgentWallet function is properly used in the network switching logic:

  • For Argent wallets (argentX, argentMobile, argentWebWallet), it triggers disconnectByClick()
  • For other wallets, it uses switchChainAsync()

The UI also correctly displays different text based on the wallet type:

<Button onClick={() => switchNetwork()}>
  {isArgentWallet(connector)
    ? `Switch to ${network}`
    : "Disconnect"}
</Button>
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the usage of isArgentWallet function in network switching logic
# and verify consistent handling of all Argent wallet types.

# Check for network switching implementation using isArgentWallet
echo "Checking network switching implementation..."
rg -A 5 "isArgentWallet.*switchNetwork"

# Verify all Argent wallet types are handled
echo "Verifying Argent wallet types handling..."
ast-grep --pattern $'isArgentWallet\(.*\) {
  return (
    $$$
    (connector.id === "argentX" ||
      connector.id === "argentMobile" ||
      connector.id === "argentWebWallet")
    $$$
  );
}'

Length of output: 431


Script:

#!/bin/bash
# Let's search for network switching related code and its connection to Argent wallets

# Search for network switching implementations
echo "Searching for network switching implementations..."
rg -A 10 "switchNetwork|changeNetwork" 

# Search for any usage of isArgentWallet function
echo "Searching for isArgentWallet usage..."
rg -A 5 "isArgentWallet"

# Search for Argent wallet related network handling
echo "Searching for Argent wallet network handling..."
rg -A 10 "argentX|argentMobile|argentWebWallet.*network"

Length of output: 22083

components/UI/navbar.tsx Outdated Show resolved Hide resolved
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)
components/UI/navbar.tsx (1)

Line range hint 149-401: Consider implementing a more robust network switching strategy

While the current implementation achieves the basic objective of switching networks, consider these architectural improvements:

  1. Create a custom hook (e.g., useNetworkSwitch) to encapsulate the network switching logic, making it reusable across components
  2. Implement a proper state machine for network switching states (idle, switching, success, error)
  3. Add analytics to track successful/failed network switches for better monitoring

This would make the implementation more maintainable and provide better insights into user experience.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d4c67ee and 4861997.

📒 Files selected for processing (1)
  • components/UI/navbar.tsx (6 hunks)
🔇 Additional comments (4)
components/UI/navbar.tsx (4)

13-18: LGTM: Import statements are well-organized

The new imports (useSwitchChain, StarknetChainId, isArgentWallet) are correctly added and align with the network switching functionality.

Also applies to: 29-29, 35-35


63-70: Add error handling for switchChainAsync

The hook setup is correct, but error handling is still missing as mentioned in a previous review.


149-156: Improve switchNetwork implementation

The function implementation needs improvements as mentioned in previous reviews:

  1. Error handling is missing
  2. Loading state should be added
  3. The network parameter is unused

398-401: 🛠️ Refactor suggestion

Improve button text clarity and add loading state

  1. The "Disconnect" text for non-Argent wallets doesn't accurately reflect the action (switching networks). This could be confusing for users.
  2. As mentioned in a previous review, consider adding a loading state during network switching.

Additionally, consider adding a confirmation dialog before disconnecting non-Argent wallets to improve user experience:

  const switchNetwork = async () => {
    if (isArgentWallet(connector)) {
      const res = await switchChainAsync();
      if (res) setIsWrongNetwork(false);
    } else {
+     const confirmed = await confirm(
+       "This wallet doesn't support automatic network switching. Would you like to disconnect?"
+     );
+     if (confirmed) {
        disconnectByClick();
+     }
    }
  };

@irisdv irisdv requested a review from fricoben November 29, 2024 10:45
@irisdv irisdv added 🔥 Ready for review This pull request needs a review and removed ❌ Change request Change requested from reviewer labels Nov 29, 2024
Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

Argent mobile and webwallet not working

@@ -90,6 +91,15 @@ export const getLastConnected = (): Connector | null => {
return null;
};

export const isArgentWallet = (connector?: StarknetReactConnector) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Testé sur Sepolia, ne marche pas pour mobile + webwallet.

Je propose de renommer isArgentExtension et ref :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah j'ai renommé en supportSwitchNetwork comme ça on pourra mettre à jour la fonction dès que d'autres wallet ajoutent le support

@fricoben fricoben added ❌ Change request Change requested from reviewer and removed 🔥 Ready for review This pull request needs a review labels Nov 29, 2024
@irisdv irisdv added 🔥 Ready for review This pull request needs a review and removed ❌ Change request Change requested from reviewer labels Nov 29, 2024
@irisdv irisdv requested a review from fricoben November 29, 2024 15:57
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

Reviewing files that changed from the base of the PR and between 4861997 and 9403ba5.

📒 Files selected for processing (2)
  • components/UI/navbar.tsx (6 hunks)
  • utils/connectorWrapper.ts (2 hunks)
🔇 Additional comments (6)
components/UI/navbar.tsx (4)

13-18: LGTM: Import statements are well-organized

The new imports are appropriate for implementing the network switching functionality.

Also applies to: 29-29, 35-35


398-401: Improve button UI and loading state

The button should show a loading state during network switching and maintain consistent messaging.

- <Button onClick={() => switchNetwork()}>
-   {supportSwitchNetwork(connector)
-     ? `Switch to ${network}`
-     : "Disconnect"}
+ <Button 
+   onClick={() => switchNetwork()}
+   disabled={isNetworkSwitching}
+ >
+   {isNetworkSwitching ? (
+     <CircularProgress size={20} />
+   ) : (
+     supportSwitchNetwork(connector)
+       ? `Switch to ${network}`
+       : `Switch to ${network}`
+   )}
  </Button>

63-70: 🛠️ Refactor suggestion

Add error handling for network switching

While the chain configuration is correct, consider adding error handling for network switch failures.

 const { switchChainAsync } = useSwitchChain({
   params: {
     chainId:
       network === "testnet"
         ? StarknetChainId.SN_SEPOLIA
         : StarknetChainId.SN_MAIN,
   },
+  onError: (error) => {
+    console.error('Failed to switch network:', error);
+    // Consider showing an error message to the user
+  }
 });

149-156: 🛠️ Refactor suggestion

Enhance network switching implementation

The implementation needs error handling and loading state management.

+ const [isNetworkSwitching, setIsNetworkSwitching] = useState<boolean>(false);

  const switchNetwork = async () => {
+   setIsNetworkSwitching(true);
    try {
      if (supportSwitchNetwork(connector)) {
        const res = await switchChainAsync();
        if (res) setIsWrongNetwork(false);
      } else {
        disconnectByClick();
      }
+   } catch (error) {
+     console.error('Failed to switch network:', error);
+     // Consider showing an error message to the user
+   } finally {
+     setIsNetworkSwitching(false);
    }
  };
utils/connectorWrapper.ts (2)

7-7: LGTM!

The import with alias is well-structured to avoid naming conflicts with the existing Connector type.


94-96: Verify integration with network switching UI

Let's verify the usage of supportSwitchNetwork function across the codebase.

✅ Verification successful

Integration with network switching UI is properly implemented

The verification shows that supportSwitchNetwork is correctly integrated:

  • It's imported and used in components/UI/navbar.tsx
  • Used in the switchNetwork function to determine whether to switch chains or disconnect
  • Properly controls the button text to show either "Switch to {network}" or "Disconnect" based on wallet capability
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of supportSwitchNetwork function and network switching UI integration

# Check for usage of supportSwitchNetwork
echo "Checking usage of supportSwitchNetwork function..."
rg -A 5 "supportSwitchNetwork"

# Check for network switching UI components
echo "Checking network switching UI components..."
rg -A 5 "switchNetwork|changeNetwork|networkSwitch"

Length of output: 2431

Comment on lines +94 to +96
export const supportSwitchNetwork = (connector?: StarknetReactConnector) => {
return connector && connector.id === "argentX";
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review network switching support for all wallet types

The current implementation has several concerns:

  1. It only supports argentX wallet, which may be too restrictive.
  2. Past review comments indicate issues with mobile + webwallet on Sepolia network.
  3. The function lacks documentation about its purpose and limitations.

Consider:

  1. Adding support for other wallets that can switch networks.
  2. Adding documentation about supported wallets and networks.
  3. Addressing the mobile + webwallet issues on Sepolia.
+/**
+ * Checks if the given connector supports network switching.
+ * Currently supported wallets:
+ * - argentX
+ * 
+ * @param connector The Starknet React connector to check
+ * @returns true if the connector supports network switching
+ */
 export const supportSwitchNetwork = (connector?: StarknetReactConnector) => {
-  return connector && connector.id === "argentX";
+  return connector && (
+    connector.id === "argentX"
+    // TODO: Add support for other wallets that can switch networks
+  );
 };
📝 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 supportSwitchNetwork = (connector?: StarknetReactConnector) => {
return connector && connector.id === "argentX";
};
/**
* Checks if the given connector supports network switching.
* Currently supported wallets:
* - argentX
*
* @param connector The Starknet React connector to check
* @returns true if the connector supports network switching
*/
export const supportSwitchNetwork = (connector?: StarknetReactConnector) => {
return connector && (
connector.id === "argentX"
// TODO: Add support for other wallets that can switch networks
);
};

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

lgtm

@fricoben fricoben merged commit 365e157 into testnet Nov 30, 2024
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔥 Ready for review This pull request needs a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ask the user to change network instead of asking him to disconnect
2 participants