-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement OptimismCard component for displaying decoded transac…
…tion fields and removes `autocompleteBlockHash` (#658) * feat: implement OptimismCard component for displaying decoded transaction fields and removes `autocompleteBlockHash` * chore: moves OptimismCard to its own file * refactor: remove async/await from parsing functions * test: add unit tests for checkBlockExists function * fix: make txTimestamp prop optional in OptimismCard component * refactor: simplify JSX structure in OptimismCard component * refactor: replace CopyToClipboard with Copyable component in OptimismCard * fix(web): Capitalize decoded field names * chore: add changeset --------- Co-authored-by: Pablo Castellano <pablo@anche.no> Co-authored-by: PJColombo <paulo.colombo@pm.me>
- Loading branch information
1 parent
766ab15
commit 95f8043
Showing
11 changed files
with
164 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@blobscan/web": patch | ||
--- | ||
|
||
Improved Optimism tx decoded fields card |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@blobscan/api": patch | ||
--- | ||
|
||
Removed auto-completion logic for hashes in Optimism decoded fields retrieval |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import type { FC } from "react"; | ||
|
||
import type { OptimismDecodedData } from "@blobscan/api/src/blob-parse/optimism"; | ||
import type dayjs from "@blobscan/dayjs"; | ||
|
||
import { InfoGrid } from "~/components/InfoGrid"; | ||
import { Link } from "~/components/Link"; | ||
import { api } from "~/api-client"; | ||
import Loading from "~/icons/loading.svg"; | ||
import { formatTimestamp } from "~/utils"; | ||
import { Card } from "./Cards/Card"; | ||
import { Copyable } from "./Copyable"; | ||
|
||
type OptimismCardProps = { | ||
data: OptimismDecodedData; | ||
txTimestamp?: dayjs.Dayjs; | ||
}; | ||
|
||
export const OptimismCard: FC<OptimismCardProps> = ({ data, txTimestamp }) => { | ||
const { data: blockExists, isLoading } = api.block.checkBlockExists.useQuery({ | ||
blockNumber: data.lastL1OriginNumber, | ||
}); | ||
|
||
const blockLink = blockExists | ||
? `https://blobscan.com/block/${data.lastL1OriginNumber}` | ||
: `https://etherscan.io/block/${data.lastL1OriginNumber}`; | ||
|
||
const hash = `0x${data.l1OriginBlockHash}...`; | ||
|
||
const timestamp = txTimestamp | ||
? formatTimestamp(txTimestamp.subtract(data.timestampSinceL2Genesis, "ms")) | ||
: undefined; | ||
|
||
if (isLoading) { | ||
return ( | ||
<Card header="Loading Decoded Fields..."> | ||
<div className="flex h-32 items-center justify-center"> | ||
<Loading className="h-8 w-8 animate-spin" /> | ||
</div> | ||
</Card> | ||
); | ||
} | ||
|
||
return ( | ||
<Card header="Decoded Fields"> | ||
<InfoGrid | ||
fields={[ | ||
{ | ||
name: "Timestamp Since L2 Genesis", | ||
value: <div className="whitespace-break-spaces">{timestamp}</div>, | ||
}, | ||
{ | ||
name: "Last L1 Origin Number", | ||
value: ( | ||
<Copyable | ||
value={data.lastL1OriginNumber.toString()} | ||
tooltipText="Copy last L1 origin number" | ||
> | ||
<Link href={blockLink}>{data.lastL1OriginNumber}</Link> | ||
</Copyable> | ||
), | ||
}, | ||
{ | ||
name: "Parent L2 Partial Block Hash", | ||
value: "0x" + data.parentL2BlockHash + "...", | ||
}, | ||
{ | ||
name: "L1 Origin Partial Block Hash", | ||
value: ( | ||
<Copyable value={hash} tooltipText="Copy L1 origin block hash"> | ||
<Link href={blockLink}>{hash}</Link> | ||
</Copyable> | ||
), | ||
}, | ||
{ | ||
name: "Number Of L2 Blocks", | ||
value: data.numberOfL2Blocks, | ||
}, | ||
{ | ||
name: "Changed By L1 Origin", | ||
value: data.changedByL1Origin, | ||
}, | ||
{ | ||
name: "Total Transactions", | ||
value: data.totalTxs, | ||
}, | ||
{ | ||
name: "Contract Creation Transactions", | ||
value: data.contractCreationTxsNumber, | ||
}, | ||
]} | ||
/> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { z } from "@blobscan/zod"; | ||
|
||
import { publicProcedure } from "../../procedures"; | ||
|
||
export const checkBlockExists = publicProcedure | ||
.input( | ||
z.object({ | ||
blockNumber: z.number(), | ||
}) | ||
) | ||
.query(async ({ ctx: { prisma }, input }) => { | ||
const block = await prisma.block.findFirst({ | ||
where: { | ||
number: input.blockNumber, | ||
}, | ||
select: { | ||
number: true, | ||
}, | ||
}); | ||
|
||
return Boolean(block); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.