diff --git a/app/components/dex-history.tsx b/app/components/dex-history.tsx new file mode 100644 index 0000000..96b5f64 --- /dev/null +++ b/app/components/dex-history.tsx @@ -0,0 +1,326 @@ +"use client"; +import TransactionTable, { + type ColumnDef, +} from "../components/transaction-table.beta"; +import Image from "next/image"; +import { useEffect, useRef } from "react"; +import explorer from "../../public/explorer.svg"; +import strk from "../../public/coin-logos/strk-logo.svg"; +import usdt from "../../public/coin-logos/usdt-logo.svg"; +interface DexHistoryProps { + length?: number; +} + +interface Transaction { + from_to?: null; + from: { + fullname: string; + shortname: string; + image: string; + }; + to: { + fullname: string; + shortname: string; + image: string; + }; + amount: { + from: number; + to: number; + }; + date: { + day: string; + time: string; + }; +} + +export default function DexHistory({ length = 0 }: DexHistoryProps) { + const tableRef = useRef(null); + const containerRef = useRef(null); + + const columns: ColumnDef[] = [ + { + header: "From", + accessorKey: "from", + cell: (info, index) => ( +
+

+ {(index as number) + 1}. +

+
+ {info.from.shortname} +
+
+ + {info.from.fullname} + + + {info.from.shortname} + +
+
+ ), + }, + { + header: "To", + accessorKey: "to", + cell: (info) => ( +
+
+ {info.to.shortname} +
+
+ + {info.to.fullname} + + + {info.to.shortname} + +
+
+ ), + }, + { + header: "Amount", + accessorKey: "to", + cell: (info) => ( +
+ + {info.amount.from} {info.from.shortname} + + + {info.amount.to} {info.to.shortname} + +
+ ), + }, + { + header: "Timestamp", + accessorKey: "date", + cell: (info) => ( +
+ {info.date.day} + {info.date.time} +
+ ), + }, + ]; + + const mobile_columns: ColumnDef[] = [ + { + header: "From . To", + accessorKey: "from_to", + cell: (info, index) => ( +
+

+ {(index as number) + 1}. +

+
+ {info.from.shortname} +
+
+ {info.to.shortname} +
+
+ ), + }, + { + header: "Amount", + accessorKey: "to", + cell: (info) => ( +
+ + {info.amount.from} {info.from.shortname} + + + {info.amount.to} {info.to.shortname} + +
+ ), + }, + { + header: "Timestamp", + accessorKey: "date", + cell: (info) => ( +
+ {info.date.day} + {info.date.time} +
+ ), + }, + ]; + + const transactions: Transaction[] = [ + { + from: { + fullname: "Starknet", + shortname: "STRK", + image: strk, + }, + to: { + fullname: "Tether", + shortname: "USDT", + image: usdt, + }, + amount: { + from: 3000, + to: 809, + }, + date: { + day: "10.09.2024", + time: "GMT 21:08 PM", + }, + }, + { + from: { + fullname: "Starknet", + shortname: "STRK", + image: strk, + }, + to: { + fullname: "Tether", + shortname: "USDT", + image: usdt, + }, + amount: { + from: 3000, + to: 809, + }, + date: { + day: "10.09.2024", + time: "GMT 21:08 PM", + }, + }, + { + from: { + fullname: "Starknet", + shortname: "STRK", + image: strk, + }, + to: { + fullname: "Tether", + shortname: "USDT", + image: usdt, + }, + amount: { + from: 3000, + to: 809, + }, + date: { + day: "10.09.2024", + time: "GMT 21:08 PM", + }, + }, + { + from: { + fullname: "Starknet", + shortname: "STRK", + image: strk, + }, + to: { + fullname: "Tether", + shortname: "USDT", + image: usdt, + }, + amount: { + from: 3000, + to: 809, + }, + date: { + day: "10.09.2024", + time: "GMT 21:08 PM", + }, + }, + { + from: { + fullname: "Starknet", + shortname: "STRK", + image: strk, + }, + to: { + fullname: "Tether", + shortname: "USDT", + image: usdt, + }, + amount: { + from: 3000, + to: 809, + }, + date: { + day: "10.09.2024", + time: "GMT 21:08 PM", + }, + }, + ]; + return ( + <> +
+
+
+
+ Transaction History +
+
+ explorer icon +
+ View in explorer +
+
+
+ {length ? ( +
+
+ +
+
+ +
+
+ ) : ( +
+

+ No Transaction History Yet +

+

+ Once you receive STRK tokens and your subscription is converted, + your history will show up here. +

+
+ )} +
+
+ + ); +} diff --git a/app/components/transaction-table.beta.tsx b/app/components/transaction-table.beta.tsx new file mode 100644 index 0000000..6ada9e9 --- /dev/null +++ b/app/components/transaction-table.beta.tsx @@ -0,0 +1,60 @@ +"use client"; + +import { useState, type ReactNode } from "react"; + +export interface ColumnDef { + header: string; + accessorKey: keyof T; + cell: (info: T, index?: number) => ReactNode; +} + +interface Props { + data: T[]; + columns: ColumnDef[]; + onRowClick?: (row: T) => void; +} + +export default function TransactionTable({ data, columns, onRowClick }: Props) { + const [selectedRow, setSelectedRow] = useState(null); + + const handleRowClick = (index: number, row: T) => { + setSelectedRow(index); + onRowClick?.(row); + }; + + return ( +
+ + + + {columns.map((column, index) => ( + + ))} + + + + {data.map((row, rowIndex) => ( + handleRowClick(rowIndex, row)} + > + {columns.map((column, columnIndex) => ( + + ))} + + ))} + +
+ {column.header} +
+ {column.cell(row, rowIndex)} +
+
+ ); +} diff --git a/app/dex/page.tsx b/app/dex/page.tsx index 6599e59..0900c38 100644 --- a/app/dex/page.tsx +++ b/app/dex/page.tsx @@ -1,5 +1,7 @@ + import React from "react"; import Swapper from "../components/swapper"; +import DexHistory from "../components/dex-history"; import { Metadata } from "next"; import GiveFeedback from "../components/give-feedback"; import PageHeading from "../components/page-heading"; @@ -9,8 +11,10 @@ export const metadata: Metadata = { description: "Please select a token to swap.", }; + export default function page() { return ( +
); diff --git a/public/explorer.svg b/public/explorer.svg new file mode 100644 index 0000000..fd6c580 --- /dev/null +++ b/public/explorer.svg @@ -0,0 +1,4 @@ + + + +