18/add ethereum classic mainnet support and rename testnet to mordor in stablepay sdk#30
Conversation
…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
WalkthroughThe 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 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 mutatingwindowduring render; guardwindowfor 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(notnetworkSelector.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
⛔ Files ignored due to path filters (8)
stablepay-sdk/dist/assets/chevron-down-icon.svgis excluded by!**/dist/**,!**/*.svgstablepay-sdk/dist/assets/stablepay-logo.svgis excluded by!**/dist/**,!**/*.svgstablepay-sdk/dist/esm/index.jsis excluded by!**/dist/**stablepay-sdk/dist/esm/styles.cssis excluded by!**/dist/**stablepay-sdk/dist/umd/index.jsis excluded by!**/dist/**stablepay-sdk/dist/umd/index.js.mapis excluded by!**/dist/**,!**/*.mapstablepay-sdk/dist/umd/styles.cssis excluded by!**/dist/**stablepay-sdk/package-lock.jsonis 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:etcMainnetchain definition looks correct; verify viem chain shape + MetaMask add-chain payload compatibility
Especially confirmrpcUrls.default.httpandblockExplorers.default.urlare sufficient for yourwallet_addEthereumChainusage.stablepay-sdk/src/contexts/WalletContext.jsx (1)
61-76: Nice improvement:wallet_addEthereumChainnow uses the selected chain object
UsingexpectedChain.*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]
| 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; | ||
| }; |
There was a problem hiding this comment.
🧩 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.jsxRepository: DjedAlliance/StablePay
Length of output: 114
🏁 Script executed:
cat -n stablepay-sdk/src/contexts/WalletContext.jsx | head -150Repository: DjedAlliance/StablePay
Length of output: 6289
🏁 Script executed:
rg -n "ethereum-classic|mordor" stablepay-sdk/src/ -t js -t jsxRepository: DjedAlliance/StablePay
Length of output: 93
🏁 Script executed:
rg -n "NetworkSelector\|selectedNetwork\s*[=:]" stablepay-sdk/src/ -B 2 -A 2Repository: DjedAlliance/StablePay
Length of output: 48
🏁 Script executed:
cat -n stablepay-sdk/src/core/NetworkSelector.js | head -50Repository: DjedAlliance/StablePay
Length of output: 1743
🏁 Script executed:
find stablepay-sdk/src -name "config*" -type fRepository: 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 20Repository: DjedAlliance/StablePay
Length of output: 1344
🏁 Script executed:
cat stablepay-sdk/src/utils/config.jsRepository: DjedAlliance/StablePay
Length of output: 1975
🏁 Script executed:
cat stablepay-sdk/src/contexts/chains.jsRepository: 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 3Repository: DjedAlliance/StablePay
Length of output: 48
🏁 Script executed:
grep -n "ethereum-classic-mainnet\|'mordor'" stablepay-sdk/src/contexts/WalletContext.jsxRepository: 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.
Resolved #18
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.