Skip to content

Commit

Permalink
ui: contract page mobile friendly (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mautjee authored Oct 18, 2024
1 parent a40adf6 commit 28e5d9d
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 306 deletions.

This file was deleted.

4 changes: 2 additions & 2 deletions services/explorer-ui/src/components/info-badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const InfoBadge: FC<InfoBadgeProps> = ({

return (
<div className="flex flex-col bg-white w-5/12 justify-between rounded-lg shadow-md p-4 md:w-96">
<p>{title}</p>
<h2 className="text-primary">{text}</h2>
<p className="text-sm">{title}</p>
<h3 className="text-primary">{text}</h3>
</div>
);
};
28 changes: 28 additions & 0 deletions services/explorer-ui/src/components/table-badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FC, useMemo } from "react";

interface TableBadgeProps {
title: string;
isLoading: boolean;
error: Error | null;
children: React.ReactNode;
}

export const TableBadge: FC<TableBadgeProps> = ({
title,
isLoading,
error,
children,
}) => {
const text = useMemo(() => {
if (isLoading) return "Loading";
if (error) return error.message;
return undefined;
}, [isLoading, error]);

return (
<div className="bg-white w-full rounded-lg shadow-md p-4 md:w-1/2">
<h3>{title}</h3>
{!text ? children : <p className="text-primary-500">{text}</p>}
</div>
);
};
22 changes: 5 additions & 17 deletions services/explorer-ui/src/pages/block-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,18 @@ export const BlockDetails: FC = () => {
<a href={apiEndpointUrl} target="_blank" rel="noreferrer">
(API Endpoint)
</a>
</div>
<div className="flex flex-col gap-4 mt-8">
<div className="bg-white rounded-lg shadow-md p-4">
<KeyValueDisplay data={getBlockDetails(latestBlock)} />
</div>
<div className="flex flex-row gap-4 w-10 mb-4">
<Button
variant={"default"}
className={"shadow-[0px_0px_1px_2px_rgba(0,0,0,1)]"}
>
<p>View TxEffects</p>
</Button>
</div>
<TxEffectsTable txEffects={getTxEffects(latestBlock)} />
</div>
</div>
<div className="flex flex-col gap-4 mt-8">
<div className="bg-white rounded-lg shadow-md p-4">
<KeyValueDisplay data={getBlockDetails(latestBlock)} />
</div>
<div className="flex flex-row gap-4 w-10 mb-4">
<Button variant={"default"}>
<Button
variant={"default"}
className={"shadow-[0px_0px_1px_2px_rgba(0,0,0,1)]"}
>
<p>View TxEffects</p>
</Button>
<Button variant={"default"}>View TxEffects</Button>
</div>
<TxEffectsTable txEffects={getTxEffects(latestBlock)} />
</div>
Expand Down
9 changes: 6 additions & 3 deletions services/explorer-ui/src/pages/block/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ export const Blocks: FC = () => {
if (error) return <p className="text-red-500">{error.message}</p>;
if (!latestBlocks) return <p>No data</p>;
const averageBlockTimeFormatted = formatDuration(
Number(avarageBlockTime) / 1000
Number(avarageBlockTime) / 1000,
);

return (
<div className="mx-auto px-[70px] max-w-[1440px]">
<h1 className="mt-16">Latest Blocks</h1>
<div className="mx-auto px-5 max-w-[1440px] md:px-[70px]">
<div className="flex flex-wrap justify-center gap-3 m-5 ">
<h2 className="mt-2 text-primary md:hidden">Blocks</h2>
<h1 className="hidden md:block md:mt-16">Blocks</h1>
</div>
<div className="flex flex-row justify-center gap-4 m-8">
<InfoBadge
title="Average fees (FPA)"
Expand Down
77 changes: 77 additions & 0 deletions services/explorer-ui/src/pages/contract-class-details/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { useParams } from "@tanstack/react-router";
import { type FC } from "react";
import { KeyValueDisplay } from "~/components/info-display/key-value-display";
import { useContractClasses, useContractInstance } from "~/hooks";
import { API_URL, aztecExplorer } from "~/service/constants";
import { getContractData } from "./util";
import { ContractInstancesTable } from "~/components/contracts/instances/table";
import { mapContractClasses, mapContractInstances } from "../contract/util";
import { TableBadge } from "~/components/table-badge";
import { ContractClassesTable } from "~/components/contracts/classes/table";

export const ContractClassDetails: FC = () => {
const { id } = useParams({
from: "/contracts/classes/$id",
});
const {
data: classesData,
isLoading: isLoadingClasses,
error: errorClasses,
} = useContractClasses(id);
const {
data: instancesData,
isLoading: isLoadingInstances,
error: errorInstances,
} = useContractInstance(id);

if (!id) return <div>No classId</div>;

const apiEndpointUrl = `${API_URL}/${aztecExplorer.getL2ContractClasses(id)}`;

return (
<div className="mx-auto px-[70px] max-w-[1440px]">
<div className="flex flex-col gap-4 mt-8">
<div>
<div>
<h2>Contract class details</h2>
<a href={apiEndpointUrl} target="_blank" rel="noreferrer">
(API Endpoint)
</a>
</div>
<div className="flex flex-col gap-4 mt-8">
<div className="bg-white rounded-lg shadow-md p-4">
<KeyValueDisplay
data={classesData ? getContractData(classesData[0]) : []}
/>
</div>
</div>
</div>
<div className="flex flex-col gap-4 md:flex-row ">
<TableBadge
title="Total Contract Instances"
isLoading={isLoadingClasses}
error={errorClasses}
>
{classesData && (
<ContractClassesTable
contracts={mapContractClasses(classesData)}
/>
)}
</TableBadge>

<TableBadge
title="Total Contract Instances"
isLoading={isLoadingInstances}
error={errorInstances}
>
{instancesData && (
<ContractInstancesTable
contracts={mapContractInstances([instancesData])}
/>
)}
</TableBadge>
</div>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ import { API_URL, aztecExplorer } from "~/service/constants";
import { getContractData } from "./util";

export const ContractInstanceDetails: FC = () => {
let address = "";
try {
const params = useParams({
from: "/contracts/instances/$address",
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
address = params.address;
} catch (e) {
// TODO
}
const { address } = useParams({
from: "/contracts/instances/$address",
});
const {
data: contractInstanceDetails,
isLoading,
Expand All @@ -28,7 +21,7 @@ export const ContractInstanceDetails: FC = () => {
if (!contractInstanceDetails) return <div>No data</div>;

const apiEndpointUrl = `${API_URL}/${aztecExplorer.getL2ContractInstance(
address
address,
)}`;

return (
Expand Down
78 changes: 78 additions & 0 deletions services/explorer-ui/src/pages/contract/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { FC } from "react";
import { InfoBadge } from "~/components/info-badge";
import { useLatestContractClasses, useLatestContractInstances } from "~/hooks";
import { useTotalContracts, useTotalContractsLast24h } from "~/hooks/stats";
import { mapContractClasses, mapContractInstances } from "./util";
import { ContractInstancesTable } from "~/components/contracts/instances/table";
import { ContractClassesTable } from "~/components/contracts/classes/table";
import { TableBadge } from "~/components/table-badge";

export const Contracts: FC = () => {
const {
data: classesData,
isLoading: isLoadingClasses,
error: errorClasses,
} = useLatestContractClasses();
const {
data: instancesData,
isLoading: isLoadingInstances,
error: errorInstances,
} = useLatestContractInstances();
const {
data: totalAmountOfContracts,
isLoading: loadingAmountContracts,
error: errorAmountContracts,
} = useTotalContracts();
const {
data: totalAmountOfContracts24h,
isLoading: loadingAmountContracts24h,
error: errorAmountContracts24h,
} = useTotalContractsLast24h();

return (
<div className="mx-auto px-7 max-w-[1440px] md:px-[70px]">
<div className="flex flex-wrap justify-center gap-3 m-5 ">
<h2 className="mt-2 text-primary md:hidden">All contracts</h2>
<h1 className="hidden md:block md:mt-16">All contracts</h1>
</div>
<div className="flex flex-row justify-center gap-4 m-8">
<InfoBadge
title="Total Contract Classes"
isLoading={loadingAmountContracts}
error={errorAmountContracts}
data={totalAmountOfContracts}
/>
<InfoBadge
title="Total Contract Classes last 24h"
isLoading={loadingAmountContracts24h}
error={errorAmountContracts24h}
data={totalAmountOfContracts24h}
/>
</div>

<div className="flex flex-col gap-4 md:flex-row ">
<TableBadge
title="Total Contract Instances"
isLoading={isLoadingClasses}
error={errorClasses}
>
{classesData && (
<ContractClassesTable contracts={mapContractClasses(classesData)} />
)}
</TableBadge>

<TableBadge
title="Total Contract Instances"
isLoading={isLoadingInstances}
error={errorInstances}
>
{instancesData && (
<ContractInstancesTable
contracts={mapContractInstances(instancesData)}
/>
)}
</TableBadge>
</div>
</div>
);
};
36 changes: 36 additions & 0 deletions services/explorer-ui/src/pages/contract/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
ChicmozL2ContractClassRegisteredEvent,
ChicmozL2ContractInstanceDeluxe,
} from "@chicmoz-pkg/types";
import { contractClassSchema } from "~/components/contracts/classes/schema";
import { contractInstanceSchema } from "~/components/contracts/instances/schema";

export const mapContractClasses = (
classesData: ChicmozL2ContractClassRegisteredEvent[],
) => {
return classesData.map((contractClass) =>
contractClassSchema.parse({
blockHash: contractClass.blockHash,
contractClassId: contractClass.contractClassId,
version: contractClass.version,
artifactHash: contractClass.artifactHash,
privateFunctionsRoot: contractClass.privateFunctionsRoot,
}),
);
};

export const mapContractInstances = (
instancesData: ChicmozL2ContractInstanceDeluxe[],
) => {
return instancesData.map((contractInstance) =>
contractInstanceSchema.parse({
address: contractInstance.address,
blockHash: contractInstance.blockHash,
blockHeight: contractInstance.blockHeight,
version: contractInstance.version,
contractClassId: contractInstance.contractClassId,
publicKeysHash: contractInstance.publicKeysHash,
deployer: contractInstance.deployer,
}),
);
};
Loading

0 comments on commit 28e5d9d

Please sign in to comment.