Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { type NextRequest, NextResponse } from "next/server";
import { type BundleEvent, getBundleHistory } from "@/lib/s3";

export interface BundleHistoryResponse {
uuid: string;
hash: string;
history: BundleEvent[];
}

export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ uuid: string }> },
{ params }: { params: Promise<{ hash: string }> },
) {
try {
const { uuid } = await params;
const { hash } = await params;

const bundle = await getBundleHistory(uuid);
const bundle = await getBundleHistory(hash);
if (!bundle) {
return NextResponse.json({ error: "Bundle not found" }, { status: 404 });
}
Expand All @@ -24,7 +24,7 @@ export async function GET(
);

const response: BundleHistoryResponse = {
uuid,
hash,
history: bundle.history,
};

Expand Down
20 changes: 10 additions & 10 deletions src/app/bundles/[uuid]/page.tsx → src/app/bundles/[hash]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import Link from "next/link";
import { useEffect, useState } from "react";
import type { BundleHistoryResponse } from "@/app/api/bundle/[uuid]/route";
import type { BundleHistoryResponse } from "@/app/api/bundle/[hash]/route";
import type { BundleTransaction, MeterBundleResponse } from "@/lib/s3";

const WEI_PER_GWEI = 10n ** 9n;
const WEI_PER_ETH = 10n ** 18n;
const BLOCK_EXPLORER_URL = process.env.NEXT_PUBLIC_BLOCK_EXPLORER_URL;

interface PageProps {
params: Promise<{ uuid: string }>;
params: Promise<{ hash: string }>;
}

function formatBigInt(value: bigint, decimals: number, scale: bigint): string {
Expand Down Expand Up @@ -474,21 +474,21 @@ function SectionTitle({ children }: { children: React.ReactNode }) {
}

export default function BundlePage({ params }: PageProps) {
const [uuid, setUuid] = useState<string>("");
const [hash, setHash] = useState<string>("");
const [data, setData] = useState<BundleHistoryResponse | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
params.then((p) => setUuid(p.uuid));
params.then((p) => setHash(p.hash));
}, [params]);

useEffect(() => {
if (!uuid) return;
if (!hash) return;

const fetchData = async () => {
try {
const response = await fetch(`/api/bundle/${uuid}`);
const response = await fetch(`/api/bundle/${hash}`);
if (!response.ok) {
setError(
response.status === 404
Expand All @@ -511,9 +511,9 @@ export default function BundlePage({ params }: PageProps) {
fetchData();
const interval = setInterval(fetchData, 5000);
return () => clearInterval(interval);
}, [uuid]);
}, [hash]);

if (!uuid || (loading && !data)) {
if (!hash || (loading && !data)) {
return (
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
<div className="flex items-center gap-3">
Expand Down Expand Up @@ -564,9 +564,9 @@ export default function BundlePage({ params }: PageProps) {
</div>
<div className="flex items-center gap-2 text-sm">
<code className="font-mono text-gray-600 bg-gray-100 px-2 py-1 rounded text-xs">
{uuid}
{hash}
</code>
<CopyButton text={uuid} />
<CopyButton text={hash} />
</div>
</div>
</header>
Expand Down
36 changes: 24 additions & 12 deletions src/lib/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,36 @@ export interface BundleHistory {
}

export async function getBundleHistory(
bundleId: string,
bundleKey: string,
): Promise<BundleHistory | null> {
const key = `bundles/${bundleId}`;
const content = await getObjectContent(key);
const prefix = `bundles/${bundleKey}/`;
const listCommand = new ListObjectsV2Command({
Bucket: BUCKET_NAME,
Prefix: prefix,
});

if (!content) {
const listResponse = await s3Client.send(listCommand);
const keys = listResponse.Contents?.map((obj) => obj.Key).filter(
Boolean,
) as string[];

if (!keys || keys.length === 0) {
return null;
}

try {
return JSON.parse(content) as BundleHistory;
} catch (error) {
console.error(
`Failed to parse bundle history for bundle ${bundleId}:`,
error,
);
return null;
const history: BundleEvent[] = [];
for (const key of keys) {
const content = await getObjectContent(key);
if (content) {
try {
history.push(JSON.parse(content) as BundleEvent);
} catch (error) {
console.error(`Failed to parse event at ${key}:`, error);
}
}
}

return { history };
}

export interface BlockTransaction {
Expand Down
Loading