Skip to content

Commit e4f385f

Browse files
authored
chore(api-reference) Add Contract Manager Support (#2785)
* chore(api-reference) Add Contract Manager Support * chore(api-reference) Add viem RPC as a backup * update * update * udpate * update * update * update * removed comments * update * update
1 parent e130743 commit e4f385f

File tree

8 files changed

+101
-998
lines changed

8 files changed

+101
-998
lines changed

apps/api-reference/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@heroicons/react": "catalog:",
2626
"@next/third-parties": "catalog:",
2727
"@pythnetwork/client": "catalog:",
28+
"@pythnetwork/contract-manager": "workspace:*",
2829
"@pythnetwork/pyth-sdk-solidity": "workspace:*",
2930
"@solana/web3.js": "catalog:",
3031
"@tanstack/react-query": "catalog:",

apps/api-reference/src/components/EvmApi/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Label,
1111
} from "@headlessui/react";
1212
import { ArrowPathIcon } from "@heroicons/react/24/outline";
13+
import { getEvmPriceFeedContractAddress } from "@pythnetwork/contract-manager/utils/utils";
1314
import PythAbi from "@pythnetwork/pyth-sdk-solidity/abis/IPyth.json";
1415
import PythErrorsAbi from "@pythnetwork/pyth-sdk-solidity/abis/PythErrors.json";
1516
import { ChainIcon } from "connectkit";
@@ -29,7 +30,6 @@ import { ParameterInput } from "./parameter-input";
2930
import type { EvmApiType } from "./run-button";
3031
import { RunButton } from "./run-button";
3132
import { getLogger } from "../../browser-logger";
32-
import { getContractAddress } from "../../evm-networks";
3333
import { useIsMounted } from "../../use-is-mounted";
3434
import type { SupportedLanguage } from "../Code";
3535
import { Code } from "../Code";
@@ -251,7 +251,8 @@ export const EvmApi = <ParameterName extends string>({
251251
? {
252252
name: currentChain.name,
253253
rpcUrl: currentChain.rpcUrls.default.http[0] ?? "",
254-
contractAddress: getContractAddress(chainId) ?? "",
254+
contractAddress:
255+
getEvmPriceFeedContractAddress(chainId) ?? "",
255256
}
256257
: { name: "", rpcUrl: "", contractAddress: "" },
257258
paramValues,
@@ -294,11 +295,10 @@ const Example = <ParameterName extends string>({
294295
const updateValues = useCallback(() => {
295296
if (typeof example.parameters === "function") {
296297
setError(undefined);
297-
const address = getContractAddress(config.state.chainId);
298+
const address = getEvmPriceFeedContractAddress(config.state.chainId);
298299
if (!address) {
299-
throw new Error(
300-
`No contract for chain id: ${config.state.chainId.toString()}`,
301-
);
300+
setError("No contract address found for this chain");
301+
return;
302302
}
303303
const params = example.parameters({
304304
readContract: (functionName, args) =>

apps/api-reference/src/components/EvmApi/run-button.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { ArrowPathIcon } from "@heroicons/react/24/outline";
4+
import { getEvmPriceFeedContractAddress } from "@pythnetwork/contract-manager/utils/utils";
45
import PythAbi from "@pythnetwork/pyth-sdk-solidity/abis/IPyth.json";
56
import PythErrorsAbi from "@pythnetwork/pyth-sdk-solidity/abis/PythErrors.json";
67
import { ConnectKitButton, Avatar } from "connectkit";
@@ -11,7 +12,6 @@ import { readContract, simulateContract, writeContract } from "wagmi/actions";
1112

1213
import type { Parameter } from "./parameter";
1314
import { TRANSFORMS } from "./parameter";
14-
import { getContractAddress } from "../../evm-networks";
1515
import { useIsMounted } from "../../use-is-mounted";
1616
import { Button } from "../Button";
1717
import { Code } from "../Code";
@@ -166,11 +166,10 @@ const useRunButton = <ParameterName extends string>({
166166
if (args === undefined) {
167167
setStatus(ErrorStatus(new Error("Invalid parameters!")));
168168
} else {
169-
const address = getContractAddress(config.state.chainId);
169+
const address = getEvmPriceFeedContractAddress(config.state.chainId);
170170
if (!address) {
171-
throw new Error(
172-
`No contract for chain id: ${config.state.chainId.toString()}`,
173-
);
171+
setStatus(ErrorStatus(new Error("No address found!")));
172+
return;
174173
}
175174
switch (props.type) {
176175
case EvmApiType.Read: {

apps/api-reference/src/components/EvmProvider/index.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
"use client";
22

3+
import {
4+
getEvmChainRpcUrl,
5+
allEvmChainIds,
6+
} from "@pythnetwork/contract-manager/utils/utils";
37
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
48
import { ConnectKitProvider, getDefaultConfig } from "connectkit";
59
import { useTheme } from "next-themes";
610
import type { ReactNode } from "react";
711
import * as chains from "viem/chains";
812
import { WagmiProvider, createConfig, http, useChainId } from "wagmi";
913

10-
import { NETWORK_IDS, getRpcUrl } from "../../evm-networks";
1114
import { metadata } from "../../metadata";
1215

13-
const CHAINS = NETWORK_IDS.map((id) =>
14-
Object.values(chains).find((chain) => chain.id === id),
15-
).filter((chain) => chain !== undefined) as unknown as readonly [
16+
const CHAINS = allEvmChainIds
17+
.map((id) => Object.values(chains).find((chain) => chain.id === id))
18+
.filter((chain) => chain !== undefined) as unknown as readonly [
1619
chains.Chain,
1720
...chains.Chain[],
1821
];
1922

2023
const TRANSPORTS = Object.fromEntries(
21-
CHAINS.map((chain) => {
22-
const url = getRpcUrl(chain.id);
23-
if (url) {
24-
return [chain.id, http(url)];
25-
} else {
26-
throw new Error(`No rpc url found for ${chain.name}`);
27-
}
28-
}),
24+
CHAINS.map((chain) => [chain.id, http(getEvmChainRpcUrl(chain.id))]),
2925
);
3026

3127
type EvmProviderProps = {

0 commit comments

Comments
 (0)