Skip to content

Commit 7c5911a

Browse files
committed
Add ability to use local openrpc spec.
Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
1 parent 5d6480d commit 7c5911a

File tree

2 files changed

+19325
-4
lines changed

2 files changed

+19325
-4
lines changed

src/components/ParserOpenRPC/index.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ import useIsBrowser from '@docusaurus/useIsBrowser'
1919
import { encrypt } from '@metamask/eth-sig-util'
2020
import { hexlify } from 'ethers'
2121

22+
// Import local specs
23+
import localLineaSpec from '@site/src/specs/linea/openrpc.json'
24+
2225
interface ParserProps {
2326
network: NETWORK_NAMES
2427
method?: string
2528
extraContent?: JSX.Element
29+
src?: 'local' | 'remote'
2630
}
2731

2832
interface ParserOpenRPCContextProps {
@@ -35,7 +39,12 @@ interface ParserOpenRPCContextProps {
3539

3640
export const ParserOpenRPCContext = createContext<ParserOpenRPCContextProps | null>(null)
3741

38-
export default function ParserOpenRPC({ network, method, extraContent }: ParserProps) {
42+
export default function ParserOpenRPC({
43+
network,
44+
method,
45+
extraContent,
46+
src = 'remote',
47+
}: ParserProps) {
3948
const isBrowser = useIsBrowser()
4049
if (!isBrowser) {
4150
return null
@@ -79,9 +88,18 @@ export default function ParserOpenRPC({ network, method, extraContent }: ParserP
7988
const { netData } = usePluginData('plugin-json-rpc') as {
8089
netData?: ResponseItem[]
8190
}
82-
const currentNetwork = netData?.find(net => net.name === network)
8391

84-
if (!currentNetwork && currentNetwork.error) return null
92+
// Use local data when src="local", otherwise use plugin data
93+
const currentNetwork =
94+
src === 'local'
95+
? {
96+
name: network,
97+
data: network === NETWORK_NAMES.linea ? localLineaSpec : null,
98+
error: network !== NETWORK_NAMES.linea, // Error if local spec not available for this network
99+
}
100+
: netData?.find(net => net.name === network)
101+
102+
if (!currentNetwork || currentNetwork.error) return null
85103

86104
const currentMethodData = useMemo(() => {
87105
const findReferencedItem = (items, refPath, componentType) => {
@@ -136,7 +154,7 @@ export default function ParserOpenRPC({ network, method, extraContent }: ParserP
136154
tags,
137155
servers: currentNetwork.data?.servers?.[0]?.url || null,
138156
}
139-
}, [currentNetwork, method])
157+
}, [currentNetwork, method, src])
140158

141159
if (currentMethodData === null) return null
142160

0 commit comments

Comments
 (0)