Skip to content

18/add ethereum classic mainnet support and rename testnet to mordor in stablepay sdk#30

Open
dark-Invincible wants to merge 2 commits intoDjedAlliance:mainfrom
dark-Invincible:18/add_ethereum_classic_mainnet_support_and_rename_testnet_to_mordor_in_stablepay_sdk
Open

18/add ethereum classic mainnet support and rename testnet to mordor in stablepay sdk#30
dark-Invincible wants to merge 2 commits intoDjedAlliance:mainfrom
dark-Invincible:18/add_ethereum_classic_mainnet_support_and_rename_testnet_to_mordor_in_stablepay_sdk

Conversation

@dark-Invincible
Copy link

@dark-Invincible dark-Invincible commented Dec 14, 2025

Resolved #18

Summary by CodeRabbit

  • New Features
    • Added support for Ethereum Classic mainnet alongside the existing Mordor testnet
    • Implemented dynamic network selection enabling users to switch between networks
    • Updated transaction explorer links to correctly reflect the currently selected network
    • Enhanced configuration to support multi-chain compatibility

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

…ETC testnet to Mordor\n\n- Rename ethereum-classic testnet key to mordor-testnet\n- Add ethereum-classic mainnet (chainId 61) with Rivet RPC\n- Set DJED (0xCc3664d7021FD36B1Fe2b136e2324710c8442cCf) and ECSD (0x5A7Ca94F6E969C94bef4CE5e2f90ed9d4891918A)\n- Update explorer links for both networks\n- Add viem chain for ETC mainnet and dynamic wallet switching\n\nFixes DjedAlliance#18
…)\n\n- Add ethereum-classic (chainId 61) with Rivet RPC\n- Set DJED and ECSD addresses\n- Rename testnet key to mordor-testnet\n- Update explorers + dynamic wallet switching\n- Ignore dist/ and local tarballs\n\nFixes DjedAlliance#18
@coderabbitai
Copy link

coderabbitai bot commented Dec 14, 2025

Walkthrough

The PR introduces dynamic chain selection between Ethereum Classic mainnet and Mordor testnet. It adds a new ETC mainnet chain configuration, updates network settings for both networks, implements global network state tracking via window.__STABLEPAY_SELECTED_NETWORK__, and refactors wallet and client creation to use the dynamically selected chain instead of hard-coded Mordor references.

Changes

Cohort / File(s) Summary
Chain and Network Configuration
stablepay-sdk/src/contexts/chains.js, stablepay-sdk/src/utils/config.js
Added ETC mainnet chain definition with id 61, RPC URL, and BlockScout explorer. Renamed mordor testnet config entry to mordor-testnet and added new ethereum-classic config for mainnet with respective contract addresses and token details. Both chains now have explicit native ETC token and stablecoin (ECSD) support with decimals and feeUI settings.
Wallet Context with Dynamic Chain Selection
stablepay-sdk/src/contexts/WalletContext.jsx
Introduced getExpectedChain() helper function to derive active chain object from global network flag. Replaced all hard-coded Mordor references with dynamic chain selection throughout wallet creation, public client creation, balance queries, and chain switching logic. Updated error messages and payload fields to reflect selected network.
Widget and UI Integration
stablepay-sdk/src/widget/Widget.jsx
Added side-effect in WidgetWithProviders to capture selected network from networkSelector and assign to window.__STABLEPAY_SELECTED_NETWORK__ global state prior to rendering providers.
Transaction Explorer URLs
stablepay-sdk/src/widget/TransactionReview.jsx
Updated transaction explorer URL logic to support both mordor-testnet and ethereum-classic (mainnet) with correct BlockScout endpoints. Replaced hard-coded Mordor URL with dynamic getExplorerUrl() function.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • WalletContext.jsx: Review all chain selection logic, dynamic client creation, and chain comparison changes thoroughly
  • Dynamic global state usage: Verify window.__STABLEPAY_SELECTED_NETWORK__ assignment and consumption flow
  • Chain configuration consistency: Ensure new etcMainnet and updated network configs align across all files (RPC URLs, contract addresses, explorer endpoints)

Possibly related PRs

Suggested reviewers

  • Zahnentferner

Poem

🐰 A network fork in every code!
Now Classic runs its mainnet road,
While Mordor testnet gets its name,
Dynamic chains, no more the same!
Two paths to hop, one global state—
StablePay chains now integrate! 🌐✨

Pre-merge checks and finishing touches

✅ Passed checks (5 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 changes: adding Ethereum Classic mainnet support and renaming testnet to mordor in the StablePay SDK.
Linked Issues check ✅ Passed The pull request successfully implements all coding-related requirements from issue #18: adds ETC mainnet configuration, renames testnet to mordor-testnet, updates chain definitions, integrates dynamic network selection, and maintains backward compatibility.
Out of Scope Changes check ✅ Passed All code changes are directly related to issue #18 objectives: chain configuration updates, network selection logic, and supporting infrastructure for dual-network support without unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
stablepay-sdk/src/widget/Widget.jsx (1)

28-35: Avoid mutating window during render; guard window for SSR/tests
Current code will throw outside the browser and can be invoked multiple times under React StrictMode.

-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
@@
 const WidgetWithProviders = ({ onClose, buttonSize, networkSelector, onTransactionComplete }) => {
-  // Keep a global reference of current selection for WalletContext
-  window.__STABLEPAY_SELECTED_NETWORK__ = networkSelector?.selectedNetwork || null;
+  // Keep a global reference of current selection for WalletContext (browser-only)
+  useEffect(() => {
+    if (typeof window !== "undefined") {
+      window.__STABLEPAY_SELECTED_NETWORK__ = networkSelector?.selectedNetwork ?? null;
+    }
+  }, [networkSelector?.selectedNetwork]);
   return (

Also: if the dropdown changes selection via NetworkContext (not networkSelector.selectedNetwork), this global may never update—worth double-checking.

stablepay-sdk/src/utils/config.js (1)

41-78: Fix network key mismatch in WalletContext.jsx: use 'ethereum-classic' not 'ethereum-classic-mainnet'

The NetworkSelector and config.js establish 'ethereum-classic' as the canonical key for ETC mainnet, but WalletContext.jsx (lines 24, 27) checks for 'ethereum-classic-mainnet'. This causes the ETC mainnet chain to never be selected—it silently defaults to Mordor testnet instead. Update both occurrences in the getExpectedChain logic to match the config key:

const expectedChainId = (function(){ return (window.__STABLEPAY_SELECTED_NETWORK__ === 'ethereum-classic' ? etcMainnet : mordor).id; })();

and

if (key === 'ethereum-classic') return etcMainnet;
🧹 Nitpick comments (1)
stablepay-sdk/src/widget/TransactionReview.jsx (1)

186-199: Explorer URL mapping: good direction; reduce drift + avoid '#' fallback
Consider sourcing the explorer base from your chain definitions / networksConfig (single source of truth), and render a non-link when unavailable to avoid '#' navigation.

Also applies to: 264-278

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a125cf and d8a9048.

⛔ Files ignored due to path filters (8)
  • stablepay-sdk/dist/assets/chevron-down-icon.svg is excluded by !**/dist/**, !**/*.svg
  • stablepay-sdk/dist/assets/stablepay-logo.svg is excluded by !**/dist/**, !**/*.svg
  • stablepay-sdk/dist/esm/index.js is excluded by !**/dist/**
  • stablepay-sdk/dist/esm/styles.css is excluded by !**/dist/**
  • stablepay-sdk/dist/umd/index.js is excluded by !**/dist/**
  • stablepay-sdk/dist/umd/index.js.map is excluded by !**/dist/**, !**/*.map
  • stablepay-sdk/dist/umd/styles.css is excluded by !**/dist/**
  • stablepay-sdk/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • stablepay-sdk/src/contexts/WalletContext.jsx (5 hunks)
  • stablepay-sdk/src/contexts/chains.js (1 hunks)
  • stablepay-sdk/src/utils/config.js (1 hunks)
  • stablepay-sdk/src/widget/TransactionReview.jsx (2 hunks)
  • stablepay-sdk/src/widget/Widget.jsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
stablepay-sdk/src/contexts/WalletContext.jsx (1)
stablepay-sdk/src/contexts/chains.js (4)
  • etcMainnet (24-42)
  • etcMainnet (24-42)
  • mordor (3-22)
  • mordor (3-22)
🔇 Additional comments (3)
stablepay-sdk/src/contexts/chains.js (1)

24-42: etcMainnet chain definition looks correct; verify viem chain shape + MetaMask add-chain payload compatibility
Especially confirm rpcUrls.default.http and blockExplorers.default.url are sufficient for your wallet_addEthereumChain usage.

stablepay-sdk/src/contexts/WalletContext.jsx (1)

61-76: Nice improvement: wallet_addEthereumChain now uses the selected chain object
Using expectedChain.* for add-chain parameters is the right direction and should prevent Mordor-specific leakage.

Also applies to: 78-80

stablepay-sdk/src/widget/TransactionReview.jsx (1)

8-8: [rewritten comment]
[classification tag]

Comment on lines +24 to +29
const expectedChainId = (function(){ return (window.__STABLEPAY_SELECTED_NETWORK__ === 'ethereum-classic-mainnet' ? etcMainnet : mordor).id; })();
const getExpectedChain = () => {
const key = window.__STABLEPAY_SELECTED_NETWORK__;
if (key === 'ethereum-classic-mainnet') return etcMainnet;
return mordor;
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

rg -n --hidden -S "__STABLEPAY_SELECTED_NETWORK__|selectedNetwork\s*[:=]" stablepay-sdk/src/

Repository: DjedAlliance/StablePay

Length of output: 731


🏁 Script executed:

wc -l stablepay-sdk/src/contexts/WalletContext.jsx

Repository: DjedAlliance/StablePay

Length of output: 114


🏁 Script executed:

cat -n stablepay-sdk/src/contexts/WalletContext.jsx | head -150

Repository: DjedAlliance/StablePay

Length of output: 6289


🏁 Script executed:

rg -n "ethereum-classic|mordor" stablepay-sdk/src/ -t js -t jsx

Repository: DjedAlliance/StablePay

Length of output: 93


🏁 Script executed:

rg -n "NetworkSelector\|selectedNetwork\s*[=:]" stablepay-sdk/src/ -B 2 -A 2

Repository: DjedAlliance/StablePay

Length of output: 48


🏁 Script executed:

cat -n stablepay-sdk/src/core/NetworkSelector.js | head -50

Repository: DjedAlliance/StablePay

Length of output: 1743


🏁 Script executed:

find stablepay-sdk/src -name "config*" -type f

Repository: DjedAlliance/StablePay

Length of output: 99


🏁 Script executed:

rg -n "ethereum-classic\|mordor" stablepay-sdk/src/

Repository: DjedAlliance/StablePay

Length of output: 48


🏁 Script executed:

rg -n "networksConfig\s*=" stablepay-sdk/src/ -A 20

Repository: DjedAlliance/StablePay

Length of output: 1344


🏁 Script executed:

cat stablepay-sdk/src/utils/config.js

Repository: DjedAlliance/StablePay

Length of output: 1975


🏁 Script executed:

cat stablepay-sdk/src/contexts/chains.js

Repository: DjedAlliance/StablePay

Length of output: 963


🏁 Script executed:

cat -n stablepay-sdk/src/contexts/WalletContext.jsx | sed -n '52,57p;61,70p;83,93p;117,125p'

Repository: DjedAlliance/StablePay

Length of output: 1874


🏁 Script executed:

rg -n "selectedNetwork\|__STABLEPAY_SELECTED_NETWORK__" stablepay-sdk/src/ -B 1 -A 3

Repository: DjedAlliance/StablePay

Length of output: 48


🏁 Script executed:

grep -n "ethereum-classic-mainnet\|'mordor'" stablepay-sdk/src/contexts/WalletContext.jsx

Repository: DjedAlliance/StablePay

Length of output: 283


Fix critical network key mismatch and stale expectedChainId

Code checks for 'ethereum-classic-mainnet' and 'mordor' but config defines 'ethereum-classic' and 'mordor-testnet'. When users select ETC mainnet via config, getExpectedChain() fails to match and incorrectly defaults to Mordor. Additionally, expectedChainId computed once at line 24 becomes stale if the network selection changes, breaking chain switching logic at lines 52 and 56.

-  const expectedChainId = (function(){ return (window.__STABLEPAY_SELECTED_NETWORK__ === 'ethereum-classic-mainnet' ? etcMainnet : mordor).id; })();
-  const getExpectedChain = () => {
-    const key = window.__STABLEPAY_SELECTED_NETWORK__;
-    if (key === 'ethereum-classic-mainnet') return etcMainnet;
-    return mordor;
-  };
+  const getExpectedChain = () => {
+    const key = (typeof window !== "undefined" ? window.__STABLEPAY_SELECTED_NETWORK__ : null);
+    if (key === "ethereum-classic" || key === "ethereum-classic-mainnet") return etcMainnet;
+    if (key === "mordor-testnet" || key === "mordor") return mordor;
+    return mordor;
+  };
@@
-      if (currentChainId !== expectedChainId) {
+      const expectedChain = getExpectedChain();
+      if (currentChainId !== expectedChain.id) {
         try {
           await window.ethereum.request({
             method: 'wallet_switchEthereumChain',
-            params: [{ chainId: `0x${expectedChainId.toString(16)}` }],
+            params: [{ chainId: `0x${expectedChain.id.toString(16)}` }],
           });
         } catch (switchError) {
           if (switchError.code === 4902) {
             try {
-              const expectedChain = getExpectedChain();
               await window.ethereum.request({
                 method: 'wallet_addEthereumChain',
                 params: [
                   {
                     chainId: `0x${expectedChain.id.toString(16)}`,
                     chainName: expectedChain.name,
                     nativeCurrency: expectedChain.nativeCurrency,
                     rpcUrls: expectedChain.rpcUrls.default.http,
                     blockExplorerUrls: [expectedChain.blockExplorers.default.url],
                   },
                 ],
               });

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In stablepay-sdk/src/contexts/WalletContext.jsx around lines 24 to 29, the
network key checks use incorrect literals and compute expectedChainId only once
making it stale; change getExpectedChain to check for 'ethereum-classic' and
'mordor-testnet' (matching config) and remove the IIFE that sets a one-time
expectedChainId; instead derive the chain id dynamically by calling
getExpectedChain().id where needed (update usages at lines ~52 and ~56) so
network changes reflect immediately.

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.

Add Ethereum Classic Mainnet Support and Rename Testnet to Mordor in StablePay SDK

1 participant