Skip to content

Commit

Permalink
Merge branch 'add-memeContract' of https://github.com/burrowHQ/burrow…
Browse files Browse the repository at this point in the history
…-cash into add-memeContract
  • Loading branch information
deep-path committed Jan 5, 2025
2 parents 62e57e9 + 769d192 commit 34e09d2
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 386 deletions.
160 changes: 0 additions & 160 deletions components/Table/common/apy-cell.tsx

This file was deleted.

64 changes: 0 additions & 64 deletions components/Table/common/cells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,11 @@ import { useAppSelector } from "../../../redux/hooks";
import { getDisplayAsTokenValue, getShowDust } from "../../../redux/appSelectors";
import { Rewards } from "../../index";
import { useFullDigits } from "../../../hooks/useFullDigits";
import APYCell from "./apy-cell";

type FormatType = "apy" | "amount" | "string" | "reward" | "usd";
type FormatMap = {
[t in FormatType]: (v: number | string) => string;
};

export const Cell = ({
value,
rowData,
format,
tooltip,
rewards,
rewardLayout,
page,
}: {
value?: number | string;
rowData: UIAsset | undefined;
format: FormatType;
tooltip?: string;
rewards?: IReward[];
rewardLayout?: "horizontal" | "vertical";
page?: "deposit" | "borrow";
}) => {
if (!rowData) return <Skeleton sx={{ bgcolor: "gray" }} height={32} />;

const { price } = rowData;
const displayAsTokenValue = useAppSelector(getDisplayAsTokenValue);
const showDust = useAppSelector(getShowDust);
const { fullDigits } = useFullDigits();
const isCompact = fullDigits?.table;
const isReward = format === "reward";
const isAPY = format === "apy";

const formatMap: FormatMap = {
apy: (v) => `${v.toLocaleString(undefined, APY_FORMAT)}%`,
amount: (v) =>
displayAsTokenValue
? isCompact
? millify(Number(v))
: Number(v).toLocaleString(undefined, showDust ? DUST_FORMAT : TOKEN_FORMAT)
: isCompact
? `$${millify(Number(v) * price)}`
: (Number(v) * price).toLocaleString(undefined, USD_FORMAT),
string: (v) => v.toString(),
reward: (v) => (isCompact ? millify(Number(v)) : formatRewardAmount(Number(v))),
usd: (v) => (isCompact ? `$${millify(Number(v))}` : v.toLocaleString(undefined, USD_FORMAT)),
};

if (isAPY) {
return <APYCell rewards={rewards} baseAPY={value} page={page} tokenId={rowData.tokenId} />;
}
if (isReward)
return (
<Rewards rewards={rewards} layout={rewardLayout} page={page} tokenId={rowData.tokenId} />
);
if (!value) return <Box>-</Box>;

const displayValue = formatMap[format](value);

return tooltip ? (
<Tooltip title={tooltip} placement="top" arrow disableFocusListener>
<Box>{displayValue}</Box>
</Tooltip>
) : (
<Box>{displayValue}</Box>
);
};

export const formatRewardAmount = (amount: number) =>
amount < 0.001 ? "<0.001" : amount.toLocaleString(undefined, NUMBER_FORMAT);

Expand Down
125 changes: 0 additions & 125 deletions components/Table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import {
Table as MUITable,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
TableSortLabel,
Box,
useTheme,
} from "@mui/material";
import { visuallyHidden } from "@mui/utils";
import { useFullDigits } from "../../hooks/useFullDigits";
import { IOrder } from "../../redux/appSlice";

const descendingComparator = (a, b, orderBy) => {
Expand Down Expand Up @@ -41,115 +28,3 @@ export interface TableProps {
onRowClick?: (rowData: any) => void;
sx?: any;
}

function Table({ rows, columns, onRowClick, sorting, sx = {} }: TableProps) {
const theme = useTheme();
const { fullDigits } = useFullDigits();

const handleRequestSort = (event, property) => {
sorting.setSorting(sorting.name, property, sorting.order === "asc" ? "desc" : "asc");
};

const createSortHandler = (property) => (event) => {
handleRequestSort(event, property);
};

const padding = fullDigits?.table ? "0.5rem 0.5rem" : "0.5rem 1rem";

return (
<TableContainer
component={Box}
sx={{
maxWidth: 950,
m: "0 auto",
mb: "1.5rem",
px: "1rem",
width: ["none", "none", "max-content"],
...sx,
}}
>
<MUITable aria-label="table">
<TableHead>
<TableRow sx={{ padding }}>
{columns?.map(({ dataKey, label, align, cellStyle, sortLabelStyle }) => (
<TableCell
align={align}
sx={{
color: theme.palette.secondary.main,
fontSize: 12,
padding,
...(cellStyle || {}),
borderBottom: "none",
}}
key={dataKey}
sortDirection={sorting.property === dataKey ? sorting.order : false}
>
<TableSortLabel
active={sorting.property === dataKey}
direction={sorting.property === dataKey ? sorting.order : "asc"}
onClick={createSortHandler(dataKey)}
sx={{
color: theme.custom.tableLabelColor,
"&:hover": {
color: "primary.main",
},
"&.Mui-active": {
color: "primary.main",
},
"& .MuiTableSortLabel-icon": {
color: `${theme.palette.primary.main} !important`,
},
minWidth: [100, 100, "auto"],
...(sortLabelStyle || {}),
}}
>
{label}
{sorting.property === dataKey ? (
<Box component="span" sx={visuallyHidden}>
{sorting.property === "desc" ? "sorted descending" : "sorted ascending"}
</Box>
) : null}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.sort(getComparator(sorting.order, sorting.property)).map((rowData, idx) => (
<TableRow
key={rowData?.symbol || idx}
sx={{
"&:last-child td, &:last-child th": { border: 0 },
cursor: onRowClick && "pointer",
"&:hover": { background: onRowClick && theme.palette.background.paper },
padding,
}}
onClick={() => onRowClick && rowData && onRowClick(rowData)}
>
{columns?.map(
({ dataKey, align, Cell, cellStyle }) =>
Cell && (
<TableCell
key={dataKey}
align={align}
sx={{
color: theme.palette.secondary.main,
fontWeight: "bold",
padding,
...(cellStyle || {}),
borderBottomColor: theme.custom.tableCellBorderBottomColor,
}}
>
<Cell rowData={rowData} />
</TableCell>
),
)}
</TableRow>
))}
</TableBody>
</MUITable>
</TableContainer>
);
}

export default Table;
2 changes: 0 additions & 2 deletions components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Input from "./Input";
import Modal from "./Modal";
import Slider from "./Slider";
import Table from "./Table";
import Layout from "./Layout";
import PageTitle from "./PageTitle";
import OnboardingBRRR from "./OnboardingBRRR";
Expand All @@ -13,7 +12,6 @@ import FallbackError from "./FallbackError";
import CheckNewAppVersion from "./CheckNewAppVersion";

export {
Table,
Modal,
Input,
Slider,
Expand Down
Loading

0 comments on commit 34e09d2

Please sign in to comment.