Skip to content

Commit

Permalink
fix: wallet table latyout
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 9, 2024
1 parent e551063 commit 6c60dd2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/renderer/src/components/ui/datetime/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import {
} from "../tooltip"

const formatTemplateString = "lll"
const formatTime = (date: string | Date, relativeBeforeDay?: number) => {
const formatTime = (
date: string | Date,
relativeBeforeDay?: number,
template = formatTemplateString,
) => {
if (
relativeBeforeDay &&
Math.abs(dayjs(date).diff(new Date(), "d")) > relativeBeforeDay
) {
return dayjs(date).format(formatTemplateString)
return dayjs(date).format(template)
}
return dayjs
.duration(dayjs(date).diff(dayjs(), "minute"), "minute")
Expand Down Expand Up @@ -47,17 +51,23 @@ const getUpdateInterval = (date: string | Date, relativeBeforeDay?: number) => {
export const RelativeTime: FC<{
date: string | Date
displayAbsoluteTimeAfterDay?: number
dateFormatTemplate?: string
}> = (props) => {
const { displayAbsoluteTimeAfterDay = 29 } = props
const {
displayAbsoluteTimeAfterDay = 29,
dateFormatTemplate = formatTemplateString,
} = props
const [relative, setRelative] = useState<string>(() =>
formatTime(props.date, displayAbsoluteTimeAfterDay),
formatTime(props.date, displayAbsoluteTimeAfterDay, dateFormatTemplate),
)

const timerRef = useRef<any>(null)

useEffect(() => {
const updateRelativeTime = () => {
setRelative(formatTime(props.date, displayAbsoluteTimeAfterDay))
setRelative(
formatTime(props.date, displayAbsoluteTimeAfterDay, dateFormatTemplate),
)
const updateInterval = getUpdateInterval(
props.date,
displayAbsoluteTimeAfterDay,
Expand All @@ -73,8 +83,8 @@ export const RelativeTime: FC<{
return () => {
clearTimeout(timerRef.current)
}
}, [props.date, displayAbsoluteTimeAfterDay])
const formated = dayjs(props.date).format(formatTemplateString)
}, [props.date, displayAbsoluteTimeAfterDay, dateFormatTemplate])
const formated = dayjs(props.date).format(dateFormatTemplate)

if (formated === relative) {
return <>{relative}</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import {
TableHeader,
TableRow,
} from "@renderer/components/ui/table"
import {
Tooltip,
TooltipContent,
TooltipPortal,
TooltipTrigger,
} from "@renderer/components/ui/tooltip"
import { cn } from "@renderer/lib/utils"
import { usePresentUserProfileModal } from "@renderer/modules/profile/hooks"
import { SettingSectionTitle } from "@renderer/modules/settings/section"
Expand Down Expand Up @@ -90,10 +96,22 @@ export const TransactionsSection = () => {
</TableCell>

<TableCell align="left" size="sm" className="pl-6">
<RelativeTime date={row.createdAt} />
<RelativeTime date={row.createdAt} dateFormatTemplate="l" />
</TableCell>
<TableCell align="left" size="sm" className="pl-6">
<a target="_blank" href={`https://scan.rss3.io/tx/${row.hash}`}>{row.hash.slice(0, 6)}...</a>
<Tooltip>
<TooltipTrigger>
<a
target="_blank"
href={`https://scan.rss3.io/tx/${row.hash}`}
>
{row.hash.slice(0, 6)}...
</a>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent>{row.hash}</TooltipContent>
</TooltipPortal>
</Tooltip>
</TableCell>
</TableRow>
))}
Expand Down

0 comments on commit 6c60dd2

Please sign in to comment.