Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@heroicons/react": "catalog:",
"@next/third-parties": "catalog:",
"@pythnetwork/client": "catalog:",
"@pythnetwork/contract-manager": "workspace:*",
"@pythnetwork/pyth-sdk-solidity": "workspace:*",
"@solana/web3.js": "catalog:",
"@tanstack/react-query": "catalog:",
Expand Down
12 changes: 6 additions & 6 deletions apps/api-reference/src/components/EvmApi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Label,
} from "@headlessui/react";
import { ArrowPathIcon } from "@heroicons/react/24/outline";
import { getEvmPriceFeedContractAddress } from "@pythnetwork/contract-manager/utils/utils";
import PythAbi from "@pythnetwork/pyth-sdk-solidity/abis/IPyth.json";
import PythErrorsAbi from "@pythnetwork/pyth-sdk-solidity/abis/PythErrors.json";
import { ChainIcon } from "connectkit";
Expand All @@ -29,7 +30,6 @@ import { ParameterInput } from "./parameter-input";
import type { EvmApiType } from "./run-button";
import { RunButton } from "./run-button";
import { getLogger } from "../../browser-logger";
import { getContractAddress } from "../../evm-networks";
import { useIsMounted } from "../../use-is-mounted";
import type { SupportedLanguage } from "../Code";
import { Code } from "../Code";
Expand Down Expand Up @@ -251,7 +251,8 @@ export const EvmApi = <ParameterName extends string>({
? {
name: currentChain.name,
rpcUrl: currentChain.rpcUrls.default.http[0] ?? "",
contractAddress: getContractAddress(chainId) ?? "",
contractAddress:
getEvmPriceFeedContractAddress(chainId) ?? "",
}
: { name: "", rpcUrl: "", contractAddress: "" },
paramValues,
Expand Down Expand Up @@ -294,11 +295,10 @@ const Example = <ParameterName extends string>({
const updateValues = useCallback(() => {
if (typeof example.parameters === "function") {
setError(undefined);
const address = getContractAddress(config.state.chainId);
const address = getEvmPriceFeedContractAddress(config.state.chainId);
if (!address) {
throw new Error(
`No contract for chain id: ${config.state.chainId.toString()}`,
);
setError("No contract address found for this chain");
return;
}
const params = example.parameters({
readContract: (functionName, args) =>
Expand Down
9 changes: 4 additions & 5 deletions apps/api-reference/src/components/EvmApi/run-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

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

import type { Parameter } from "./parameter";
import { TRANSFORMS } from "./parameter";
import { getContractAddress } from "../../evm-networks";
import { useIsMounted } from "../../use-is-mounted";
import { Button } from "../Button";
import { Code } from "../Code";
Expand Down Expand Up @@ -166,11 +166,10 @@ const useRunButton = <ParameterName extends string>({
if (args === undefined) {
setStatus(ErrorStatus(new Error("Invalid parameters!")));
} else {
const address = getContractAddress(config.state.chainId);
const address = getEvmPriceFeedContractAddress(config.state.chainId);
if (!address) {
throw new Error(
`No contract for chain id: ${config.state.chainId.toString()}`,
);
setStatus(ErrorStatus(new Error("No address found!")));
return;
}
switch (props.type) {
case EvmApiType.Read: {
Expand Down
20 changes: 8 additions & 12 deletions apps/api-reference/src/components/EvmProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
"use client";

import {
getEvmChainRpcUrl,
getAllEvmChainsIds,
} from "@pythnetwork/contract-manager/utils/utils";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ConnectKitProvider, getDefaultConfig } from "connectkit";
import { useTheme } from "next-themes";
import type { ReactNode } from "react";
import * as chains from "viem/chains";
import { WagmiProvider, createConfig, http, useChainId } from "wagmi";

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

const CHAINS = NETWORK_IDS.map((id) =>
Object.values(chains).find((chain) => chain.id === id),
).filter((chain) => chain !== undefined) as unknown as readonly [
const CHAINS = getAllEvmChainsIds
.map((id) => Object.values(chains).find((chain) => chain.id === id))
.filter((chain) => chain !== undefined) as unknown as readonly [
chains.Chain,
...chains.Chain[],
];

const TRANSPORTS = Object.fromEntries(
CHAINS.map((chain) => {
const url = getRpcUrl(chain.id);
if (url) {
return [chain.id, http(url)];
} else {
throw new Error(`No rpc url found for ${chain.name}`);
}
}),
CHAINS.map((chain) => [chain.id, http(getEvmChainRpcUrl(chain.id))]),
);

type EvmProviderProps = {
Expand Down
Loading
Loading