From 2f2245be754d45933fec3f83dfb4dd4dbddf958c Mon Sep 17 00:00:00 2001 From: om santoshwar Date: Sat, 2 Nov 2024 01:38:39 +0530 Subject: [PATCH] add Liquidity provider tab --- pages/pools/[id]/index.tsx | 13 +- .../liquidity-provider-table.tsx | 239 ++++++++++++++++++ 2 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 src/components/liquidity-provider-table/liquidity-provider-table.tsx diff --git a/pages/pools/[id]/index.tsx b/pages/pools/[id]/index.tsx index a96f31b..bc9b164 100644 --- a/pages/pools/[id]/index.tsx +++ b/pages/pools/[id]/index.tsx @@ -29,6 +29,7 @@ import { Row } from "components/styled/row"; import { SearchInput } from "components/styled/search-input"; import RenderIf from "components/render-if"; import TokensTable from "components/tokens-table/tokens-table"; +import LiquidityProvidersTable from "components/liquidity-provider-table/liquidity-provider-table"; import { useQueryTokens } from "hooks/tokens"; import { useState } from "react"; import { shouldFilterEvent, shouldFilterToken } from "utils/filters"; @@ -316,7 +317,7 @@ const PoolPage = () => { ( { filters={eventsFilter} /> + + {/* */} + + )} diff --git a/src/components/liquidity-provider-table/liquidity-provider-table.tsx b/src/components/liquidity-provider-table/liquidity-provider-table.tsx new file mode 100644 index 0000000..e835926 --- /dev/null +++ b/src/components/liquidity-provider-table/liquidity-provider-table.tsx @@ -0,0 +1,239 @@ +import { + Skeleton, + Box, + Table, + TableBody, + TableCell, + TableHead, + TablePagination, + TableRow, + TableSortLabel, + TableContainer, + } from "soroswap-ui"; + + import { visuallyHidden } from "@mui/utils"; + import { useRouter } from "next/router"; + import * as React from "react"; + import useTable from "../../hooks/use-table"; + import { Token } from "../../types/tokens"; + import { formatNumberToMoney } from "../../utils/utils"; + import TokenImage from "../token"; + import { StyledCard } from "components/styled/card"; + import { StyledTableCell } from "components/styled/table-cell"; + import { useTheme } from "soroswap-ui"; + + interface HeadCell { + id: keyof Token; + label: string; + numeric: boolean; + } + + const headCells: readonly HeadCell[] = [ + { + id: "asset", + numeric: false, + label: "Name", + }, + { + id: "price", + numeric: true, + label: "Account", + }, + /* { + id: "change", + numeric: true, + label: "Price Change", + }, */ + + { + id: "tvl", + numeric: true, + label: "TVL", + }, + { + id: "volume24h", + numeric: true, + label: "Pool Share", + }, + ]; + + interface TokensTableProps { + onRequestSort: ( + event: React.MouseEvent, + property: keyof Token + ) => void; + order: "asc" | "desc"; + orderBy: string; + } + + function TokensTableHead(props: TokensTableProps) { + const { order, orderBy, onRequestSort } = props; + const createSortHandler = + (property: keyof Token) => (event: React.MouseEvent) => { + onRequestSort(event, property); + }; + + return ( + + + # + {headCells.map((headCell) => ( + + + {headCell.label} + {orderBy === headCell.id ? ( + + {order === "desc" ? "sorted descending" : "sorted ascending"} + + ) : null} + + + ))} + + + ); + } + + export default function TokensTable({ + rows, + emptyMessage = "No tokens found", + isLoading = false, + itemsPerPage = 10, + }: { + rows: Token[]; + emptyMessage?: string; + isLoading?: boolean; + itemsPerPage?: number; + }) { + const { + order, + orderBy, + handleRequestSort, + visibleRows, + emptyRows, + rowsPerPage, + page, + handleChangePage, + handleChangeRowsPerPage, + } = useTable({ + rows, + defaultOrder: "desc", + defaultOrderBy: "tvl", + itemsPerPage, + }); + + const router = useRouter(); + + const onClickRow = (token: string) => { + router.push({ + pathname: `/tokens/${token}`, + query: { + network: router.query.network, + }, + }); + }; + + const theme = useTheme(); + + if (isLoading) { + return ; + } + + return ( + + + + + + + {visibleRows.map((row, index) => { + return ( + + {index + 1} + + + {row.asset.name ?? row.asset.code} + + + {formatNumberToMoney(row.price)} + + {/* + + */} + + {formatNumberToMoney(row.volume24h)} + + + {formatNumberToMoney(row.tvl, 2)} + + + ); + })} + {emptyRows > 0 && ( + + + + )} + {visibleRows.length === 0 && ( + + + No tokens found + + + )} + +
+
+ +
+
+ ); + } + \ No newline at end of file