|
|
|
@ -1,8 +1,10 @@ |
|
|
|
|
import { useState } from 'react'; |
|
|
|
|
import { useQuery } from '@tanstack/react-query'; |
|
|
|
|
import { useCallback, useState } from 'react'; |
|
|
|
|
|
|
|
|
|
import { Fade } from '../../components/animation/Fade'; |
|
|
|
|
import { SearchBar } from '../../components/search/SearchBar'; |
|
|
|
|
import { |
|
|
|
|
NoSearchError, |
|
|
|
|
SearchEmptyError, |
|
|
|
|
SearchInvalidError, |
|
|
|
|
SearchUnknownError, |
|
|
|
@ -13,6 +15,8 @@ import useDebounce from '../../utils/debounce'; |
|
|
|
|
import { sanitizeString } from '../../utils/string'; |
|
|
|
|
import { isValidSearchQuery } from '../search/utils'; |
|
|
|
|
|
|
|
|
|
import { debugMessageForHash } from './debugMessage'; |
|
|
|
|
|
|
|
|
|
export function TxDebugger() { |
|
|
|
|
const environment = useStore((s) => s.environment); |
|
|
|
|
|
|
|
|
@ -21,11 +25,15 @@ export function TxDebugger() { |
|
|
|
|
const debouncedSearchInput = useDebounce(searchInput, 750); |
|
|
|
|
const hasInput = !!debouncedSearchInput; |
|
|
|
|
const sanitizedInput = sanitizeString(debouncedSearchInput); |
|
|
|
|
const isValidInput = hasInput ? isValidSearchQuery(sanitizedInput, false) : true; |
|
|
|
|
const isValidInput = isValidSearchQuery(sanitizedInput, false); |
|
|
|
|
|
|
|
|
|
const fetching = false; |
|
|
|
|
const hasError = false; |
|
|
|
|
const txResult = {}; |
|
|
|
|
// Debugger query
|
|
|
|
|
const query = useCallback(() => { |
|
|
|
|
if (!isValidInput || !sanitizedInput) return null; |
|
|
|
|
else return debugMessageForHash(sanitizedInput, environment); |
|
|
|
|
}, [isValidInput, sanitizedInput, environment]); |
|
|
|
|
const { isLoading: fetching, error, data } = useQuery(['debugMessage'], query); |
|
|
|
|
const hasError = !!error; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
@ -36,19 +44,19 @@ export function TxDebugger() { |
|
|
|
|
placeholder="Search transaction hash to debug message" |
|
|
|
|
/> |
|
|
|
|
<div className="w-full h-[38.05rem] mt-5 bg-white shadow-md border border-blue-50 rounded overflow-auto relative"> |
|
|
|
|
{/* Content header and filter bar */} |
|
|
|
|
<div className="px-2 py-3 sm:px-4 md:px-5 md:py-3 flex items-center justify-between border-b border-gray-100"> |
|
|
|
|
<h2 className="text-gray-600">{`Transaction Debugger (${envDisplayValue[environment]})`}</h2> |
|
|
|
|
</div> |
|
|
|
|
{/* Message list */} |
|
|
|
|
<Fade show={!hasError && isValidInput && !!txResult}>{JSON.stringify(txResult)}</Fade> |
|
|
|
|
|
|
|
|
|
<SearchInvalidError show={!isValidInput} /> |
|
|
|
|
<SearchUnknownError show={isValidInput && hasError} /> |
|
|
|
|
<Fade show={isValidInput && !hasError && !!data}>{JSON.stringify(data)}</Fade> |
|
|
|
|
<SearchEmptyError |
|
|
|
|
show={isValidInput && !hasError && !fetching && !txResult} |
|
|
|
|
show={isValidInput && !hasError && !fetching && !data} |
|
|
|
|
hasInput={hasInput} |
|
|
|
|
allowAddress={false} |
|
|
|
|
/> |
|
|
|
|
<NoSearchError show={!hasInput && !hasError} /> |
|
|
|
|
<SearchInvalidError show={hasInput && !hasError && !isValidInput} allowAddress={false} /> |
|
|
|
|
<SearchUnknownError show={hasInput && hasError} /> |
|
|
|
|
</div> |
|
|
|
|
</> |
|
|
|
|
); |
|
|
|
|