Skip to content

Commit eed0b13

Browse files
committed
ui getting there
1 parent 4047d46 commit eed0b13

File tree

8 files changed

+76
-65
lines changed

8 files changed

+76
-65
lines changed

services/explorer-ui/.env.development

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
VITE_L2_NETWORK_ID=SANDBOX
2-
VITE_API_URL=http://api.sandbox.chicmoz.localhost:80/v1
1+
VITE_L2_NETWORK_ID=SP_TESTNET
2+
VITE_API_URL=http://api.sp.chicmoz.localhost:80/v1
33
VITE_CHICMOZ_ALL_UI_URLS=Sandbox|http://sandbox.chicmoz.localhost,S&P-testnet|http://sp.chicmoz.localhost
44
VITE_API_KEY=dev-api-key
5-
VITE_WS_URL=ws://ws.sandbox.chicmoz.localhost:80
5+
VITE_WS_URL=ws://ws.sp.chicmoz.localhost:80
66
VITE_DISCORD_URL=https://discord.gg/obscura-build
77
VITE_X_URL=https://x.com/Obscura_Build
88
VITE_GITHUB_URL=https://github.com/aztec-scan/chicmoz

services/explorer-ui/src/api/tx-effect.ts

+4
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ export const TxEffectsAPI = {
4646
);
4747
return validateResponse(chicmozL2BlockSchema.shape.height, response.data);
4848
},
49+
getLatestTxEffects: async (): Promise<ChicmozL2TxEffectDeluxe[]> => {
50+
const response = await client.get(aztecExplorer.getL2TxEffects);
51+
return validateResponse(z.array(chicmozL2TxEffectDeluxeSchema), response.data);
52+
}
4953
};

services/explorer-ui/src/hooks/api/tx-effect.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { TxEffectsAPI } from "~/api";
88
import { queryKeyGenerator } from "./utils";
99

1010
export const useGetTxEffectByHash = (
11-
hash: string
11+
hash: string,
1212
): UseQueryResult<ChicmozL2TxEffectDeluxe, Error> => {
1313
return useQuery<ChicmozL2TxEffectDeluxe, Error>({
1414
queryKey: queryKeyGenerator.txEffectByHash(hash),
@@ -17,7 +17,7 @@ export const useGetTxEffectByHash = (
1717
};
1818

1919
export const useGetTxEffectsByBlockHeight = (
20-
height: bigint | string | number | undefined
20+
height: bigint | string | number | undefined,
2121
): UseQueryResult<ChicmozL2TxEffectDeluxe[], Error> => {
2222
if (typeof height === "string" && height?.startsWith("0x"))
2323
throw new Error("Invalid block height");
@@ -32,7 +32,7 @@ export const useGetTxEffectsByBlockHeight = (
3232

3333
export const useGetTxEffectsByBlockHeightRange = (
3434
from: bigint | undefined,
35-
to: bigint | undefined
35+
to: bigint | undefined,
3636
): UseQueryResult<(ChicmozL2TxEffectDeluxe | undefined)[], Error>[] => {
3737
return useQueries({
3838
queries:
@@ -45,3 +45,13 @@ export const useGetTxEffectsByBlockHeightRange = (
4545
})),
4646
});
4747
};
48+
49+
export const useGetLatestTxEffects = (): UseQueryResult<
50+
ChicmozL2TxEffectDeluxe[] | undefined,
51+
Error
52+
> => {
53+
return useQuery<ChicmozL2TxEffectDeluxe[] | undefined, Error>({
54+
queryKey: queryKeyGenerator.latestTxEffects,
55+
queryFn: () => TxEffectsAPI.getLatestTxEffects(),
56+
});
57+
};

services/explorer-ui/src/hooks/api/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const queryKeyGenerator = {
77
Number(height),
88
],
99
txEffectByHash: (hash: string) => ["txEffectByHash", hash],
10+
latestTxEffects: ["latestTxEffects"],
1011
pendingTxs: ["pendingTxs"],
1112
latestBlock: ["latestBlock"],
1213
latestBlocks: ["latestBlocks"],

services/explorer-ui/src/pages/landing/index.tsx

+20-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
HealthStatus,
88
useAvarageBlockTime,
99
useAvarageFees,
10-
useGetTxEffectsByBlockHeightRange,
10+
useGetLatestTxEffects,
1111
useLatestBlocks,
1212
usePendingTxs,
1313
useSubTitle,
@@ -19,7 +19,7 @@ import {
1919
} from "~/hooks";
2020
import { formatDuration, formatFees } from "~/lib/utils";
2121
import { routes } from "~/routes/__root";
22-
import { mapLatestBlocks, parseTxEffectsData } from "./util";
22+
import { mapLatestBlocks, mapLatestTxEffects } from "./util";
2323

2424
export const Landing: FC = () => {
2525
const { systemHealth } = useSystemHealth();
@@ -57,23 +57,24 @@ export const Landing: FC = () => {
5757

5858
useSubTitle(latestBlocks?.[0]?.height.toString() ?? routes.home.title);
5959

60-
const latestTxEffectsData = useGetTxEffectsByBlockHeightRange(
61-
latestBlocks?.at(40)?.height ?? latestBlocks?.at(-1)?.height,
62-
latestBlocks?.at(0)?.height
63-
);
60+
const {
61+
data: latestTxEffectsData,
62+
isLoading: isLoadingTxEffects,
63+
error: txEffectsError,
64+
} = useGetLatestTxEffects();
6465

6566
const { data: pendingTxs } = usePendingTxs();
6667

67-
const {
68-
isLoadingTxEffects,
69-
txEffectsErrorMsg: txEffectsError,
70-
latestTxEffects,
71-
} = parseTxEffectsData(latestTxEffectsData, latestBlocks);
72-
7368
const latestTxEffectsWithPending = useMemo(() => {
69+
if (!latestTxEffectsData) {
70+
return [];
71+
}
72+
if (!latestBlocks) {
73+
return [];
74+
}
7475
const disguisedPendingTxs =
7576
pendingTxs?.reduce((acc, tx) => {
76-
if (!latestTxEffects.some((effect) => effect.txHash === tx.hash)) {
77+
if (!latestTxEffectsData.some((effect) => effect.txHash === tx.hash)) {
7778
acc.push({
7879
txHash: tx.hash,
7980
transactionFee: -1,
@@ -83,12 +84,15 @@ export const Landing: FC = () => {
8384
}
8485
return acc;
8586
}, [] as TxEffectTableSchema[]) ?? [];
86-
return [...disguisedPendingTxs, ...latestTxEffects];
87-
}, [pendingTxs, latestTxEffects]);
87+
return [
88+
...disguisedPendingTxs,
89+
...mapLatestTxEffects(latestTxEffectsData, latestBlocks),
90+
];
91+
}, [pendingTxs, latestTxEffectsData, latestBlocks]);
8892

8993
const averageBlockTimeFormatted = formatDuration(
9094
Number(avarageBlockTime) / 1000,
91-
true
95+
true,
9296
);
9397

9498
const formattedFees = formatFees(avarageFees);
+19-28
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { type ChicmozL2BlockLight } from "@chicmoz-pkg/types";
1+
import {
2+
type ChicmozL2TxEffectDeluxe,
3+
type ChicmozL2BlockLight,
4+
} from "@chicmoz-pkg/types";
25
import { blockSchema } from "~/components/blocks/blocks-schema";
36
import {
4-
type TxEffectTableSchema,
57
getTxEffectTableObj,
8+
type TxEffectTableSchema,
69
} from "~/components/tx-effects/tx-effects-schema";
7-
import { type useGetTxEffectsByBlockHeightRange } from "~/hooks";
810

911
export const mapLatestBlocks = (latestBlocks?: ChicmozL2BlockLight[]) => {
10-
if (!latestBlocks) return undefined;
12+
if (!latestBlocks) {
13+
return undefined;
14+
}
1115
return latestBlocks.map((block) => {
1216
return blockSchema.parse({
1317
height: block.height,
@@ -19,30 +23,17 @@ export const mapLatestBlocks = (latestBlocks?: ChicmozL2BlockLight[]) => {
1923
});
2024
};
2125

22-
export const parseTxEffectsData = (
23-
txEffectsData: ReturnType<typeof useGetTxEffectsByBlockHeightRange>,
24-
latestBlocks?: ChicmozL2BlockLight[]
26+
export const mapLatestTxEffects = (
27+
latestTxEffects: ChicmozL2TxEffectDeluxe[],
28+
latestBlocks: ChicmozL2BlockLight[],
2529
) => {
26-
let isLoadingTxEffects = false;
27-
let txEffectsErrorMsg: string | undefined = undefined;
28-
29-
let latestTxEffects: TxEffectTableSchema[] = [];
30-
txEffectsData.forEach((data, i) => {
31-
if (data.isLoading) isLoadingTxEffects = true;
32-
if (data.error) txEffectsErrorMsg = data.error.message;
33-
if (data.data) {
34-
if (!latestBlocks) return;
35-
const newTxEffects = data.data.reduce((acc, txEffect) => {
36-
if (txEffect === undefined) return acc;
37-
if (latestBlocks[i] === undefined) return acc;
38-
return acc.concat(getTxEffectTableObj(txEffect, latestBlocks[i]));
39-
}, latestTxEffects);
40-
latestTxEffects = newTxEffects;
30+
return latestTxEffects.reduce((acc, txEffect) => {
31+
const matchingBlock = latestBlocks.find(
32+
(block) => block.height === txEffect.blockHeight,
33+
);
34+
if (!matchingBlock) {
35+
return acc;
4136
}
42-
});
43-
return {
44-
isLoadingTxEffects,
45-
txEffectsErrorMsg,
46-
latestTxEffects,
47-
};
37+
return acc.concat(getTxEffectTableObj(txEffect, matchingBlock));
38+
}, [] as TxEffectTableSchema[]);
4839
};

services/explorer-ui/src/pages/tx-effect/index.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { type FC } from "react";
22
import { InfoBadge } from "~/components/info-badge";
33
import { TxEffectsTable } from "~/components/tx-effects/tx-effects-table";
44
import {
5-
useGetTxEffectsByBlockHeightRange,
5+
useGetLatestTxEffects,
66
useLatestBlocks,
77
useSubTitle,
88
useTotalTxEffects,
99
useTotalTxEffectsLast24h,
1010
} from "~/hooks";
1111
import { routes } from "~/routes/__root";
12-
import { parseTxEffectsData } from "../landing/util";
12+
import { mapLatestTxEffects } from "../landing/util";
1313

1414
export const TxEffects: FC = () => {
1515
useSubTitle(routes.txEffects.children.index.title);
@@ -25,15 +25,11 @@ export const TxEffects: FC = () => {
2525
error: errorTotalEffects24h,
2626
} = useTotalTxEffectsLast24h();
2727

28-
const latestTxEffectsData = useGetTxEffectsByBlockHeightRange(
29-
latestBlocks?.at(-1)?.height,
30-
latestBlocks?.at(0)?.height
31-
);
3228
const {
33-
isLoadingTxEffects,
34-
txEffectsErrorMsg: txEffectsError,
35-
latestTxEffects,
36-
} = parseTxEffectsData(latestTxEffectsData, latestBlocks);
29+
data: latestTxEffectsData,
30+
isLoading: isLoadingTxEffects,
31+
error: txEffectsError,
32+
} = useGetLatestTxEffects();
3733

3834
return (
3935
<div className="mx-auto px-5 max-w-[1440px] md:px-[70px]">
@@ -56,11 +52,15 @@ export const TxEffects: FC = () => {
5652
/>
5753
</div>
5854
<div className="rounded-lg shadow-lg">
59-
<TxEffectsTable
60-
txEffects={latestTxEffects}
61-
isLoading={isLoading || isLoadingTxEffects}
62-
error={error ?? txEffectsError}
63-
/>
55+
{latestTxEffectsData && latestBlocks ? (
56+
<TxEffectsTable
57+
txEffects={mapLatestTxEffects(latestTxEffectsData, latestBlocks)}
58+
isLoading={isLoading || isLoadingTxEffects}
59+
error={error ?? txEffectsError}
60+
/>
61+
) : (
62+
<div>No data</div>
63+
)}
6464
</div>
6565
</div>
6666
);

services/explorer-ui/src/service/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const aztecExplorer = {
66
getL2BlockByHash: "l2/blocks/",
77
getL2BlockByHeight: "l2/blocks/",
88
getL2BlocksByHeightRange: "l2/blocks",
9+
getL2TxEffects: "l2/tx-effects",
910
getL2TxEffectByHash: "l2/tx-effects/",
1011
getL2TxEffectsByHeight: (height: bigint) => `l2/blocks/${height}/tx-effects`,
1112
getL2TxEffectByHeightAndIndex: (height: bigint, index: number) =>

0 commit comments

Comments
 (0)