Skip to content

Commit 1d1537c

Browse files
authored
feat: Block status indicator badge (#347)
* new badge component for block details * remove commends * remove unused imports
1 parent 915db70 commit 1d1537c

File tree

5 files changed

+105
-17
lines changed

5 files changed

+105
-17
lines changed

services/event-cannon/src/cannon/scenarios/utils/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { deriveSigningKey } from "@aztec/circuits.js";
2525
import { FunctionType } from "@aztec/foundation/abi";
2626
import { ContractClassRegisteredEvent } from "@aztec/protocol-contracts/class-registerer";
2727
import {
28-
VerifyInstanceDeploymentPayload,
2928
generateVerifyArtifactPayload,
3029
generateVerifyArtifactUrl,
3130
generateVerifyInstancePayload,
@@ -292,7 +291,7 @@ export const verifyContractInstanceDeployment = async ({
292291
const postData = JSON.stringify({
293292
verifiedDeploymentArguments: generateVerifyInstancePayload(
294293
verifyArgs,
295-
) as VerifyInstanceDeploymentPayload,
294+
),
296295
deployerMetadata,
297296
});
298297
await callExplorerApi({
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { ChicmozL2BlockFinalizationStatus } from "@chicmoz-pkg/types";
2+
3+
4+
interface BlockStatusBadgeProps {
5+
status: ChicmozL2BlockFinalizationStatus;
6+
className?: string;
7+
}
8+
9+
export const BlockStatusBadge: React.FC<BlockStatusBadgeProps> = ({ status, className = "" }) => {
10+
let badgeText = "Unknown";
11+
let badgeStyle = {};
12+
13+
switch (status) {
14+
case ChicmozL2BlockFinalizationStatus.L2_NODE_SEEN_PROPOSED:
15+
badgeText = "L2 Proposed";
16+
badgeStyle = {
17+
backgroundColor: "#FEE2E2",
18+
color: "#991B1B",
19+
borderColor: "#EF4444"
20+
};
21+
break;
22+
case ChicmozL2BlockFinalizationStatus.L2_NODE_SEEN_PROVEN:
23+
badgeText = "L2 Proven";
24+
badgeStyle = {
25+
backgroundColor: "#FFEDD5",
26+
color: "#9A3412",
27+
borderColor: "#F97316"
28+
};
29+
break;
30+
case ChicmozL2BlockFinalizationStatus.L1_SEEN_PROPOSED:
31+
badgeText = "L1 Proposed";
32+
badgeStyle = {
33+
backgroundColor: "#FEF3C7",
34+
color: "#92400E",
35+
borderColor: "#F59E0B"
36+
};
37+
break;
38+
case ChicmozL2BlockFinalizationStatus.L1_SEEN_PROVEN:
39+
badgeText = "L1 Proven";
40+
badgeStyle = {
41+
backgroundColor: "#FEF9C3",
42+
color: "#854D0E",
43+
borderColor: "#EAB308"
44+
};
45+
break;
46+
case ChicmozL2BlockFinalizationStatus.L1_MINED_PROPOSED:
47+
badgeText = "L1 Mined (Proposed)";
48+
badgeStyle = {
49+
backgroundColor: "#CCFBF1",
50+
color: "#115E59",
51+
borderColor: "#14B8A6"
52+
};
53+
break;
54+
case ChicmozL2BlockFinalizationStatus.L1_MINED_PROVEN:
55+
badgeText = "L1 Mined (Proven)";
56+
badgeStyle = {
57+
backgroundColor: "#DCFCE7",
58+
color: "#166534",
59+
borderColor: "#22C55E"
60+
};
61+
break;
62+
default:
63+
badgeStyle = {
64+
backgroundColor: "#F3F4F6",
65+
color: "#1F2937",
66+
borderColor: "#6B7280"
67+
};
68+
}
69+
70+
return (
71+
<span
72+
className={`inline-block px-2.5 py-0.5 rounded-md text-xs font-medium border ${className}`}
73+
style={badgeStyle}
74+
>
75+
{badgeText}
76+
</span>
77+
);
78+
};
79+

services/explorer-ui/src/components/info-display/key-value-row.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Link } from "@tanstack/react-router";
22
import { type FC } from "react";
33
import { truncateHashString } from "~/lib/create-hash-string";
44
import { CopyableText } from "../copy-text";
5+
import { BlockStatusBadge } from "../block-status-badge";
56

67
interface KeyValueRowProps {
78
label: string;
@@ -17,6 +18,7 @@ enum DisplayType {
1718
LINK = "link",
1819
HEX = "hex",
1920
EXTERNAL_LINK = "external-link",
21+
BADGE = "badge",
2022
}
2123

2224
export const KeyValueRow: FC<KeyValueRowProps> = ({
@@ -27,18 +29,18 @@ export const KeyValueRow: FC<KeyValueRowProps> = ({
2729
extLink,
2830
}) => {
2931
let displayType = DisplayType.TEXT;
30-
if (link) displayType = DisplayType.LINK;
31-
else if (label === "data") displayType = DisplayType.TEXTAREA;
32-
else if (value.startsWith("0x")) displayType = DisplayType.HEX;
33-
else if (extLink) displayType = DisplayType.EXTERNAL_LINK;
32+
if (link) { displayType = DisplayType.LINK; }
33+
else if (label === "data") { displayType = DisplayType.TEXTAREA; }
34+
else if (value.startsWith("0x")) { displayType = DisplayType.HEX; }
35+
else if (extLink) { displayType = DisplayType.EXTERNAL_LINK; }
36+
else if (label.includes("status")) { displayType = DisplayType.BADGE; }
3437

3538
const commonTextClasses = "text-sm flex-grow text-end justify-end";
3639
return (
3740
<div
3841
key={label}
39-
className={`flex items-center gap-2 py-3 ${
40-
!isLast ? "border-b border-gray-200" : ""
41-
}`}
42+
className={`flex items-center gap-2 py-3 ${!isLast ? "border-b border-gray-200" : ""
43+
}`}
4244
>
4345
<span className="text-gray-600 w-1/3">{label}</span>
4446
{displayType === DisplayType.TEXT && (
@@ -80,6 +82,11 @@ export const KeyValueRow: FC<KeyValueRowProps> = ({
8082
{displayType === DisplayType.TEXTAREA && (
8183
<CopyableText text={value} toCopy={value} textArea />
8284
)}
85+
{displayType === DisplayType.BADGE && (
86+
<div className={commonTextClasses}>
87+
<BlockStatusBadge status={Number(value)} />
88+
</div>
89+
)}
8390
</div>
8491
);
8592
};

services/explorer-ui/src/pages/block-details/util.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export const getBlockDetails = (
6666
label: "feePerL2Gas",
6767
value: "" + latestBlock.header.globalVariables.gasFees.feePerL2Gas,
6868
},
69+
{
70+
label: " Block status",
71+
value: "" + latestBlock.finalizationStatus,
72+
},
6973
{
7074
label: "Proposed on L1",
7175
value: proposedOnL1Date
@@ -90,7 +94,7 @@ export const getTxEffects = (
9094
txEffects?: ChicmozL2Block["body"]["txEffects"],
9195
latestBlock?: ChicmozL2BlockLight
9296
) => {
93-
if (!txEffects) return undefined;
94-
if (!latestBlock) return undefined;
97+
if (!txEffects) { return undefined; }
98+
if (!latestBlock) { return undefined; }
9599
return txEffects.map((tx) => getTxEffectTableObj(tx, latestBlock));
96100
};

services/explorer-ui/src/pages/contract-class-details/util.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,28 @@ export const getArtifactData = (
7878
artifact = JSON.parse(selectedVersion.artifactJson) as SimpleArtifactData;
7979

8080
artifact.functions.forEach((func) => {
81-
if (!func.abi?.parameters) return;
81+
if (!func.abi?.parameters) { return; }
8282

8383
// Use String() to ensure we have primitive string keys
8484
const funcNameStr = String(func.name);
8585

8686
func.abi.parameters.forEach((param) => {
87-
if (param.name === "inputs") return;
87+
if (param.name === "inputs") { return; }
8888
const paramNameStr = String(param.name);
8989
const paramType = param.type?.kind || "unknown";
9090

9191
if (func.is_unconstrained) {
92-
if (!uncFunc.has(funcNameStr)) uncFunc.set(funcNameStr, new Map());
92+
if (!uncFunc.has(funcNameStr)) { uncFunc.set(funcNameStr, new Map()); }
9393
uncFunc.get(funcNameStr)?.set(paramNameStr, paramType);
9494
}
9595

9696
if (func.custom_attributes?.includes("public")) {
97-
if (!pubFunc.has(funcNameStr)) pubFunc.set(funcNameStr, new Map());
97+
if (!pubFunc.has(funcNameStr)) { pubFunc.set(funcNameStr, new Map()); }
9898
pubFunc.get(funcNameStr)?.set(paramNameStr, paramType);
9999
}
100100

101101
if (func.custom_attributes?.includes("private")) {
102-
if (!privFunc.has(funcNameStr))
103-
privFunc.set(funcNameStr, new Map());
102+
if (!privFunc.has(funcNameStr)) { privFunc.set(funcNameStr, new Map()); }
104103
privFunc.get(funcNameStr)?.set(paramNameStr, paramType);
105104
}
106105
});

0 commit comments

Comments
 (0)