diff --git a/frontend/src/components/TransactionItem.tsx b/frontend/src/components/TransactionItem.tsx new file mode 100644 index 00000000..e521b235 --- /dev/null +++ b/frontend/src/components/TransactionItem.tsx @@ -0,0 +1,212 @@ +import dayjs from "dayjs"; +import { + ArrowDownIcon, + ArrowUpIcon, + ChevronDown, + ChevronUp, + CopyIcon, +} from "lucide-react"; +import React from "react"; +import { + Credenza, + CredenzaBody, + CredenzaContent, + CredenzaFooter, + CredenzaHeader, + CredenzaTitle, + CredenzaTrigger, +} from "src/components/ui/credenza"; +import { toast } from "src/components/ui/use-toast"; +import { copyToClipboard } from "src/lib/clipboard"; +import { Transaction } from "src/types"; + +type Props = { + tx: Transaction; +}; + +function TransactionItem({ tx }: Props) { + const [showDetails, setShowDetails] = React.useState(false); + const type = tx.type; + + const copy = (text: string) => { + copyToClipboard(text); + toast({ title: "Copied to clipboard." }); + }; + + return ( + { + if (!open) { + setShowDetails(false); + } + }} + > + +
+
+ {type == "outgoing" ? ( +
+ +
+ ) : ( +
+ +
+ )} +
+
+
+

+ {type == "incoming" ? "Received" : "Sent"} +

+

+ {dayjs(tx.settled_at * 1000).fromNow()} +

+
+

+ {tx.description || "Lightning invoice"} +

+
+
+
+

+ {type == "outgoing" ? "-" : "+"} {Math.floor(tx.amount / 1000)} +

+

sats

+ + {/* {!!tx.totalAmountFiat && ( +

+ ~{tx.totalAmountFiat} +

+ )} */} +
+
+
+
+ + + + {type == "outgoing" ? "Sent Bitcoin" : "Received Bitcoin"} + + + +
+ {type == "outgoing" ? ( +
+ +
+ ) : ( +
+ +
+ )} +
+

+ {Math.floor(tx.amount / 1000)}{" "} + {Math.floor(tx.amount / 1000) == 1 ? "sat" : "sats"} +

+ {/*

+ Fiat Amount +

*/} +
+
+
+

Date & Time

+

+ {dayjs(tx.settled_at).toString()} +

+
+ {type == "outgoing" && ( +
+

Fee

+

+ {Math.floor(tx.fees_paid / 1000)}{" "} + {Math.floor(tx.fees_paid / 1000) == 1 ? "sat" : "sats"} +

+
+ )} + {tx.description && ( +
+

Description

+

{tx.description}

+
+ )} +
+ +
setShowDetails(!showDetails)} + > + Details + {showDetails ? ( + + ) : ( + + )} +
+ {showDetails && ( + <> +
+

Preimage

+
+

+ {tx.preimage} +

+ { + copy(tx.preimage); + }} + /> +
+
+
+

Hash

+
+

+ {tx.payment_hash} +

+ { + copy(tx.payment_hash); + }} + /> +
+
+ + )} +
+
+
+ ); +} + +export default TransactionItem; diff --git a/frontend/src/components/TransactionsList.tsx b/frontend/src/components/TransactionsList.tsx index 1076707a..f64551c7 100644 --- a/frontend/src/components/TransactionsList.tsx +++ b/frontend/src/components/TransactionsList.tsx @@ -1,41 +1,16 @@ -import dayjs from "dayjs"; -import { - ArrowDownIcon, - ArrowUpIcon, - ChevronDown, - ChevronUp, - CopyIcon, - Drum, -} from "lucide-react"; -import React from "react"; +import { Drum } from "lucide-react"; import EmptyState from "src/components/EmptyState"; import Loading from "src/components/Loading"; -import { - Credenza, - CredenzaBody, - CredenzaContent, - CredenzaFooter, - CredenzaHeader, - CredenzaTitle, - CredenzaTrigger, -} from "src/components/ui/credenza"; -import { toast } from "src/components/ui/use-toast"; +import TransactionItem from "src/components/TransactionItem"; import { useTransactions } from "src/hooks/useTransactions"; -import { copyToClipboard } from "src/lib/clipboard"; function TransactionsList() { const { data: transactions, isLoading } = useTransactions(); - const [showDetails, setShowDetails] = React.useState(false); if (isLoading) { return ; } - const copy = (text: string) => { - copyToClipboard(text); - toast({ title: "Copied to clipboard." }); - }; - return (
{!transactions?.length ? ( @@ -49,189 +24,7 @@ function TransactionsList() { ) : ( <> {transactions?.map((tx, i) => { - const type = tx.type; - - return ( - { - if (!open) { - setShowDetails(false); - } - }} - > - -
-
- {type == "outgoing" ? ( -
- -
- ) : ( -
- -
- )} -
-
-
-

- {type == "incoming" ? "Received" : "Sent"} -

-

- {dayjs(tx.settled_at * 1000).fromNow()} -

-
-

- {tx.description || "Lightning invoice"} -

-
-
-
-

- {type == "outgoing" ? "-" : "+"}{" "} - {Math.floor(tx.amount / 1000)} -

-

sats

- - {/* {!!tx.totalAmountFiat && ( -

- ~{tx.totalAmountFiat} -

- )} */} -
-
-
-
- - - - {type == "outgoing" ? "Sent Bitcoin" : "Received Bitcoin"} - - - -
- {type == "outgoing" ? ( -
- -
- ) : ( -
- -
- )} -
-

- {Math.floor(tx.amount / 1000)}{" "} - {Math.floor(tx.amount / 1000) == 1 ? "sat" : "sats"} -

- {/*

- Fiat Amount -

*/} -
-
-
-

Date & Time

-

- {dayjs(tx.settled_at).toString()} -

-
- {type == "outgoing" && ( -
-

Fee

-

- {Math.floor(tx.fees_paid / 1000)}{" "} - {Math.floor(tx.fees_paid / 1000) == 1 - ? "sat" - : "sats"} -

-
- )} - {tx.description && ( -
-

Description

-

- {tx.description} -

-
- )} -
- -
setShowDetails(!showDetails)} - > - Details - {showDetails ? ( - - ) : ( - - )} -
- {showDetails && ( - <> -
-

Preimage

-
-

- {tx.preimage} -

- { - copy(tx.preimage); - }} - /> -
-
-
-

Hash

-
-

- {tx.payment_hash} -

- { - copy(tx.payment_hash); - }} - /> -
-
- - )} -
-
-
- ); + return ; })} )}