From 6f6580cc2f89f7c0191cb7ad03b875df519f069d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Wed, 19 Jun 2024 00:25:34 +0200 Subject: [PATCH] feat: badges --- .../connections/AlbyConnectionCard.tsx | 14 ++++-- .../src/components/connections/AppCard.tsx | 2 +- .../connections/AppCardConnectionInfo.tsx | 49 +++++-------------- .../components/connections/AppCardNotice.tsx | 43 ++++++++-------- frontend/src/screens/apps/AppList.tsx | 2 +- 5 files changed, 48 insertions(+), 62 deletions(-) diff --git a/frontend/src/components/connections/AlbyConnectionCard.tsx b/frontend/src/components/connections/AlbyConnectionCard.tsx index 3fd02970..164e6f89 100644 --- a/frontend/src/components/connections/AlbyConnectionCard.tsx +++ b/frontend/src/components/connections/AlbyConnectionCard.tsx @@ -1,10 +1,12 @@ import { CheckCircle2, CircleX, + EditIcon, ExternalLinkIcon, Link2Icon, ZapIcon, } from "lucide-react"; +import { Link } from "react-router-dom"; import ExternalLink from "src/components/ExternalLink"; import Loading from "src/components/Loading"; import UserAvatar from "src/components/UserAvatar"; @@ -42,14 +44,14 @@ function AlbyConnectionCard({ connection }: { connection?: App }) { - -
+ +
{albyMe?.name}
-
+
{albyMe?.lightning_address}
@@ -91,6 +93,12 @@ function AlbyConnectionCard({ connection }: { connection?: App }) {
+ + + {connection && }
diff --git a/frontend/src/components/connections/AppCard.tsx b/frontend/src/components/connections/AppCard.tsx index c6441307..7276e323 100644 --- a/frontend/src/components/connections/AppCard.tsx +++ b/frontend/src/components/connections/AppCard.tsx @@ -23,7 +23,7 @@ export default function AppCard({ app }: Props) { return ( <> - + diff --git a/frontend/src/components/connections/AppCardConnectionInfo.tsx b/frontend/src/components/connections/AppCardConnectionInfo.tsx index e2736984..7026ab59 100644 --- a/frontend/src/components/connections/AppCardConnectionInfo.tsx +++ b/frontend/src/components/connections/AppCardConnectionInfo.tsx @@ -1,8 +1,5 @@ -import dayjs from "dayjs"; -import { Edit } from "lucide-react"; -import { Link } from "react-router-dom"; -import { Button } from "src/components/ui/button"; import { Progress } from "src/components/ui/progress"; +import { formatAmount } from "src/lib/utils"; import { App } from "src/types"; type AppCardConnectionInfoProps = { @@ -18,19 +15,10 @@ export function AppCardConnectionInfo({ <>
-

- You've spent -

-

- {new Intl.NumberFormat().format(connection.budgetUsage)} sats -

-
-
- {" "}

Left in budget

-

+

{new Intl.NumberFormat().format( connection.maxAmount - connection.budgetUsage )}{" "} @@ -42,30 +30,19 @@ export function AppCardConnectionInfo({ className="h-4" value={(connection.budgetUsage * 100) / connection.maxAmount} /> -

- {connection.maxAmount > 0 && - connection.budgetRenewal !== "never" ? ( - <>Renews {connection.budgetRenewal} - ) : ( -
// force edit button to right hand side - )} -
- - - +
+
+ {connection.maxAmount && ( + <>{formatAmount(connection.maxAmount * 1000)} sats + )}
-
- {connection.lastEventAt && ( -
-
-
Last used: 
-
{dayjs(connection.lastEventAt).fromNow()}
-
+
+ {connection.maxAmount > 0 && + connection.budgetRenewal !== "never" && ( + <>Renews {connection.budgetRenewal} + )}
- )} +
)} diff --git a/frontend/src/components/connections/AppCardNotice.tsx b/frontend/src/components/connections/AppCardNotice.tsx index f3778c47..eb4f0aac 100644 --- a/frontend/src/components/connections/AppCardNotice.tsx +++ b/frontend/src/components/connections/AppCardNotice.tsx @@ -1,7 +1,8 @@ -import { ExclamationTriangleIcon } from "@radix-ui/react-icons"; import dayjs from "dayjs"; +import isBetween from "dayjs/plugin/isBetween"; // Add this line +import { CalendarClock } from "lucide-react"; import { Link } from "react-router-dom"; -import { Button } from "src/components/ui/button"; +import { Badge } from "src/components/ui/badge"; import { Tooltip, TooltipContent, @@ -10,47 +11,47 @@ import { } from "src/components/ui/tooltip"; import { App } from "src/types"; +dayjs.extend(isBetween); // Extend dayjs with the isBetween plugin + type AppCardNoticeProps = { app: App; }; -const ONE_WEEK_IN_SECONDS = 8 * 24 * 60 * 60 * 1000; - export function AppCardNotice({ app }: AppCardNoticeProps) { + const now = dayjs(); + const expiresAt = dayjs(app.expiresAt); + const isExpired = expiresAt.isBefore(now); + const expiresSoon = expiresAt.isBetween(now, now.add(7, "days")); + return (
{app.expiresAt ? ( - new Date(app.expiresAt).getTime() < new Date().getTime() ? ( + isExpired ? ( - + + + Expired + - - Expired {dayjs(app.expiresAt).fromNow()} - + Expired {expiresAt.fromNow()} - ) : new Date(app.expiresAt).getTime() - ONE_WEEK_IN_SECONDS < - new Date().getTime() ? ( + ) : expiresSoon ? ( - + + + Expires Soon + - - Expires {dayjs(app.expiresAt).fromNow()} - + Expires {expiresAt.fromNow()} ) : null diff --git a/frontend/src/screens/apps/AppList.tsx b/frontend/src/screens/apps/AppList.tsx index 37ab383f..8d417669 100644 --- a/frontend/src/screens/apps/AppList.tsx +++ b/frontend/src/screens/apps/AppList.tsx @@ -52,7 +52,7 @@ function AppList() { )} {otherApps.length > 0 && ( -
+
{otherApps.map((app, index) => ( ))}