-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtable.tsx
More file actions
51 lines (46 loc) · 1.64 KB
/
table.tsx
File metadata and controls
51 lines (46 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use client'
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
import React from 'react'
import type { DecodedTransaction } from '@3loop/transaction-decoder'
import { findAndRunInterpreter, Interpretation } from '@/lib/interpreter'
export default function TxTable({ txs }: { txs: DecodedTransaction[] }) {
const [result, setResult] = React.useState<Interpretation[]>([])
React.useEffect(() => {
async function run() {
const withIntepretations = await Promise.all(
txs.map((tx) => {
return findAndRunInterpreter(tx)
}),
)
setResult(withIntepretations)
}
run()
}, [txs])
return (
<Table>
<TableCaption>A list of recent transactions.</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="">Age</TableHead>
<TableHead>Link</TableHead>
<TableHead>Interpretation</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{result.map(({ tx, interpretation }) => (
<TableRow key={tx?.txHash}>
<TableCell>{new Date(Number(tx?.timestamp + '000')).toUTCString()}</TableCell>
<TableCell>
<a href={`https://etherscan.io/tx/${tx?.txHash}`} target="_blank" rel="noreferrer">
{tx?.txHash.slice(0, 6) + '...' + tx?.txHash.slice(-4)}
</a>
</TableCell>
<TableCell>
<pre>{typeof interpretation === 'string' ? interpretation : JSON.stringify(interpretation, null, 2)}</pre>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
}