From f976161642083d315f956003b893536b9ecf2d96 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Sun, 25 Sep 2022 17:08:50 -0400 Subject: [PATCH] Implement components for debug message result --- src/components/nav/Header.tsx | 8 +-- src/features/debugger/TxDebugger.tsx | 83 ++++++++++++++++++++++++++- src/features/debugger/debugMessage.ts | 9 ++- src/features/search/MessageSearch.tsx | 2 +- 4 files changed, 91 insertions(+), 11 deletions(-) diff --git a/src/components/nav/Header.tsx b/src/components/nav/Header.tsx index 5ffb283..da29c06 100644 --- a/src/components/nav/Header.tsx +++ b/src/components/nav/Header.tsx @@ -32,7 +32,7 @@ export function Header({ pathName }: { pathName: string }) { -
+
+
{/* Dropdown menu, used on mobile */} -
+
+ ); } diff --git a/src/features/debugger/TxDebugger.tsx b/src/features/debugger/TxDebugger.tsx index 444f38d..42fe68d 100644 --- a/src/features/debugger/TxDebugger.tsx +++ b/src/features/debugger/TxDebugger.tsx @@ -1,7 +1,9 @@ import { useQuery } from '@tanstack/react-query'; +import Image from 'next/future/image'; import { useState } from 'react'; import { Fade } from '../../components/animation/Fade'; +import { CopyButton } from '../../components/buttons/CopyButton'; import { SearchBar } from '../../components/search/SearchBar'; import { NoSearchError, @@ -10,12 +12,13 @@ import { SearchUnknownError, } from '../../components/search/SearchError'; import { envDisplayValue } from '../../consts/environments'; +import ShrugIcon from '../../images/icons/shrug.svg'; import { useStore } from '../../store'; import useDebounce from '../../utils/debounce'; import { sanitizeString } from '../../utils/string'; import { isValidSearchQuery } from '../search/utils'; -import { debugMessageForHash } from './debugMessage'; +import { MessageDebugResult, TxDebugStatus, debugMessageForHash } from './debugMessage'; export function TxDebugger() { const environment = useStore((s) => s.environment); @@ -49,11 +52,15 @@ export function TxDebugger() { placeholder="Search transaction hash to debug message" />
-
+

{`Transaction Debugger (${envDisplayValue[environment]})`}

- {JSON.stringify(data)} + +
+ +
+
); } + +function DebugResult({ result }: { result: MessageDebugResult | null | undefined }) { + if (!result) return null; + + if (result.status === TxDebugStatus.NotFound) { + return ( +
+ +

No transaction found

+

{result.details}

+
+ ); + } + + if (result.status === TxDebugStatus.NoMessages) { + return ( +
+ +

No message found

+

{result.details}

+ +
+ ); + } + + if (result.status === TxDebugStatus.MessagesFound) { + return ( + <> + {result.messageDetails.map((m, i) => ( +
+

{`Message ${i + 1} / ${ + result.messageDetails.length + }`}

+

{m.summary}

+
+ {Array.from(m.properties.entries()).map(([key, val]) => ( +
+ +
+ {val} +
+ {val.length > 20 && ( + + )} +
+ ))} +
+
+ ))} + + + ); + } + + return null; +} + +function TxExplorerLink({ href }: { href: string | undefined }) { + if (!href) return null; + return ( + + View transaction in explorer + + ); +} diff --git a/src/features/debugger/debugMessage.ts b/src/features/debugger/debugMessage.ts index 14b752e..1a83c2d 100644 --- a/src/features/debugger/debugMessage.ts +++ b/src/features/debugger/debugMessage.ts @@ -55,7 +55,10 @@ export interface DebugMessagesFoundResult { messageDetails: MessageDetails[]; } -type MessageDebugResult = DebugNotFoundResult | DebugNoMessagesResult | DebugMessagesFoundResult; +export type MessageDebugResult = + | DebugNotFoundResult + | DebugNoMessagesResult + | DebugMessagesFoundResult; export async function debugMessageForHash( txHash: string, @@ -89,9 +92,9 @@ export async function debugMessageForHash( logger.debug(`Found ${dispatchedMessages.length} messages`); const messageDetails: MessageDetails[] = []; for (let i = 0; i < dispatchedMessages.length; i++) { - logger.debug(`Checking message ${i} of ${dispatchedMessages.length}`); + logger.debug(`Checking message ${i + 1} of ${dispatchedMessages.length}`); messageDetails.push(await checkMessage(core, multiProvider, dispatchedMessages[i])); - logger.debug(`Done checking message ${i}`); + logger.debug(`Done checking message ${i + 1}`); } return { status: TxDebugStatus.MessagesFound, diff --git a/src/features/search/MessageSearch.tsx b/src/features/search/MessageSearch.tsx index 54a81a1..e3d7a5e 100644 --- a/src/features/search/MessageSearch.tsx +++ b/src/features/search/MessageSearch.tsx @@ -91,7 +91,7 @@ export function MessageSearch() { />
{/* Content header and filter bar */} -
+

{!hasInput ? 'Latest Messages' : 'Search Results'}