Skip to content

Commit

Permalink
add status to bridge txn columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennievon committed Aug 26, 2024
1 parent 389430e commit 5215482
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { ColumnDef } from "@tanstack/react-table";
import { Badge } from "@/src/components/ui/badge";
import { Badge, badgeVariants } from "@/src/components/ui/badge";

import { statuses } from "@/src/components/modules/transactions/constants";
import { DataTableColumnHeader } from "@/src/components/modules/common/data-table/data-table-column-header";
Expand All @@ -18,18 +18,18 @@ export const columns: ColumnDef<Transactions>[] = [
<DataTableColumnHeader column={column} title="Status" />
),
cell: ({ row }) => {
const status = statuses.find((s) => s.value === "0x1");
const variant = "success";
const status = statuses.find((s) => s.value === row.original.status);
return (
<Badge variant={variant}>
{status?.icon && <status.icon className="h-5 w-5 mr\2" />}
<Badge variant={status?.variant as keyof typeof badgeVariants}>
{status?.icon && <status.icon className="h-5 w-5 mr-2" />}
{status?.label}
</Badge>
);
},
enableSorting: false,
enableHiding: false,
},

{
accessorKey: "blockNumber",
header: ({ column }) => (
Expand Down Expand Up @@ -80,14 +80,14 @@ export const columns: ColumnDef<Transactions>[] = [
enableSorting: false,
enableHiding: false,
},
{
id: "actions",
cell: ({ row }) => {
return (
<Link href={`/tx/personal/${row.original.transactionHash}`}>
<EyeOpenIcon className="h-5 w-5 text-muted-foreground hover:text-primary transition-colors cursor-pointer" />
</Link>
);
},
},
// {
// id: "actions",
// cell: ({ row }) => {
// return (
// <Link href={`/tx/personal/${row.original.transactionHash}`}>
// <EyeOpenIcon className="h-5 w-5 text-muted-foreground hover:text-primary transition-colors cursor-pointer" />
// </Link>
// );
// },
// },
];
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { CheckIcon, Cross2Icon } from "@radix-ui/react-icons";
import { HourglassIcon } from "lucide-react";

export const statuses = [
{
value: "0x1",
value: "Success",
label: "Success",
icon: CheckIcon,
variant: "success",
},
{
value: "0x0",
value: "Failure",
label: "Failure",
icon: Cross2Icon,
variant: "destructive",
},
{
value: "Pending",
label: "Pending",
icon: HourglassIcon,
variant: "primary",
},
];

export const types = [
Expand Down
16 changes: 14 additions & 2 deletions tools/bridge-frontend/src/services/useContractService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,24 @@ export const useContractService = () => {
const filter = {
address: messageBusAddress,
topics,
fromBlock: 72548,
};

let prov = new ethers.providers.Web3Provider(provider);
const logs = await prov.getLogs(filter);
return logs;
const transactions = await Promise.all(
logs.map(async (log) => {
const receipt = await prov.getTransactionReceipt(log.transactionHash);
return {
...log,
status: receipt
? receipt.status
? "Success"
: "Failed"
: "Pending",
};
})
);
return transactions;
} catch (error) {
return handleError(error, "Error fetching transactions");
}
Expand Down
3 changes: 1 addition & 2 deletions tools/bridge-frontend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ export enum ItemPosition {
LAST = "last",
}

export type TransactionType = "0x0" | "0x1" | "0x2" | "0x3";

export type Transactions = {
blockNumber: number;
blockHash: string;
Expand All @@ -234,4 +232,5 @@ export type Transactions = {
topics: string[];
transactionHash: string;
logIndex: number;
status: "Success" | "Failed" | "Pending";
};

0 comments on commit 5215482

Please sign in to comment.