Skip to content

Commit

Permalink
Use new hook in tx detail
Browse files Browse the repository at this point in the history
  • Loading branch information
abefernan committed Sep 30, 2024
1 parent 09da031 commit 4c42263
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions components/tx-data.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use client";

import { useTx } from "@/hooks/api";
import { sequenceDiagramFromSpans } from "@/lib/mermaid";
import { Tx, TxSchema } from "@/types/txs";
import { useQuery } from "@tanstack/react-query";
import { z } from "zod";
import { Tx } from "@/types/txs";
import Mermaid from "./mermaid";

type TxDataProps = {
Expand All @@ -12,27 +11,18 @@ type TxDataProps = {
};

export default function TxData({ txId, spanId }: TxDataProps) {
const { isPending, error, data } = useQuery({
queryKey: [`tx-${txId}`],
queryFn: () =>
fetch(`http://localhost:4000/api/v1/txs?traceID=${txId}`)
.then((res) => res.json())
.then((json) => json.txs),
});
const { isPending, isFetching, error, data: spans } = useTx(txId);

if (isPending) return "Loading...";

if (error) return "An error has occurred: " + error.message;

const spans: Readonly<Array<Tx>> = z.array(TxSchema).parse(data);

const mermaidChart = sequenceDiagramFromSpans(spans);

const span = spans.find((span: Tx) => span.spanId === spanId);

return (
<div>
<Mermaid chart={mermaidChart} />
{!isFetching ? <Mermaid chart={mermaidChart} /> : null}
{span ? (
<pre>
{JSON.stringify(
Expand Down

0 comments on commit 4c42263

Please sign in to comment.