Skip to content

Conversation

@kyrers
Copy link
Contributor

@kyrers kyrers commented Dec 7, 2025

Resolves #526.


PR-Codex overview

This PR introduces a new NetworkStatus component and modifies the AccountStatus and NetworkStatus components to enhance network management features, including chain switching functionality.

Detailed summary

  • Added NetworkStatus component in src/bootstrap/app.js.
  • Removed NetworkStatus from AccountStatus.
  • Implemented a chain switching menu in NetworkStatus.
  • Enhanced NetworkStatus with dropdown for switching chains.
  • Updated styles for StyledBadge and added StyledMenu.

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

Summary by CodeRabbit

  • New Features

    • Header now shows an interactive network status with a dropdown to switch networks.
  • UI/UX Improvements

    • Cleaner, simplified account display in the header.
    • Updated network badge styling with improved hover/focus visuals and accessibility.
  • Bug Fixes

    • Network switch attempts show user-friendly error messages on failure.

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

@kyrers kyrers self-assigned this Dec 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 7, 2025

Walkthrough

NetworkStatus was moved from the AccountStatus trigger into the header tray and replaced with a Dropdown-wrapped interactive badge that opens a SwitchChainMenu; the menu attempts async chain switches via requestSwitchChain with error reporting and updated badge/menu styling, preserving Skeleton rendering when no chain is present.

Changes

Cohort / File(s) Summary
Header / Account trigger
src/bootstrap/app.js, src/components/account-status.js
Rendered <NetworkStatus /> inside the header StyledTray; removed Divider import and StyledDivider usage/definition; simplified AccountStatus trigger UI by removing the previous NetworkStatus trigger wrapper and divider.
Network status & switcher
src/components/network-status.js
Replaced static Badge with an Ant Design Dropdown containing a new SwitchChainMenu; added handleSwitchChain to call requestSwitchChain asynchronously and surface errors via message.error; introduced StyledMenu and enhanced StyledBadge styling; retains Skeleton when no chain is present.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NetworkStatusUI as NetworkStatus (UI)
    participant AppLogic as requestSwitchChain / useDrizzle
    participant Wallet as Wallet Provider

    User->>NetworkStatusUI: Click badge → open Dropdown
    User->>NetworkStatusUI: Select target chain
    NetworkStatusUI->>AppLogic: requestSwitchChain(targetChain)
    AppLogic->>Wallet: RPC: wallet_switchEthereumChain / request
    Wallet-->>AppLogic: Success / Error
    AppLogic-->>NetworkStatusUI: Resolve / reject result
    NetworkStatusUI->>User: Show success or message.error on failure
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inspect handleSwitchChain / requestSwitchChain error paths and user-facing messages.
  • Verify Dropdown/Menu keyboard accessibility and focus/hover styling of StyledBadge.
  • Confirm chain list/filter logic (production-only switchableChains) and that current chain is excluded from switch targets.

Poem

🐰 I hopped to the tray with a sparkle and grin,

A badge that would whisper which chain I was in,
I clicked and it opened a menu so neat,
Chose one, sent a nudge — the wallet and beat,
Hooray, chains switched fast — a rabbit’s small feat.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main feature: adding a dropdown for chain switching in the network status component.
Linked Issues check ✅ Passed The pull request implements all requirements from issue #526: adds a chain switching dropdown in the Header via the NetworkStatus component.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the chain switching dropdown feature; no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/swith-chain-drodpown

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

@netlify
Copy link

netlify bot commented Dec 7, 2025

Deploy Preview for kleros-court ready!

Name Link
🔨 Latest commit 8b5545b
🔍 Latest deploy log https://app.netlify.com/projects/kleros-court/deploys/6936d51e02295b00087e607d
😎 Deploy Preview https://deploy-preview-527--kleros-court.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 project configuration.

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 (1)
src/components/network-status.js (1)

74-86: Consider extracting shared button styling.

Lines 77-86 duplicate the styling from StyledAccountStatus in account-status.js (background-color, border-radius, padding, hover states). Both components now share identical interactive button styling.

Consider creating a shared styled component or CSS mixin:

// In a shared styles file or at the top of a component file
const InteractiveButtonStyles = css`
  cursor: pointer;
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 8px 12px;
  font-weight: 400;
  transition: all 0.2s ease-in;

  :hover,
  :focus {
    background-color: rgba(255, 255, 255, 0.25);
  }
`;

// Then use it in both components:
const StyledBadge = styled(Badge)`
  white-space: nowrap;
  ${InteractiveButtonStyles}
  
  // ... rest of specific styles
`;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7461676 and 9ffca5a.

📒 Files selected for processing (3)
  • src/bootstrap/app.js (2 hunks)
  • src/components/account-status.js (1 hunks)
  • src/components/network-status.js (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/components/account-status.js (1)
src/components/eth-address.js (1)
  • ETHAddress (8-21)
src/bootstrap/app.js (1)
src/components/network-status.js (1)
  • NetworkStatus (41-58)
src/components/network-status.js (3)
src/bootstrap/app.js (1)
  • StyledMenu (300-327)
src/api/side-chain/request-switch-chain.js (1)
  • requestSwitchChain (6-18)
src/helpers/networks.js (2)
  • chainIdToNetworkShortName (8-13)
  • chainIdToNetworkShortName (8-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules - kleros-court
  • GitHub Check: Header rules - kleros-court
  • GitHub Check: Pages changed - kleros-court
🔇 Additional comments (6)
src/components/account-status.js (1)

21-23: LGTM! Clean refactoring.

The simplification correctly removes NetworkStatus from the account trigger, as it's now rendered separately in the header tray.

src/bootstrap/app.js (2)

11-11: LGTM!

The NetworkStatus import is correctly added to support rendering the network indicator in the header tray.


126-126: LGTM! Good placement in the header tray.

The NetworkStatus component is now rendered alongside AccountStatus and NotificationSettings, providing a consistent location for network information.

src/components/network-status.js (3)

47-54: LGTM! Good implementation of the dropdown trigger.

The badge is properly wrapped in a Dropdown component, making the network status clickable and showing available chains on click.


70-72: LGTM!

Simple, clean styling for the dropdown menu.


9-9: The import is correct. The src/api/side-chain/index.js re-exports requestSwitchChain as a named export (line 7: export { default as requestSwitchChain } from "./request-switch-chain"), so the named import syntax { requestSwitchChain } is valid and will work correctly at runtime.

Likely an incorrect or invalid review comment.

Copy link
Contributor

@tractorss tractorss left a comment

Choose a reason for hiding this comment

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

Network change does not handle Addition of Chiado chain
It's because of this check which checks if it's supported chain, and chiado is not added to the list of supported lists

@kyrers kyrers force-pushed the feat/swith-chain-drodpown branch from 68be488 to 878a430 Compare December 8, 2025 13:28
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 (1)
src/components/account-status.js (1)

20-25: Avoid an empty clickable pill in view‑only mode.

When account === VIEW_ONLY_ADDRESS, the trigger renders an empty StyledAccountStatus button, which is clickable but has no visible or accessible label. Consider showing a placeholder (e.g., “View-only” / “Not connected”) or disabling the button in that state:

-          {account !== VIEW_ONLY_ADDRESS ? (
-            <span className="address">
-              <ETHAddress address={account} withLink={false} />
-            </span>
-          ) : null}
+          {account !== VIEW_ONLY_ADDRESS ? (
+            <span className="address">
+              <ETHAddress address={account} withLink={false} />
+            </span>
+          ) : (
+            <span className="address">View-only</span>
+          )}

Adjust the placeholder copy as fits your UX.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68be488 and 878a430.

📒 Files selected for processing (3)
  • src/bootstrap/app.js (2 hunks)
  • src/components/account-status.js (1 hunks)
  • src/components/network-status.js (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/bootstrap/app.js (1)
src/components/network-status.js (1)
  • NetworkStatus (42-59)
src/components/account-status.js (2)
src/components/eth-address.js (1)
  • ETHAddress (8-21)
src/components/required-chain-id-modal.js (1)
  • account (14-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules - kleros-court
  • GitHub Check: Header rules - kleros-court
  • GitHub Check: Pages changed - kleros-court
🔇 Additional comments (3)
src/bootstrap/app.js (1)

11-11: NetworkStatus integration in the header tray looks correct.

Importing NetworkStatus and placing it in StyledTray before AccountStatus ensures it’s rendered within both DrizzleProvider and DrizzleChainIdProvider, so it has the contexts it needs and matches the “switch chain dropdown in the header” requirement.

Also applies to: 126-129

src/components/network-status.js (2)

5-11: SwitchChainMenu logic and error handling look solid.

Filtering out the current chain, short‑circuiting when targetChainId === chainId, and surfacing failures via message.error gives a clean UX and avoids redundant RPC calls. The use of chainIdToNetworkShortName keeps the menu options in sync with the displayed badge text.

Also applies to: 14-40


71-83: Dropdown and badge styling match the header pill pattern.

The rounded StyledMenu and pill‑style StyledBadge (background, padding, border radius, hover/focus transition) align visually with AccountStatus, keeping the header tray cohesive while making the network badge look clearly interactive.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 8, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

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

♻️ Duplicate comments (1)
src/components/network-status.js (1)

55-61: Make the Dropdown trigger keyboard‑accessible with a real button.

StyledBadge ultimately renders a non-focusable element (e.g., span), so keyboard users can’t tab to or activate the network switcher even though it’s clickable with a mouse.

Wrap the badge in a button trigger and add an accessible label:

   return chainId ? (
     <Dropdown overlay={<SwitchChainMenu />} trigger={["click"]}>
-      <StyledBadge
-        className={clsx(status, className)}
-        status={networkStatusToBadgeStatus[status]}
-        text={chainIdToNetworkShortName[chainId]}
-      />
+      <StyledTrigger
+        type="button"
+        aria-label={`Switch network (current: ${chainIdToNetworkShortName[chainId] || "unknown"})`}
+      >
+        <StyledBadge
+          className={clsx(status, className)}
+          status={networkStatusToBadgeStatus[status]}
+          text={chainIdToNetworkShortName[chainId]}
+        />
+      </StyledTrigger>
     </Dropdown>
   ) : (

And define the trigger styles near the other styled components:

 const StyledMenu = styled(Menu)`
   border-radius: 4px;
 `;
 
+const StyledTrigger = styled.button`
+  padding: 0;
+  border: none;
+  background: transparent;
+  cursor: pointer;
+`;
+
 const StyledBadge = styled(Badge)`

After this change, please verify in-browser that:

  • The trigger is reachable via Tab.
  • Enter/Space opens the dropdown.
  • A visible focus indicator is present when the trigger is focused.
🧹 Nitpick comments (2)
src/components/network-status.js (2)

14-46: Normalize chainId type to avoid redundant self-switches and keep menu options clean.

If useChainId() ever returns a string (e.g., "1"), the strict comparisons in the filter and in handleSwitchChain will fail, and the current network will still appear as an option and trigger an unnecessary switch request. Normalizing to numbers in this component makes the logic robust regardless of the hook’s return type.

You can harden this block like so:

 function SwitchChainMenu() {
   const { drizzle } = useDrizzle();
-  const chainId = useChainId();
+  const chainId = Number(useChainId());

   const handleSwitchChain = async (targetChainId) => {
     if (targetChainId === chainId) return; // Already on this chain

@@
-      {Object.entries(switchableChains)
-        .filter(([key]) => Number(key) !== chainId)
-        .map(([key, value]) => (
-          <Menu.Item key={key} onClick={() => handleSwitchChain(Number(key))}>
-            <span>{value}</span>
-          </Menu.Item>
-        ))}
+      {Object.entries(switchableChains)
+        .filter(([key]) => Number(key) !== chainId)
+        .map(([key, value]) => {
+          const targetId = Number(key);
+          return (
+            <Menu.Item key={targetId} onClick={() => handleSwitchChain(targetId)}>
+              <span>{value}</span>
+            </Menu.Item>
+          );
+        })}

Optionally, to avoid duplicating labels, you could derive switchableChains from chainIdToNetworkShortName:

const switchableChains = {
};

Please verify how useChainId is currently typed/implemented and adjust if needed.


83-93: Hover/focus styling is good; consider aligning it with the actual focusable element.

The hover/focus background changes on StyledBadge look nice, but once the trigger is a button, the keyboard focus will be on StyledTrigger, not the badge. If you want keyboard focus to mirror the hover visuals, you might move (or duplicate) the :hover, :focus styles onto StyledTrigger instead of the badge.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 878a430 and 8b5545b.

📒 Files selected for processing (1)
  • src/components/network-status.js (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/network-status.js (3)
src/bootstrap/app.js (1)
  • StyledMenu (300-327)
src/api/side-chain/request-switch-chain.js (1)
  • requestSwitchChain (6-18)
src/helpers/networks.js (2)
  • chainIdToNetworkShortName (8-13)
  • chainIdToNetworkShortName (8-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules - kleros-court
  • GitHub Check: Header rules - kleros-court
  • GitHub Check: Pages changed - kleros-court
🔇 Additional comments (2)
src/components/network-status.js (2)

5-11: Imports and hook wiring look consistent.

All newly added imports (Badge, Dropdown, Menu, message, Skeleton, requestSwitchChain, useDrizzle) are used and keep the file’s responsibilities cohesive; no issues here.


77-80: Menu styling change is safe and improves visual polish.

Adding a border radius on StyledMenu is unobtrusive and consistent with the rest of the header tray styling; no functional concerns here.

@tractorss tractorss self-requested a review December 8, 2025 14:03
Copy link
Contributor

@tractorss tractorss left a comment

Choose a reason for hiding this comment

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

lgtm

@kyrers kyrers merged commit eb36981 into master Dec 8, 2025
9 checks passed
@kyrers kyrers deleted the feat/swith-chain-drodpown branch December 8, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch chain dropdown

3 participants