"use client"; import hljs from "highlight.js/lib/core"; import bash from "highlight.js/lib/languages/bash"; import { useState, useMemo, useCallback, useEffect, useRef } from "react"; import { Input } from "../components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../components/ui/select"; import { Switch } from "../components/ui/switch"; import { requestCallback } from "../lib/revelation"; import { EntropyDeployments, isValidDeployment, } from "../store/entropy-deployments"; import "highlight.js/styles/github-dark.css"; // You can choose different themes // Register the bash language hljs.registerLanguage("bash", bash); class BaseError extends Error { constructor(message: string) { super(message); this.name = "BaseError"; } } class InvalidTxHashError extends BaseError { constructor(message: string) { super(message); this.name = "InvalidTxHashError"; } } enum TxStateType { NotLoaded, Loading, Success, Error, } const TxState = { NotLoaded: () => ({ status: TxStateType.NotLoaded as const }), Loading: () => ({ status: TxStateType.Loading as const }), Success: (data: string) => ({ status: TxStateType.Success as const, data }), ErrorState: (error: unknown) => ({ status: TxStateType.Error as const, error, }), }; type TxStateContext = | ReturnType | ReturnType | ReturnType | ReturnType; export default function PythEntropyDebugApp() { const [state, setState] = useState(TxState.NotLoaded()); const [isMainnet, setIsMainnet] = useState(false); const [txHash, setTxHash] = useState(""); const [error, setError] = useState(undefined); const [selectedChain, setSelectedChain] = useState< "" | keyof typeof EntropyDeployments >(""); const validateTxHash = (hash: string) => { if (!isValidTxHash(hash) && hash !== "") { setError( new InvalidTxHashError( "Transaction hash must be 64 hexadecimal characters", ), ); } else { setError(undefined); } setTxHash(hash); }; const availableChains = useMemo(() => { return Object.entries(EntropyDeployments) .filter( ([, deployment]) => deployment.network === (isMainnet ? "mainnet" : "testnet"), ) .toSorted(([a], [b]) => a.localeCompare(b)) .map(([key]) => key); }, [isMainnet]); const oncClickFetchInfo = useCallback(() => { if (selectedChain !== "") { setState(TxState.Loading()); requestCallback(txHash, selectedChain) .then((data) => { setState(TxState.Success(data)); }) .catch((error: unknown) => { setState(TxState.ErrorState(error)); }); } }, [txHash, selectedChain]); const updateIsMainnet = useCallback( (newValue: boolean) => { setSelectedChain(""); setIsMainnet(newValue); }, [setSelectedChain, setIsMainnet], ); const updateSelectedChain = useCallback( (chain: string) => { if (isValidDeployment(chain)) { setSelectedChain(chain); } }, [setSelectedChain], ); return (

Pyth Entropy Debug App

{ validateTxHash(e.target.value); }} /> {error &&

{error.message}

}
); } const Info = ({ state }: { state: TxStateContext }) => { const preRef = useRef(null); useEffect(() => { if (preRef.current && state.status === TxStateType.Success) { hljs.highlightElement(preRef.current); } }, [state]); switch (state.status) { case TxStateType.NotLoaded: { return
Not loaded
; } case TxStateType.Loading: { return
Loading...
; } case TxStateType.Success: { return (

Please run the following command in your terminal:

              {state.data}
            
); } case TxStateType.Error: { return (
{String(state.error)}
); } } }; function isValidTxHash(hash: string) { const cleanHash = hash.toLowerCase().replace("0x", ""); return /^[\da-f]{64}$/.test(cleanHash); }