diff --git a/frontend/src/components/TransactionItem.tsx b/frontend/src/components/TransactionItem.tsx index ed589387..60e8bf4d 100644 --- a/frontend/src/components/TransactionItem.tsx +++ b/frontend/src/components/TransactionItem.tsx @@ -15,6 +15,7 @@ import { CredenzaContent, CredenzaFooter, CredenzaHeader, + CredenzaProvider, CredenzaTitle, CredenzaTrigger, } from "src/components/ui/credenza"; @@ -41,188 +42,190 @@ function TransactionItem({ tx }: Props) { }; return ( - { - if (!open) { - setShowDetails(false); - } - }} - > - + { + if (!open) { + setShowDetails(false); + } + }} > -
-
-
- +
+
+
+ > + +
-
-
-
-

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

-

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

+
+

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

+

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

+
+

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

-

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

-
-
-
-

- {type == "outgoing" ? "-" : "+"} - {new Intl.NumberFormat(undefined, {}).format( - Math.floor(tx.amount / 1000) - )}{" "} -

-

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

+
+
+

+ {type == "outgoing" ? "-" : "+"} + {new Intl.NumberFormat(undefined, {}).format( + Math.floor(tx.amount / 1000) + )}{" "} +

+

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

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

~{tx.totalAmountFiat}

)} */} +
-
- - - - - {`${type == "outgoing" ? "Sent" : "Received"} Bitcoin`} - - - -
-
- + + + + {`${type == "outgoing" ? "Sent" : "Received"} Bitcoin`} + + + +
+
-
-
-

- {new Intl.NumberFormat(undefined, {}).format( - Math.floor(tx.amount / 1000) - )}{" "} - {Math.floor(tx.amount / 1000) == 1 ? "sat" : "sats"} -

- {/*

+ > + +

+
+

+ {new Intl.NumberFormat(undefined, {}).format( + Math.floor(tx.amount / 1000) + )}{" "} + {Math.floor(tx.amount / 1000) == 1 ? "sat" : "sats"} +

+ {/*

Fiat Amount

*/} +
-
-
-

Date & Time

-

- {dayjs(tx.settled_at * 1000) - .tz(dayjs.tz.guess()) - .format("D MMMM YYYY, HH:mm")} -

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

Fee

+
+

Date & Time

- {new Intl.NumberFormat(undefined, {}).format( - Math.floor(tx.fees_paid / 1000) - )}{" "} - {Math.floor(tx.fees_paid / 1000) == 1 ? "sat" : "sats"} + {dayjs(tx.settled_at * 1000) + .tz(dayjs.tz.guess()) + .format("D MMMM YYYY, HH:mm")}

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

Description

-

{tx.description}

-
- )} - - -
setShowDetails(!showDetails)} - > - Details - {showDetails ? ( - - ) : ( - + {type == "outgoing" && ( +
+

Fee

+

+ {new Intl.NumberFormat(undefined, {}).format( + Math.floor(tx.fees_paid / 1000) + )}{" "} + {Math.floor(tx.fees_paid / 1000) == 1 ? "sat" : "sats"} +

+
)} -
- {showDetails && ( - <> -
-

Preimage

-
-

- {tx.preimage} -

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

Description

+

{tx.description}

-
-

Hash

-
-

- {tx.payment_hash} -

- { - copy(tx.payment_hash); - }} - /> + )} + + +
setShowDetails(!showDetails)} + > + Details + {showDetails ? ( + + ) : ( + + )} +
+ {showDetails && ( + <> +
+

Preimage

+
+

+ {tx.preimage} +

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

Hash

+
+

+ {tx.payment_hash} +

+ { + copy(tx.payment_hash); + }} + /> +
+
+ + )} + + + + ); } diff --git a/frontend/src/components/ui/credenza.tsx b/frontend/src/components/ui/credenza.tsx index 587515fd..63068eac 100644 --- a/frontend/src/components/ui/credenza.tsx +++ b/frontend/src/components/ui/credenza.tsx @@ -1,5 +1,4 @@ import * as React from "react"; - import { useMediaQuery } from "src/hooks/useMediaQuery"; import { cn } from "src/lib/utils"; import { @@ -39,15 +38,30 @@ interface CredenzaProps extends BaseProps { const desktop = "(min-width: 768px)"; -const Credenza = ({ children, ...props }: RootCredenzaProps) => { +const CredenzaContext = React.createContext(false); + +const CredenzaProvider = ({ children }: BaseProps) => { const isDesktop = useMediaQuery(desktop); + return ( + + {children} + + ); +}; + +const useCredenzaContext = () => { + return React.useContext(CredenzaContext); +}; + +const Credenza = ({ children, ...props }: RootCredenzaProps) => { + const isDesktop = useCredenzaContext(); const Credenza = isDesktop ? Dialog : Drawer; return {children}; }; const CredenzaTrigger = ({ className, children, ...props }: CredenzaProps) => { - const isDesktop = useMediaQuery(desktop); + const isDesktop = useCredenzaContext(); const CredenzaTrigger = isDesktop ? DialogTrigger : DrawerTrigger; return ( @@ -58,7 +72,7 @@ const CredenzaTrigger = ({ className, children, ...props }: CredenzaProps) => { }; const CredenzaClose = ({ className, children, ...props }: CredenzaProps) => { - const isDesktop = useMediaQuery(desktop); + const isDesktop = useCredenzaContext(); const CredenzaClose = isDesktop ? DialogClose : DrawerClose; return ( @@ -69,7 +83,7 @@ const CredenzaClose = ({ className, children, ...props }: CredenzaProps) => { }; const CredenzaContent = ({ className, children, ...props }: CredenzaProps) => { - const isDesktop = useMediaQuery(desktop); + const isDesktop = useCredenzaContext(); const CredenzaContent = isDesktop ? DialogContent : DrawerContent; return ( @@ -84,7 +98,7 @@ const CredenzaDescription = ({ children, ...props }: CredenzaProps) => { - const isDesktop = useMediaQuery(desktop); + const isDesktop = useCredenzaContext(); const CredenzaDescription = isDesktop ? DialogDescription : DrawerDescription; return ( @@ -95,7 +109,7 @@ const CredenzaDescription = ({ }; const CredenzaHeader = ({ className, children, ...props }: CredenzaProps) => { - const isDesktop = useMediaQuery(desktop); + const isDesktop = useCredenzaContext(); const CredenzaHeader = isDesktop ? DialogHeader : DrawerHeader; return ( @@ -106,7 +120,7 @@ const CredenzaHeader = ({ className, children, ...props }: CredenzaProps) => { }; const CredenzaTitle = ({ className, children, ...props }: CredenzaProps) => { - const isDesktop = useMediaQuery(desktop); + const isDesktop = useCredenzaContext(); const CredenzaTitle = isDesktop ? DialogTitle : DrawerTitle; return ( @@ -125,7 +139,7 @@ const CredenzaBody = ({ className, children, ...props }: CredenzaProps) => { }; const CredenzaFooter = ({ className, children, ...props }: CredenzaProps) => { - const isDesktop = useMediaQuery(desktop); + const isDesktop = useCredenzaContext(); const CredenzaFooter = isDesktop ? DialogFooter : DrawerFooter; return ( @@ -143,6 +157,7 @@ export { CredenzaDescription, CredenzaFooter, CredenzaHeader, + CredenzaProvider, CredenzaTitle, CredenzaTrigger, };