Add optional Chain 2138 frontend support

This commit is contained in:
defiQUG
2026-03-28 15:38:51 -07:00
parent 6deb072fa7
commit 1771db2190
31 changed files with 408 additions and 187 deletions

View File

@@ -1,8 +1,11 @@
import { useAccount, useConnect, useDisconnect, useChainId, useSwitchChain } from 'wagmi'
import { useEffect, useState, useRef } from 'react'
const CHAIN_138_ID = 138
const EXPLORER_URL = 'https://explorer.d-bis.org'
import {
defaultFrontendChainId,
defaultFrontendChainName,
defaultFrontendExplorerUrl,
frontendSourceChainIds,
} from '../../config/networks'
interface WalletConnectProps {
/** Callback before disconnect so we can treat it as user-initiated (no "disconnected" toast). */
@@ -21,7 +24,7 @@ export default function WalletConnect({ onBeforeDisconnect }: WalletConnectProps
const dropdownRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (isConnected && chainId !== CHAIN_138_ID) {
if (isConnected && !frontendSourceChainIds.includes(chainId)) {
setShowChainWarning(true)
} else {
setShowChainWarning(false)
@@ -40,7 +43,7 @@ export default function WalletConnect({ onBeforeDisconnect }: WalletConnectProps
const handleSwitchChain = async () => {
try {
await switchChain({ chainId: CHAIN_138_ID })
await switchChain({ chainId: defaultFrontendChainId })
} catch (error) {
console.error('Failed to switch chain:', error)
}
@@ -59,7 +62,7 @@ export default function WalletConnect({ onBeforeDisconnect }: WalletConnectProps
}
const viewOnExplorer = () => {
if (address) window.open(`${EXPLORER_URL}/address/${address}`, '_blank', 'noopener')
if (address) window.open(`${defaultFrontendExplorerUrl}/address/${address}`, '_blank', 'noopener')
setShowDropdown(false)
}
@@ -81,7 +84,7 @@ export default function WalletConnect({ onBeforeDisconnect }: WalletConnectProps
Switching...
</>
) : (
'Switch to Chain 138'
`Switch to ${defaultFrontendChainName}`
)}
</button>
)}