diff --git a/apps/dashboard/src/app/(dashboard)/chain/validate/ChainValidation.tsx b/apps/dashboard/src/app/(dashboard)/chain/validate/ChainValidation.tsx deleted file mode 100644 index b714c5893bb..00000000000 --- a/apps/dashboard/src/app/(dashboard)/chain/validate/ChainValidation.tsx +++ /dev/null @@ -1,180 +0,0 @@ -"use client"; - -import { InlineCode } from "@/components/ui/inline-code"; -import { TableContainer } from "@/components/ui/table"; -import { - FormControl, - Input, - InputGroup, - Table, - Tbody, - Td, - Th, - Thead, - Tr, -} from "@chakra-ui/react"; -import { useTrack } from "hooks/analytics/useTrack"; -import { useRpcValidation } from "hooks/chains/useRpcValidation"; -import { AlertCircleIcon, CheckCircleIcon } from "lucide-react"; -import { type ChangeEvent, useState } from "react"; -import { Button, Card, FormLabel, Link } from "tw-components"; - -const StatusCheck = (props: { - status: "success" | "error" | "warning"; -}) => { - switch (props.status) { - case "error": - return ; - case "warning": - return ; - case "success": - return ; - } -}; - -const ChainValidation: React.FC = () => { - const [rpcUrl, setRpcUrl] = useState(""); - const [validationReport, validate] = useRpcValidation(rpcUrl); - const [validated, setValidated] = useState(false); - const existingChain = validationReport?.existingChain; - - const trackEvent = useTrack(); - - const handleValidate = () => { - if (rpcUrl.length > 0) { - validate(); - setValidated(true); - - trackEvent({ - category: "validation", - action: "validate", - label: "rpc", - url: rpcUrl, - }); - } - }; - - const handleChange = (e: ChangeEvent) => { - setRpcUrl(e.currentTarget.value); - setValidated(false); - }; - - return ( - -
- - RPC URL - - 0 && !validationReport.urlValid} - value={rpcUrl} - onChange={handleChange} - placeholder="https://rpc.yourchain.com/rpc" - type="url" - /> - - - - - {validated && ( - - - - - - - - - - - - - {validationReport.urlValid && ( - <> - - - - - - - - - {validationReport.chainIdSupported && ( - - - - - - )} - - )} - -
RPC validation report
RPC URL valid - -
- RPC supports method - - -
- RPC supports {" "} - method - - -
- Chain ID{" "} - {existingChain?.id ? ( - {existingChain.id} - ) : ( - "" - )} - {!existingChain - ? "is available" - : existingChain?.mainnet - ? "is already on mainnet" - : "is on testnet"} - {existingChain?.infoURL && ( - - visit site - - )} - - -
-
- )} -
-
- ); -}; - -export default ChainValidation; diff --git a/apps/dashboard/src/app/(dashboard)/chain/validate/page.tsx b/apps/dashboard/src/app/(dashboard)/chain/validate/page.tsx deleted file mode 100644 index fffa8499d5f..00000000000 --- a/apps/dashboard/src/app/(dashboard)/chain/validate/page.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { ChakraProviderSetup } from "@/components/ChakraProviderSetup"; -import type { Metadata } from "next"; -import Link from "next/link"; -import ChainValidation from "./ChainValidation"; - -const title = "Validate Chain"; -const description = "Validate a given chain is compatible with thirdweb."; - -export const metadata: Metadata = { - title, - description, - robots: "noindex, nofollow", -}; - -export default function Page() { - return ( - -
-
-
-

- Validate Chain -

-

- Validate a given chain is compatible with{" "} - - thirdweb - - . -

-
- - -
-
-
- ); -} diff --git a/apps/dashboard/src/hooks/chains/useRpcValidation.ts b/apps/dashboard/src/hooks/chains/useRpcValidation.ts deleted file mode 100644 index 8e0099163f6..00000000000 --- a/apps/dashboard/src/hooks/chains/useRpcValidation.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import { useState } from "react"; -import { fetchChain } from "utils/fetchChain"; -import { type ZodError, z } from "zod"; - -const rpcUrlSchema = z.string().url(); - -interface IExistingChain { - id: number; - mainnet: boolean; - name: string; - infoURL?: string | undefined; -} - -export function useRpcValidation(rpcUrl: string) { - const [existingChain, setExistingChain] = useState< - IExistingChain | null | undefined - >(undefined); - - const validUrlQuery = useQuery({ - queryKey: ["validate-rpc-url", { rpcUrl }], - queryFn: async () => { - return rpcUrlSchema.parseAsync(rpcUrl); - }, - enabled: false, - retry: false, - }); - - const supportsChainId = useQuery({ - queryKey: ["validate-rpc-chain-id", { rpcUrl }], - queryFn: async () => { - const response = await fetch(rpcUrl, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - jsonrpc: "2.0", - method: "eth_chainId", - params: [], - id: 1, - }), - }); - - const json = await response.json(); - - if (json.error) { - throw new Error(json.error.message); - } - - try { - const rpcChainId = Number.parseInt(json.result, 16); - const r = await fetchChain(rpcChainId); - if (!r) { - setExistingChain(null); - return true; - } - setExistingChain({ - id: r.chainId, - name: r.name, - mainnet: !r.testnet, - infoURL: "infoURL" in r ? r.infoURL : undefined, - }); - } catch { - setExistingChain(null); - } - - return true; - }, - enabled: false, - retry: false, - }); - - const supportsBlockNumber = useQuery({ - queryKey: ["validate-rpc-block-number", { rpcUrl }], - queryFn: async () => { - const response = await fetch(rpcUrl, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - jsonrpc: "2.0", - method: "eth_blockNumber", - params: [], - id: 1, - }), - }); - - const json = await response.json(); - - if (json.error) { - throw new Error(json.error.message); - } - - return true; - }, - enabled: false, - retry: false, - }); - - const validationReport = { - urlValid: validUrlQuery.isSuccess, - urlLoading: validUrlQuery.isFetching, - urlError: validUrlQuery.error, - chainIdSupported: supportsChainId.isSuccess, - chainIdLoading: supportsChainId.isFetching, - chainIdError: supportsChainId.error, - blockNumberSupported: supportsBlockNumber.isSuccess, - blockNumberLoading: supportsBlockNumber.isFetching, - blockNumberError: supportsBlockNumber.error, - existingChain, - allValid: - validUrlQuery.isSuccess && - supportsChainId.isSuccess && - supportsBlockNumber.isSuccess, - } as const; - - return [ - validationReport, - () => { - validUrlQuery.refetch(); - supportsChainId.refetch(); - supportsBlockNumber.refetch(); - }, - ] as const; -}