From 62cd515a9e3304da98b2ecac8ee859131c367b07 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 19 Sep 2025 18:03:46 -0500 Subject: [PATCH] Improve credits dialog --- src/components/CreditsDialog.test.tsx | 10 +- src/components/CreditsDialog.tsx | 259 +++++++++++++------------- 2 files changed, 138 insertions(+), 131 deletions(-) diff --git a/src/components/CreditsDialog.test.tsx b/src/components/CreditsDialog.test.tsx index dd69b9a4..c5c4e74c 100644 --- a/src/components/CreditsDialog.test.tsx +++ b/src/components/CreditsDialog.test.tsx @@ -25,9 +25,9 @@ describe('CreditsDialog', () => { ); - expect(screen.getByText('Credits - test-provider')).toBeInTheDocument(); - expect(screen.getByText('Add Credits')).toBeInTheDocument(); - expect(screen.getByText('Transaction History')).toBeInTheDocument(); + expect(screen.getByText('Credits')).toBeInTheDocument(); + expect(screen.getByText('Amount (USD)')).toBeInTheDocument(); + expect(screen.getByText('Recent Transactions')).toBeInTheDocument(); }); it('does not render when closed', () => { @@ -42,7 +42,7 @@ describe('CreditsDialog', () => { ); - expect(screen.queryByText('Credits - test-provider')).not.toBeInTheDocument(); + expect(screen.queryByText('Credits')).not.toBeInTheDocument(); }); it('shows payment method options', () => { @@ -120,6 +120,6 @@ describe('CreditsDialog', () => { ); - expect(screen.getByText('Credits - test-provider')).toBeInTheDocument(); + expect(screen.getByText('Credits')).toBeInTheDocument(); }); }); \ No newline at end of file diff --git a/src/components/CreditsDialog.tsx b/src/components/CreditsDialog.tsx index 2eedbff5..7d639572 100644 --- a/src/components/CreditsDialog.tsx +++ b/src/components/CreditsDialog.tsx @@ -127,10 +127,10 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr return; } - if (amount < 5) { + if (amount <= 0) { toast({ - title: 'Minimum amount', - description: 'Minimum credit amount is $5.00', + title: 'Invalid amount', + description: 'Please enter a valid amount.', variant: 'destructive', }); return; @@ -158,13 +158,27 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr }; const formatDate = (timestamp: number) => { - return new Intl.DateTimeFormat('en-US', { - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', - }).format(new Date(timestamp * 1000)); + const date = new Date(timestamp * 1000); + const now = new Date(); + const diffDays = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60 * 24)); + + if (diffDays === 0) { + return new Intl.DateTimeFormat('en-US', { + hour: '2-digit', + minute: '2-digit', + }).format(date); + } else if (diffDays === 1) { + return 'Yesterday'; + } else if (diffDays < 7) { + return new Intl.DateTimeFormat('en-US', { + weekday: 'short', + }).format(date); + } else { + return new Intl.DateTimeFormat('en-US', { + month: 'short', + day: 'numeric', + }).format(date); + } }; const getStatusIcon = (status: Payment['status']) => { @@ -197,154 +211,141 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr return ( - - - + + + - Credits - {providerId} + Credits -
+
{/* Add Credits Form */}
-

Add Credits

- -
-
- -
- setAmount(Number(e.target.value))} - placeholder="Enter amount" - className="flex-1" - /> -
- {PRESET_AMOUNTS.map((preset) => ( - - ))} -
+
+ +
+ setAmount(Number(e.target.value))} + placeholder="Enter amount" + className="text-center text-lg font-medium" + /> +
+ {PRESET_AMOUNTS.map((preset) => ( + + ))}
- {amount > 0 && amount < 5 && ( -

Minimum amount is $5.00

- )} +
- -
- - -
- - - - {!user && ( -

- Please log in to purchase credits -

- )}
+ +
+ + +
+ + + + {!user && ( +

+ Please log in to purchase credits +

+ )}
{/* Transaction History */}
-

Transaction History

+

Recent Transactions

{isLoadingPayments ? (
{Array.from({ length: 3 }).map((_, i) => ( -
-
+
+
-
- - -
-
-
- - + +
+
))}
) : !payments || payments.length === 0 ? (
- -

No transactions yet

-

Your payment history will appear here

+ +

No transactions yet

+

Your payment history will appear here

) : ( -
- {payments.map((payment) => ( +
+ {payments.slice(0, 5).map((payment) => (
-
- {getStatusIcon(payment.status)} -
-
- {payment.description} - - {payment.status} - -
-

- {formatDate(payment.created_at)} - {payment.completed_at && payment.completed_at !== payment.created_at && ( - • Completed {formatDate(payment.completed_at)} - )} -

+
+
+ {getStatusIcon(payment.status)} + + {payment.method === 'stripe' ? 'Credit Card' : 'Lightning'} + + + {payment.status} + +
+
+

{formatCurrency(payment.amount)}

+ {payment.fee > 0 && ( +

+ +{formatCurrency(payment.fee)} +

+ )}
-
-

{formatCurrency(payment.amount)}

- {payment.fee > 0 && ( -

- +{formatCurrency(payment.fee)} fee -

- )} + +
+ {formatDate(payment.created_at)} {payment.status === 'pending' && payment.url && (
))} + + {payments.length > 5 && ( +

+ Showing recent 5 transactions +

+ )}
)}