Skip to content

Commit

Permalink
chore: format sat amounts and date
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jul 9, 2024
1 parent 58d4d95 commit f5de6ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
26 changes: 21 additions & 5 deletions frontend/src/components/TransactionItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import {
ArrowDownIcon,
ArrowUpIcon,
Expand All @@ -21,6 +23,9 @@ import { copyToClipboard } from "src/lib/clipboard";
import { cn } from "src/lib/utils";
import { Transaction } from "src/types";

dayjs.extend(utc);
dayjs.extend(timezone);

type Props = {
tx: Transaction;
};
Expand Down Expand Up @@ -89,9 +94,14 @@ function TransactionItem({ tx }: Props) {
type == "incoming" && "text-green-600 dark:color-green-400"
)}
>
{type == "outgoing" ? "-" : "+"} {Math.floor(tx.amount / 1000)}
{type == "outgoing" ? "-" : "+"}
{new Intl.NumberFormat(undefined, {}).format(
Math.floor(tx.amount / 1000)
)}{" "}
</p>
<p className="text-muted-foreground">
{Math.floor(tx.amount / 1000) == 1 ? "sat" : "sats"}
</p>
<p className="text-muted-foreground">sats</p>

{/* {!!tx.totalAmountFiat && (
<p className="text-xs text-gray-400 dark:text-neutral-600">
Expand Down Expand Up @@ -130,7 +140,9 @@ function TransactionItem({ tx }: Props) {
</div>
<div className="ml-4">
<p className="text-xl md:text-2xl font-semibold">
{Math.floor(tx.amount / 1000)}{" "}
{new Intl.NumberFormat(undefined, {}).format(
Math.floor(tx.amount / 1000)
)}{" "}
{Math.floor(tx.amount / 1000) == 1 ? "sat" : "sats"}
</p>
{/* <p className="text-sm md:text-base text-gray-500">
Expand All @@ -141,14 +153,18 @@ function TransactionItem({ tx }: Props) {
<div className="mt-8">
<p className="dark:text-white">Date & Time</p>
<p className="text-muted-foreground">
{dayjs(tx.settled_at * 1000).toString()}
{dayjs(tx.settled_at * 1000)
.tz(dayjs.tz.guess())
.format("D MMMM YYYY, HH:mm")}
</p>
</div>
{type == "outgoing" && (
<div className="mt-6">
<p className="dark:text-white">Fee</p>
<p className="text-muted-foreground">
{Math.floor(tx.fees_paid / 1000)}{" "}
{new Intl.NumberFormat(undefined, {}).format(
Math.floor(tx.fees_paid / 1000)
)}{" "}
{Math.floor(tx.fees_paid / 1000) == 1 ? "sat" : "sats"}
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/TransactionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function TransactionsList() {
/>
) : (
<>
{transactions?.map((tx, i) => {
return <TransactionItem key={`tx-${i}`} tx={tx} />;
{transactions?.map((tx) => {
return <TransactionItem key={tx.payment_hash} tx={tx} />;
})}
</>
)}
Expand Down

0 comments on commit f5de6ac

Please sign in to comment.