|
@@ -23,7 +23,6 @@ import {
|
|
|
useCallback,
|
|
useCallback,
|
|
|
useMemo,
|
|
useMemo,
|
|
|
} from "react";
|
|
} from "react";
|
|
|
-import Markdown from "react-markdown";
|
|
|
|
|
import { useSwitchChain, useChainId, useConfig } from "wagmi";
|
|
import { useSwitchChain, useChainId, useConfig } from "wagmi";
|
|
|
import { readContract } from "wagmi/actions";
|
|
import { readContract } from "wagmi/actions";
|
|
|
|
|
|
|
@@ -32,11 +31,11 @@ import { ParameterInput } from "./parameter-input";
|
|
|
import { type EvmApiType, RunButton } from "./run-button";
|
|
import { type EvmApiType, RunButton } from "./run-button";
|
|
|
import { getLogger } from "../../browser-logger";
|
|
import { getLogger } from "../../browser-logger";
|
|
|
import { getContractAddress } from "../../evm-networks";
|
|
import { getContractAddress } from "../../evm-networks";
|
|
|
-import { MARKDOWN_COMPONENTS } from "../../markdown-components";
|
|
|
|
|
import { useIsMounted } from "../../use-is-mounted";
|
|
import { useIsMounted } from "../../use-is-mounted";
|
|
|
import { type SupportedLanguage, Code } from "../Code";
|
|
import { type SupportedLanguage, Code } from "../Code";
|
|
|
import { ErrorTooltip } from "../ErrorTooltip";
|
|
import { ErrorTooltip } from "../ErrorTooltip";
|
|
|
import { InlineLink } from "../InlineLink";
|
|
import { InlineLink } from "../InlineLink";
|
|
|
|
|
+import { Markdown } from "../Markdown";
|
|
|
import { Select } from "../Select";
|
|
import { Select } from "../Select";
|
|
|
|
|
|
|
|
export { ParameterType } from "./parameter";
|
|
export { ParameterType } from "./parameter";
|
|
@@ -127,138 +126,143 @@ export const EvmApi = <ParameterName extends string>({
|
|
|
}, [chainId, chains, isMounted]);
|
|
}, [chainId, chains, isMounted]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div className="gap-x-20 lg:grid lg:grid-cols-[2fr_1fr]">
|
|
|
|
|
- <h1 className="col-span-2 mb-6 font-mono text-4xl font-medium">{name}</h1>
|
|
|
|
|
- <div className="col-span-2 mb-6 opacity-60">
|
|
|
|
|
- <Markdown components={MARKDOWN_COMPONENTS}>{summary}</Markdown>
|
|
|
|
|
|
|
+ <>
|
|
|
|
|
+ <h1 className="mb-6 font-mono text-4xl font-medium">{name}</h1>
|
|
|
|
|
+ <div className="mb-6 opacity-60">
|
|
|
|
|
+ <Markdown>{summary}</Markdown>
|
|
|
</div>
|
|
</div>
|
|
|
- <section>
|
|
|
|
|
- <h2 className="mb-4 border-b border-neutral-200 text-2xl/loose font-medium dark:border-neutral-800">
|
|
|
|
|
- Description
|
|
|
|
|
- </h2>
|
|
|
|
|
- <Markdown components={MARKDOWN_COMPONENTS}>{description}</Markdown>
|
|
|
|
|
- </section>
|
|
|
|
|
- <section className="flex min-w-0 flex-col">
|
|
|
|
|
- <h2 className="mb-4 border-b border-neutral-200 text-2xl/loose font-medium dark:border-neutral-800">
|
|
|
|
|
- Arguments
|
|
|
|
|
- </h2>
|
|
|
|
|
- <div className="mb-8">
|
|
|
|
|
- {parameters.length > 0 ? (
|
|
|
|
|
- <ul className="flex flex-col gap-4">
|
|
|
|
|
- {parameters.map((parameter) => (
|
|
|
|
|
- <li key={parameter.name} className="contents">
|
|
|
|
|
- <ParameterInput
|
|
|
|
|
- spec={parameter}
|
|
|
|
|
- value={paramValues[parameter.name]}
|
|
|
|
|
- setParamValues={setParamValues}
|
|
|
|
|
- />
|
|
|
|
|
- </li>
|
|
|
|
|
- ))}
|
|
|
|
|
- </ul>
|
|
|
|
|
- ) : (
|
|
|
|
|
- <div className="rounded-lg bg-neutral-200 p-8 text-center text-sm dark:bg-neutral-800">
|
|
|
|
|
- This API takes no arguments
|
|
|
|
|
- </div>
|
|
|
|
|
- )}
|
|
|
|
|
- </div>
|
|
|
|
|
- {examples && examples.length > 0 && (
|
|
|
|
|
|
|
+ <div className="grid grid-cols-1 gap-20 lg:grid-cols-[3fr_2fr] 2xl:grid-cols-[1fr_28rem]">
|
|
|
|
|
+ <section>
|
|
|
|
|
+ <h2 className="mb-4 border-b border-neutral-200 text-2xl/loose font-medium dark:border-neutral-800">
|
|
|
|
|
+ Description
|
|
|
|
|
+ </h2>
|
|
|
|
|
+ <Markdown>{description}</Markdown>
|
|
|
|
|
+ </section>
|
|
|
|
|
+ <section className="flex min-w-0 flex-col">
|
|
|
|
|
+ <h2 className="mb-4 border-b border-neutral-200 text-2xl/loose font-medium dark:border-neutral-800">
|
|
|
|
|
+ Arguments
|
|
|
|
|
+ </h2>
|
|
|
<div className="mb-8">
|
|
<div className="mb-8">
|
|
|
- <h3 className="text-sm font-semibold">Examples</h3>
|
|
|
|
|
- <ul className="ml-2 text-sm">
|
|
|
|
|
- {examples.map((example) => (
|
|
|
|
|
- <li key={example.name}>
|
|
|
|
|
- <Example example={example} setParamValues={setParamValues} />
|
|
|
|
|
- </li>
|
|
|
|
|
- ))}
|
|
|
|
|
- </ul>
|
|
|
|
|
- </div>
|
|
|
|
|
- )}
|
|
|
|
|
- <Field className="mb-4 flex w-full flex-row items-center gap-2">
|
|
|
|
|
- <Label className="text-sm font-bold">Network</Label>
|
|
|
|
|
- <Select
|
|
|
|
|
- value={currentChain}
|
|
|
|
|
- onChange={({ id }) => {
|
|
|
|
|
- switchChain({ chainId: id });
|
|
|
|
|
- }}
|
|
|
|
|
- renderButtonContents={({ id, name }) => (
|
|
|
|
|
- <div className="flex h-8 grow basis-0 flex-row items-center gap-2 overflow-hidden">
|
|
|
|
|
- {isMounted && (
|
|
|
|
|
- <>
|
|
|
|
|
- <ChainIcon id={id} />
|
|
|
|
|
- <div className="grow basis-0 truncate">{name}</div>
|
|
|
|
|
- </>
|
|
|
|
|
- )}
|
|
|
|
|
- </div>
|
|
|
|
|
- )}
|
|
|
|
|
- renderOption={({ id, name }) => (
|
|
|
|
|
- <div key={id} className="flex flex-row items-center gap-2">
|
|
|
|
|
- <ChainIcon id={id} />
|
|
|
|
|
- <span>{name}</span>
|
|
|
|
|
|
|
+ {parameters.length > 0 ? (
|
|
|
|
|
+ <ul className="flex flex-col gap-4">
|
|
|
|
|
+ {parameters.map((parameter) => (
|
|
|
|
|
+ <li key={parameter.name} className="contents">
|
|
|
|
|
+ <ParameterInput
|
|
|
|
|
+ spec={parameter}
|
|
|
|
|
+ value={paramValues[parameter.name]}
|
|
|
|
|
+ setParamValues={setParamValues}
|
|
|
|
|
+ />
|
|
|
|
|
+ </li>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </ul>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <div className="rounded-lg bg-neutral-200 p-8 text-center text-sm dark:bg-neutral-800">
|
|
|
|
|
+ This API takes no arguments
|
|
|
</div>
|
|
</div>
|
|
|
)}
|
|
)}
|
|
|
- optionGroups={[
|
|
|
|
|
- {
|
|
|
|
|
- name: "Mainnet",
|
|
|
|
|
- options: chains
|
|
|
|
|
- .filter((chain) => !chain.testnet)
|
|
|
|
|
- .sort((a, b) => a.name.localeCompare(b.name)),
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- name: "Testnet",
|
|
|
|
|
- options: chains
|
|
|
|
|
- .filter((chain) => chain.testnet)
|
|
|
|
|
- .sort((a, b) => a.name.localeCompare(b.name)),
|
|
|
|
|
- },
|
|
|
|
|
- ]}
|
|
|
|
|
- filter={(chains, value) =>
|
|
|
|
|
- chains.filter((chain) =>
|
|
|
|
|
- chain.name.toLowerCase().includes(value.toLowerCase()),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- className="min-w-0 grow"
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {examples && examples.length > 0 && (
|
|
|
|
|
+ <div className="mb-8">
|
|
|
|
|
+ <h3 className="text-sm font-semibold">Examples</h3>
|
|
|
|
|
+ <ul className="ml-2 text-sm">
|
|
|
|
|
+ {examples.map((example) => (
|
|
|
|
|
+ <li key={example.name}>
|
|
|
|
|
+ <Example
|
|
|
|
|
+ example={example}
|
|
|
|
|
+ setParamValues={setParamValues}
|
|
|
|
|
+ />
|
|
|
|
|
+ </li>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </ul>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ <Field className="mb-4 flex w-full flex-row items-center gap-2">
|
|
|
|
|
+ <Label className="text-sm font-bold">Network</Label>
|
|
|
|
|
+ <Select
|
|
|
|
|
+ value={currentChain}
|
|
|
|
|
+ onChange={({ id }) => {
|
|
|
|
|
+ switchChain({ chainId: id });
|
|
|
|
|
+ }}
|
|
|
|
|
+ renderButtonContents={({ id, name }) => (
|
|
|
|
|
+ <div className="flex h-8 grow basis-0 flex-row items-center gap-2 overflow-hidden">
|
|
|
|
|
+ {isMounted && (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <ChainIcon id={id} />
|
|
|
|
|
+ <div className="grow basis-0 truncate">{name}</div>
|
|
|
|
|
+ </>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ renderOption={({ id, name }) => (
|
|
|
|
|
+ <div key={id} className="flex flex-row items-center gap-2">
|
|
|
|
|
+ <ChainIcon id={id} />
|
|
|
|
|
+ <span>{name}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+ optionGroups={[
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Mainnet",
|
|
|
|
|
+ options: chains
|
|
|
|
|
+ .filter((chain) => !chain.testnet)
|
|
|
|
|
+ .sort((a, b) => a.name.localeCompare(b.name)),
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Testnet",
|
|
|
|
|
+ options: chains
|
|
|
|
|
+ .filter((chain) => chain.testnet)
|
|
|
|
|
+ .sort((a, b) => a.name.localeCompare(b.name)),
|
|
|
|
|
+ },
|
|
|
|
|
+ ]}
|
|
|
|
|
+ filter={(chains, value) =>
|
|
|
|
|
+ chains.filter((chain) =>
|
|
|
|
|
+ chain.name.toLowerCase().includes(value.toLowerCase()),
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ className="min-w-0 grow"
|
|
|
|
|
+ />
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <RunButton
|
|
|
|
|
+ functionName={name}
|
|
|
|
|
+ parameters={parameters}
|
|
|
|
|
+ paramValues={paramValues}
|
|
|
|
|
+ {...props}
|
|
|
/>
|
|
/>
|
|
|
- </Field>
|
|
|
|
|
- <RunButton
|
|
|
|
|
- functionName={name}
|
|
|
|
|
- parameters={parameters}
|
|
|
|
|
- paramValues={paramValues}
|
|
|
|
|
- {...props}
|
|
|
|
|
- />
|
|
|
|
|
- </section>
|
|
|
|
|
- <TabGroup className="col-span-2 mt-24">
|
|
|
|
|
- <TabList className="mb-4 flex flex-row gap-2 border-b border-neutral-200 pb-px dark:border-neutral-800">
|
|
|
|
|
- {code.map(({ language }) => (
|
|
|
|
|
- <Tab
|
|
|
|
|
- key={LANGUAGE_TO_DISPLAY_NAME[language]}
|
|
|
|
|
- className="mb-[-2px] border-b-2 border-transparent px-2 text-sm font-medium leading-loose hover:text-pythpurple-600 data-[selected]:cursor-default data-[selected]:border-pythpurple-600 data-[selected]:text-pythpurple-600 dark:hover:text-pythpurple-400 dark:data-[selected]:border-pythpurple-400 dark:data-[selected]:text-pythpurple-400"
|
|
|
|
|
- >
|
|
|
|
|
- {LANGUAGE_TO_DISPLAY_NAME[language]}
|
|
|
|
|
- </Tab>
|
|
|
|
|
- ))}
|
|
|
|
|
- </TabList>
|
|
|
|
|
- <TabPanels>
|
|
|
|
|
- {code.map(({ code: codeContents, language, dimRange }) => (
|
|
|
|
|
- <TabPanel key={LANGUAGE_TO_DISPLAY_NAME[language]}>
|
|
|
|
|
- <Code
|
|
|
|
|
- language={LANUGAGE_TO_SHIKI_NAME[language]}
|
|
|
|
|
- dimRange={dimRange}
|
|
|
|
|
|
|
+ </section>
|
|
|
|
|
+ <TabGroup className="lg:col-span-2">
|
|
|
|
|
+ <TabList className="mb-4 flex flex-row gap-2 border-b border-neutral-200 pb-px dark:border-neutral-800">
|
|
|
|
|
+ {code.map(({ language }) => (
|
|
|
|
|
+ <Tab
|
|
|
|
|
+ key={LANGUAGE_TO_DISPLAY_NAME[language]}
|
|
|
|
|
+ className="mb-[-2px] border-b-2 border-transparent px-2 text-sm font-medium leading-loose hover:text-pythpurple-600 data-[selected]:cursor-default data-[selected]:border-pythpurple-600 data-[selected]:text-pythpurple-600 dark:hover:text-pythpurple-400 dark:data-[selected]:border-pythpurple-400 dark:data-[selected]:text-pythpurple-400"
|
|
|
>
|
|
>
|
|
|
- {codeContents(
|
|
|
|
|
- isMounted
|
|
|
|
|
- ? {
|
|
|
|
|
- name: currentChain.name,
|
|
|
|
|
- rpcUrl: currentChain.rpcUrls.default.http[0] ?? "",
|
|
|
|
|
- contractAddress: getContractAddress(chainId) ?? "",
|
|
|
|
|
- }
|
|
|
|
|
- : { name: "", rpcUrl: "", contractAddress: "" },
|
|
|
|
|
- paramValues,
|
|
|
|
|
- )}
|
|
|
|
|
- </Code>
|
|
|
|
|
- </TabPanel>
|
|
|
|
|
- ))}
|
|
|
|
|
- </TabPanels>
|
|
|
|
|
- </TabGroup>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ {LANGUAGE_TO_DISPLAY_NAME[language]}
|
|
|
|
|
+ </Tab>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </TabList>
|
|
|
|
|
+ <TabPanels>
|
|
|
|
|
+ {code.map(({ code: codeContents, language, dimRange }) => (
|
|
|
|
|
+ <TabPanel key={LANGUAGE_TO_DISPLAY_NAME[language]}>
|
|
|
|
|
+ <Code
|
|
|
|
|
+ language={LANUGAGE_TO_SHIKI_NAME[language]}
|
|
|
|
|
+ dimRange={dimRange}
|
|
|
|
|
+ >
|
|
|
|
|
+ {codeContents(
|
|
|
|
|
+ isMounted
|
|
|
|
|
+ ? {
|
|
|
|
|
+ name: currentChain.name,
|
|
|
|
|
+ rpcUrl: currentChain.rpcUrls.default.http[0] ?? "",
|
|
|
|
|
+ contractAddress: getContractAddress(chainId) ?? "",
|
|
|
|
|
+ }
|
|
|
|
|
+ : { name: "", rpcUrl: "", contractAddress: "" },
|
|
|
|
|
+ paramValues,
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Code>
|
|
|
|
|
+ </TabPanel>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </TabPanels>
|
|
|
|
|
+ </TabGroup>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|