Skip to content

Conversation

@sai-suraj143
Copy link

@sai-suraj143 sai-suraj143 commented Dec 19, 2025

Description

Currently, clicking the "Switch Chain" button fails silently if the user does not have a crypto wallet (like MetaMask) installed. This PR adds a check to verify if window.ethereum exists. If not, it alerts the user and guides them to install a wallet.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Tested locally by disabling MetaMask extension.
  • Verified that the alert appears instead of a silent failure.
  • Verified that functionality remains normal when MetaMask is active.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

Closes #206

Summary by CodeRabbit

  • New Features
    • Added wallet verification to the create feature. If a crypto wallet is not detected, users receive an error notification and are prompted to install MetaMask.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Added a runtime guard in the changeChain function to detect missing crypto wallets. When window.ethereum is undefined, the function displays an error notification, shows an alert prompt, and opens the MetaMask download page before returning. Three floating-UI dependencies added to package.json.

Changes

Cohort / File(s) Summary
Wallet Presence Validation
client/app/create/page.tsx
Added runtime guard in changeChain to verify window.ethereum exists. If missing, displays error toast, shows alert, opens MetaMask download link, and returns early; otherwise proceeds to chain switch.
UI Dependencies
client/package.json
Added three @floating-ui dependencies: @floating-ui/core (^1.7.3), @floating-ui/dom (^1.7.4), and @floating-ui/react (^0.27.16).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Straightforward guard clause addition with standard error handling pattern
  • Simple dependency additions without version conflicts

Poem

🐰 When wallets hide and silence falls,
This bunny fixed the sleepy calls!
Now MetaMask downloads shine so bright,
With toasts and alerts to set things right! 🎩✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The addition of @floating-ui dependencies appears unrelated to the wallet check feature and the linked issue #206, suggesting scope creep. Clarify whether the @floating-ui dependencies are necessary for this fix. If not required, remove them or create a separate PR for dependency updates.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding an alert for missing wallet in the Switch Chain modal, which directly addresses the core issue.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #206: checks for window.ethereum, displays an alert, redirects to MetaMask download, and prevents silent failure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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 (3)
client/app/create/page.tsx (3)

27-27: Remove the development comment.

The "TRAINER FIX" prefix appears to be a development or training artifact that should not be in production code.

🔎 Suggested change
-    // TRAINER FIX: Check if a Wallet is actually installed first!
+    // Check if a crypto wallet is installed

28-28: Consider adding proper typing for window.ethereum.

Using (window as any).ethereum bypasses type checking. Consider declaring a proper type for better type safety.

🔎 Suggested type declaration

Add this type declaration at the top of the file or in a types file:

declare global {
  interface Window {
    ethereum?: any;
  }
}

Then update the check:

-    if (typeof window !== "undefined" && !(window as any).ethereum) {
+    if (typeof window !== "undefined" && !window.ethereum) {

29-31: Consider improving the user experience.

The current implementation has a few UX concerns:

  1. Double notification: Using both toast.error() and alert() is redundant. The blocking alert() modal interrupts the user flow and is generally considered poor UX in modern web applications.

  2. MetaMask-specific messaging: While MetaMask is popular, window.ethereum can be provided by other wallets (Coinbase Wallet, Brave Wallet, etc.). The error message should be more generic.

  3. Popup blocker risk: window.open() might be blocked by popup blockers in some browsers.

🔎 Suggested improvements
-    toast.error("No Crypto Wallet Found!");
-    alert("Please install MetaMask to continue.");
-    window.open("https://metamask.io/download/", "_blank");
+    toast.error(
+      "No crypto wallet detected. Please install a wallet extension (e.g., MetaMask) to continue.",
+      { duration: 6000 }
+    );
+    // Optionally provide a link in the UI instead of opening automatically

Alternatively, if you prefer to keep the automatic redirect:

-    toast.error("No Crypto Wallet Found!");
-    alert("Please install MetaMask to continue.");
+    toast.error("No crypto wallet detected. Redirecting to wallet installation page...");
     window.open("https://metamask.io/download/", "_blank");
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d3a4dd and 344dded.

⛔ Files ignored due to path filters (2)
  • client/package-lock.json is excluded by !**/package-lock.json
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • client/app/create/page.tsx (1 hunks)
  • client/package.json (1 hunks)
🔇 Additional comments (1)
client/app/create/page.tsx (1)

26-37: Good fix for the silent failure issue!

The wallet detection logic successfully addresses the main problem from issue #206 by:

  • Adding an SSR-safe check for window.ethereum
  • Providing user feedback instead of failing silently
  • Preventing the chain switch attempt when no wallet is detected
  • Using an early return to avoid propagating errors

The implementation correctly solves the reported bug. The suggestions above are refinements to improve UX and code quality.

Comment on lines +12 to +14
"@floating-ui/core": "^1.7.3",
"@floating-ui/dom": "^1.7.4",
"@floating-ui/react": "^0.27.16",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for floating-ui imports and usage in the client code

echo "=== Searching for @floating-ui imports ===" 
rg -n '@floating-ui' --type=ts --type=tsx

echo ""
echo "=== Searching for useFloating hook usage ==="
rg -n 'useFloating' --type=ts --type=tsx

echo ""
echo "=== Summary: Checking package.json to confirm packages are listed ===" 
grep -n '@floating-ui' client/package.json

Repository: AOSSIE-Org/Agora-Blockchain

Length of output: 419


Remove unused floating-ui dependencies.

These packages were added to package.json but are not imported or used anywhere in the codebase. They increase bundle size without providing value. If floating elements (tooltips, popovers, etc.) are planned for future use, they can be added when actually needed.

🤖 Prompt for AI Agents
In client/package.json around lines 12 to 14, the three @floating-ui entries are
unused; remove the "@floating-ui/core", "@floating-ui/dom", and
"@floating-ui/react" dependencies from package.json, run your package manager to
update node_modules and the lockfile (npm install / yarn install / pnpm
install), run the test/build to ensure nothing breaks, and commit the updated
package.json and lockfile changes.

@sai-suraj143
Copy link
Author

Hi @mentors!

I've submitted this PR to fix the 'Switch Chain' silent failure. I've verified the fix locally by disabling the wallet extension to simulate a new user environment.

Note: I've also joined the Discord (Username: Sai Suraj), but I'm currently unable to post messages there due to new-member restrictions. I'll keep an eye on this thread for any reviews or feedback. Thanks!

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.

[UX] "Switch Chain" Button Fails Silently when Wallet is Missing

1 participant