Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add transaction popup #15

Merged
merged 7 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"swr": "^2.2.4",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.1",
rolznz marked this conversation as resolved.
Show resolved Hide resolved
"zustand": "^4.5.0"
},
"devDependencies": {
Expand Down
213 changes: 213 additions & 0 deletions frontend/src/components/TransactionItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
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 { cn } from "src/lib/utils";
import { Transaction } from "src/types";

type Props = {
tx: Transaction;
};

function TransactionItem({ tx }: Props) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to add a lot of dependencies (see the change to yarn.lock) and wrap every single transaction in the list with all this markup - this would not be needed if we just made a separate page to view transaction details, is it really that much better?

const [showDetails, setShowDetails] = React.useState(false);
const type = tx.type;
const Icon = tx.type == "outgoing" ? ArrowUpIcon : ArrowDownIcon;

const copy = (text: string) => {
copyToClipboard(text);
toast({ title: "Copied to clipboard." });
};

return (
<Credenza
onOpenChange={(open) => {
if (!open) {
setShowDetails(false);
}
}}
>
<CredenzaTrigger
asChild
className="p-3 mb-4 hover:bg-muted/50 data-[state=selected]:bg-muted cursor-pointer rounded-md slashed-zero"
>
<div className="flex gap-3">
<div className="flex items-center">
<div
className={cn(
"flex justify-center items-center rounded-full w-10 h-10 md:w-14 md:h-14",
type === "outgoing"
? "bg-orange-100 dark:bg-orange-950"
: "bg-green-100 dark:bg-emerald-950"
)}
>
<Icon
strokeWidth={3}
className={cn(
"w-6 h-6 md:w-8 md:h-8",
type === "outgoing"
? "text-orange-400 dark:text-amber-600 stroke-orange-400 dark:stroke-amber-600"
: "text-green-500 dark:text-emerald-500 stroke-green-400 dark:stroke-emerald-500"
)}
/>
</div>
</div>
<div className="overflow-hidden mr-3">
<div className="flex items-center gap-2 truncate dark:text-white">
<p className="text-lg md:text-xl font-semibold">
{type == "incoming" ? "Received" : "Sent"}
</p>
<p className="text-sm md:text-base truncate text-muted-foreground">
{dayjs(tx.settled_at * 1000).fromNow()}
</p>
</div>
<p className="text-sm md:text-base text-muted-foreground">
{tx.description || "Lightning invoice"}
</p>
</div>
<div className="flex ml-auto text-right space-x-3 shrink-0 dark:text-white">
<div className="flex items-center gap-2 text-xl">
<p
className={cn(
"font-semibold",
type == "incoming" && "text-green-600 dark:color-green-400"
)}
>
{type == "outgoing" ? "-" : "+"} {Math.floor(tx.amount / 1000)}
</p>
<p className="text-muted-foreground">sats</p>

{/* {!!tx.totalAmountFiat && (
<p className="text-xs text-gray-400 dark:text-neutral-600">
~{tx.totalAmountFiat}
</p>
)} */}
</div>
</div>
</div>
</CredenzaTrigger>
<CredenzaContent className="slashed-zero">
<CredenzaHeader>
<CredenzaTitle>
{`${type == "outgoing" ? "Sent" : "Received"} Bitcoin`}
</CredenzaTitle>
</CredenzaHeader>
<CredenzaBody>
<div className="flex items-center mt-6">
<div
className={cn(
"flex justify-center items-center rounded-full w-10 h-10 md:w-14 md:h-14",
type === "outgoing"
? "bg-orange-100 dark:bg-orange-950"
: "bg-green-100 dark:bg-emerald-950"
)}
>
<Icon
strokeWidth={3}
className={cn(
"w-6 h-6 md:w-8 md:h-8",
type === "outgoing"
? "text-orange-400 dark:text-amber-600 stroke-orange-400 dark:stroke-amber-600"
: "text-green-500 dark:text-emerald-500 stroke-green-400 dark:stroke-emerald-500"
)}
/>
</div>
<div className="ml-4">
<p className="text-xl md:text-2xl font-semibold">
{Math.floor(tx.amount / 1000)}{" "}
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
{Math.floor(tx.amount / 1000) == 1 ? "sat" : "sats"}
</p>
{/* <p className="text-sm md:text-base text-gray-500">
Fiat Amount
</p> */}
</div>
</div>
<div className="mt-8">
<p className="dark:text-white">Date & Time</p>
<p className="text-muted-foreground">
{dayjs(tx.settled_at * 1000).toString()}
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
</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)}{" "}
{Math.floor(tx.fees_paid / 1000) == 1 ? "sat" : "sats"}
</p>
</div>
)}
{tx.description && (
<div className="mt-6">
<p className="dark:text-white">Description</p>
<p className="text-muted-foreground">{tx.description}</p>
</div>
)}
</CredenzaBody>
<CredenzaFooter className="!justify-start mt-4 !flex-col">
<div
className="flex items-center gap-2 cursor-pointer"
onClick={() => setShowDetails(!showDetails)}
>
Details
{showDetails ? (
<ChevronUp className="w-4 h-4" />
) : (
<ChevronDown className="w-4 h-4" />
)}
</div>
{showDetails && (
<>
<div className="mt-6 !ml-0">
<p className="dark:text-white">Preimage</p>
<div className="flex items-center gap-4">
<p className="text-muted-foreground break-all">
{tx.preimage}
</p>
<CopyIcon
className="cursor-pointer text-muted-foreground w-6 h-6"
onClick={() => {
copy(tx.preimage);
}}
/>
</div>
</div>
<div className="mt-6 !ml-0">
<p className="dark:text-white">Hash</p>
<div className="flex items-center gap-4">
<p className="text-muted-foreground break-all">
{tx.payment_hash}
</p>
<CopyIcon
className="cursor-pointer text-muted-foreground w-6 h-6"
onClick={() => {
copy(tx.payment_hash);
}}
/>
</div>
</div>
</>
)}
</CredenzaFooter>
</CredenzaContent>
</Credenza>
);
}

export default TransactionItem;
81 changes: 3 additions & 78 deletions frontend/src/components/TransactionsList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import dayjs from "dayjs";
import { ArrowDownIcon, ArrowUpIcon, Drum } from "lucide-react";
import { Drum } from "lucide-react";
import EmptyState from "src/components/EmptyState";

import Loading from "src/components/Loading";
import TransactionItem from "src/components/TransactionItem";
import { useTransactions } from "src/hooks/useTransactions";

function TransactionsList() {
Expand All @@ -25,82 +24,8 @@ function TransactionsList() {
) : (
<>
{transactions?.map((tx, i) => {
const type = tx.type;

return (
<div
key={`tx-${i}`}
className="p-3 mb-4 rounded-md"
// TODO: Add modal onclick to show payment details
>
<div className="flex gap-3">
<div className="flex items-center">
{type == "outgoing" ? (
<div
className={
"flex justify-center items-center bg-orange-100 dark:bg-orange-950 rounded-full w-10 h-10 md:w-14 md:h-14"
}
>
<ArrowUpIcon
strokeWidth={3}
className="w-6 h-6 md:w-8 md:h-8 text-orange-400 dark:text-amber-600 stroke-orange-400 dark:stroke-amber-600"
/>
</div>
) : (
<div className="flex justify-center items-center bg-green-100 dark:bg-emerald-950 rounded-full w-10 h-10 md:w-14 md:h-14">
<ArrowDownIcon
strokeWidth={3}
className="w-6 h-6 md:w-8 md:h-8 text-green-500 dark:text-emerald-500 stroke-green-400 dark:stroke-emerald-500"
/>
</div>
)}
</div>
<div className="overflow-hidden mr-3">
<div className="flex items-center gap-2 truncate dark:text-white">
<p className="text-lg md:text-xl font-semibold">
{type == "incoming" ? "Received" : "Sent"}
</p>
<p className="text-sm md:text-base truncate text-muted-foreground">
{dayjs(tx.settled_at * 1000).fromNow()}
</p>
</div>
<p className="text-sm md:text-base text-muted-foreground">
{tx.description || "Lightning invoice"}
</p>
</div>
<div className="flex ml-auto text-right space-x-3 shrink-0 dark:text-white">
<div className="flex items-center gap-2 text-xl">
<p
className={`font-semibold ${
type == "incoming" &&
"text-green-600 dark:color-green-400"
}`}
>
{type == "outgoing" ? "-" : "+"}{" "}
{Math.floor(tx.amount / 1000)}
</p>
<p className="text-muted-foreground">sats</p>

{/* {!!tx.totalAmountFiat && (
<p className="text-xs text-gray-400 dark:text-neutral-600">
~{tx.totalAmountFiat}
</p>
)} */}
</div>
</div>
</div>
</div>
);
return <TransactionItem key={`tx-${i}`} tx={tx} />;
})}
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
{/* {transaction && (
<TransactionModal
transaction={transaction}
isOpen={modalOpen}
onClose={() => {
setModalOpen(false);
}}
/>
)} */}
</>
)}
</div>
Expand Down
Loading
Loading