-
-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useMemo } from "react"; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
import Link from "@docusaurus/Link"; | ||
import Badge from "@site/src/components/Badge"; | ||
import Table from "@site/src/components/Table"; | ||
|
||
const TABLE_DATA = [ | ||
{ | ||
id: "01", | ||
This comment has been minimized.
Sorry, something went wrong. |
||
createdAt: "2024-06-05T13:24:49.207Z", | ||
txnHash: "0x38412083eb28fdf332d4ca7e1955cbb40a94adfae14ef7a3e9856f95c32b2ef2", | ||
This comment has been minimized.
Sorry, something went wrong. |
||
value: "0.0001", | ||
status: "success", | ||
}, | ||
{ | ||
id: "02", | ||
createdAt: "2024-05-05T13:24:49.207Z", | ||
txnHash: "0x48412083eb28fdf332d4ca7e1955cbb40a94adfae14ef7a3e9856f95c32b2ef2", | ||
value: "0.0002", | ||
status: "failed", | ||
}, | ||
{ | ||
id: "03", | ||
createdAt: "2024-07-05T13:24:49.207Z", | ||
txnHash: "0x58412083eb28fdf332d4ca7e1955cbb40a94adfae14ef7a3e9856f95c32b2ef2", | ||
value: "0.0003", | ||
status: "pending", | ||
}, | ||
]; | ||
|
||
const hideCenterLetters = (word) => { | ||
if (word.length < 10) return word; | ||
return `${word.substring(0, 5)}...${word.substring(word.length - 4)}`; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
}; | ||
|
||
const transformWordEnding = (value, end) => { | ||
const upValue = Math.floor(value); | ||
return `${upValue} ${end}${upValue === 1 ? "" : "s"} ago`; | ||
}; | ||
|
||
const getDiffTime = (time) => { | ||
if (!time) return "unknown"; | ||
const currentTime = Date.now(); | ||
const startTime = new Date(time).getTime(); | ||
const deltaTimeInSec = (currentTime - startTime) / 1000; | ||
const deltaTimeInMin = deltaTimeInSec / 60; | ||
const deltaTimeInHours = deltaTimeInMin / 60; | ||
const deltaTimeInDays = deltaTimeInHours / 24; | ||
|
||
if (deltaTimeInMin < 1) return transformWordEnding(deltaTimeInSec, "second"); | ||
if (deltaTimeInHours < 1) return transformWordEnding(deltaTimeInMin, "minute"); | ||
if (deltaTimeInDays < 1) return transformWordEnding(deltaTimeInHours, "hour"); | ||
return transformWordEnding(deltaTimeInDays, "day"); | ||
}; | ||
|
||
const renderStatus = (status) => { | ||
switch (status) { | ||
case "success": | ||
return "success"; | ||
case "failed": | ||
return "error"; | ||
default: | ||
return "pending"; | ||
} | ||
}; | ||
|
||
export default function TransactionTable() { | ||
const dataRows = useMemo(() => { | ||
return TABLE_DATA.map((item) => ({ | ||
cells: [ | ||
hideCenterLetters(item.txnHash), | ||
getDiffTime(item.createdAt), | ||
`${item.value} ETH`, | ||
<Badge key={item.id} label={item.status} variant={renderStatus(item.status)} />, | ||
<Link key={`link-${item.id}`} to="/" target="_blank" rel="noopener noreferrer"> | ||
View on Etherscan | ||
</Link>, | ||
], | ||
})); | ||
}, []); | ||
|
||
return <Table thCells={["Your Transactions", "Age", "Value", "Status", ""]} trRows={dataRows} />; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from "react"; | ||
import styles from "./table.module.scss"; | ||
import clsx from "clsx"; | ||
|
||
type TableCell = string | React.ReactElement; | ||
|
||
interface TableRow { | ||
cells: TableCell[]; | ||
} | ||
|
||
interface ITable { | ||
classes?: string; | ||
thCells: TableCell[]; | ||
trRows?: TableRow[]; | ||
} | ||
|
||
export default function Table({ classes, thCells = [], trRows = [] }: ITable) { | ||
return ( | ||
This comment has been minimized.
Sorry, something went wrong. |
||
<div className={clsx(styles.tableWrapper, classes)}> | ||
<div className={styles.tableInner}> | ||
<table className={styles.table}> | ||
<thead className={styles.thead}> | ||
<tr className={styles.throw}> | ||
{thCells.map((cell, i) => ( | ||
<th className={styles.thcell} key={`th-${i}`}>{cell}</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{trRows.map((row, i) => ( | ||
<tr key={`tr-${i}`} className={styles.trow}> | ||
{row.cells.map((cell, y) => <td className={styles.tdcell} key={`td-${i}-${y}`}>{cell}</td>)} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
:root { | ||
--table-border-color: rgba(132, 140, 150, 0.16); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
--table-bg-color: #FFF; | ||
--table-bg-thead-color: #F2F4F6; | ||
} | ||
|
||
:root[data-theme='dark'] { | ||
--table-border-color: rgba(132, 140, 150, 0.16); | ||
--table-bg-color: #24272A; | ||
--table-bg-thead-color: #24272A; | ||
} | ||
|
||
.tableWrapper { | ||
max-width: 1014px; | ||
width: 100%; | ||
margin: 0 auto; | ||
overflow-x: auto; | ||
margin-bottom: 24px; | ||
} | ||
|
||
.tableInner { | ||
border: 1px solid var(--table-border-color); | ||
border-radius: 8px; | ||
overflow: hidden; | ||
min-width: 768px; | ||
} | ||
|
||
.table { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
display: table; | ||
border-collapse: collapse; | ||
width: 100%; | ||
font-size: 16px; | ||
line-height: 24px; | ||
font-weight: 400; | ||
margin: 0; | ||
background-color: var(--table-bg-color); | ||
|
||
.thead { | ||
background-color: var(--table-bg-thead-color); | ||
} | ||
|
||
.trow { | ||
background-color: transparent; | ||
border-top: 1px solid var(--table-border-color); | ||
} | ||
} | ||
|
||
.throw { | ||
background-color: transparent; | ||
border: 0; | ||
|
||
.thcell { | ||
font-size: 16px; | ||
line-height: 24px; | ||
font-weight: 500; | ||
padding: 16px; | ||
text-align: left; | ||
background-color: transparent !important; | ||
border: 0; | ||
} | ||
} | ||
|
||
.tdcell { | ||
font-size: 16px; | ||
line-height: 24px; | ||
font-weight: 400; | ||
padding: 16px; | ||
background-color: transparent; | ||
border: 0; | ||
} |
1 comment
on commit 8871cf8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328
Abdulhafez
[email protected]
0xFD689e5f2d8d9Aec0aD328225Ae62FdBDdb30328