forked from BETAIL-BOYS/TradeFlow-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRWALoansDashboard.tsx
More file actions
318 lines (297 loc) · 9.9 KB
/
Copy pathRWALoansDashboard.tsx
File metadata and controls
318 lines (297 loc) · 9.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
"use client";
import React, { useState, useMemo } from 'react';
import { ArrowUpDown, ArrowUp, ArrowDown, FileText, Building, DollarSign, Percent, Calendar, CheckCircle, Clock, Wallet } from 'lucide-react';
// --- Types & Interfaces ---
type LoanStatus = 'Funding' | 'Active' | 'Repaid';
interface RWALoan {
id: string;
invoiceId: string;
debtor: string;
amount: number;
apy: number;
maturityDate: string; // ISO string date
status: LoanStatus;
}
interface SortConfig {
key: keyof RWALoan | null;
direction: 'asc' | 'desc';
}
// --- Mock Data ---
const MOCK_RWA_LOANS: RWALoan[] = [
{
id: 'RWA-001',
invoiceId: 'INV-8821',
debtor: 'Acme Corporation',
amount: 50000,
apy: 8.5,
maturityDate: '2026-06-15T00:00:00Z',
status: 'Active'
},
{
id: 'RWA-002',
invoiceId: 'INV-9942',
debtor: 'Global Industries Ltd',
amount: 120000,
apy: 10.2,
maturityDate: '2026-04-20T00:00:00Z',
status: 'Funding'
},
{
id: 'RWA-003',
invoiceId: 'INV-7731',
debtor: 'Tech Solutions Inc',
amount: 35000,
apy: 7.8,
maturityDate: '2026-03-10T00:00:00Z',
status: 'Repaid'
},
{
id: 'RWA-004',
invoiceId: 'INV-6521',
debtor: 'Manufacturing Co',
amount: 85000,
apy: 9.3,
maturityDate: '2026-08-30T00:00:00Z',
status: 'Active'
},
{
id: 'RWA-005',
invoiceId: 'INV-4482',
debtor: 'Retail Chain LLC',
amount: 65000,
apy: 11.5,
maturityDate: '2026-05-25T00:00:00Z',
status: 'Funding'
},
];
// --- Helper Functions ---
// Format currency with proper formatting
const formatCurrency = (amount: number): string => {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}).format(amount);
};
// Format date to readable format
const formatDate = (dateString: string): string => {
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
}).format(new Date(dateString));
};
// Returns the correct Tailwind classes based on the status
const StatusBadge = ({ status }: { status: LoanStatus }) => {
switch (status) {
case 'Repaid':
return (
<span className="inline-flex items-center gap-1 px-3 py-1 text-xs font-medium rounded-full bg-green-500/20 text-green-400 border border-green-500/30">
<CheckCircle size={12} />
Repaid
</span>
);
case 'Funding':
return (
<span className="inline-flex items-center gap-1 px-3 py-1 text-xs font-medium rounded-full bg-yellow-500/20 text-yellow-400 border border-yellow-500/30">
<Clock size={12} />
Funding
</span>
);
case 'Active':
default:
return (
<span className="inline-flex items-center gap-1 px-3 py-1 text-xs font-medium rounded-full bg-blue-500/20 text-blue-400 border border-blue-500/30">
<Wallet size={12} />
Active
</span>
);
}
};
// --- Main Component ---
export default function RWALoansDashboard() {
const [sortConfig, setSortConfig] = useState<SortConfig>({ key: null, direction: 'asc' });
const [loans] = useState<RWALoan[]>(MOCK_RWA_LOANS);
// Handle sorting
const handleSort = (key: keyof RWALoan) => {
let direction: 'asc' | 'desc' = 'asc';
if (sortConfig.key === key && sortConfig.direction === 'asc') {
direction = 'desc';
}
setSortConfig({ key, direction });
};
// Sort the loans based on the current sort configuration
const sortedLoans = useMemo(() => {
let sortableLoans = [...loans];
if (sortConfig.key) {
sortableLoans.sort((a, b) => {
const aValue = a[sortConfig.key!];
const bValue = b[sortConfig.key!];
if (aValue < bValue) {
return sortConfig.direction === 'asc' ? -1 : 1;
}
if (aValue > bValue) {
return sortConfig.direction === 'asc' ? 1 : -1;
}
return 0;
});
}
return sortableLoans;
}, [loans, sortConfig]);
// Get sort icon for column headers
const getSortIcon = (columnKey: keyof RWALoan) => {
if (sortConfig.key !== columnKey) {
return <ArrowUpDown size={14} className="text-slate-500" />;
}
return sortConfig.direction === 'asc' ?
<ArrowUp size={14} className="text-blue-400" /> :
<ArrowDown size={14} className="text-blue-400" />;
};
// Check if there are any active loans
const hasActiveLoans = loans.length > 0;
if (!hasActiveLoans) {
return (
<div className="bg-tradeflow-secondary rounded-2xl border border-tradeflow-muted overflow-hidden">
<div className="p-6 border-b border-slate-700">
<h2 className="text-xl font-semibold">Active RWA Loans</h2>
</div>
<div className="p-12">
<div className="flex flex-col items-center justify-center text-center">
<FileText size={48} className="text-slate-600 mx-auto mb-4" />
<h3 className="text-xl font-semibold text-white mb-2">No Active Loans</h3>
<p className="text-slate-400 text-sm max-w-md mb-6">
There are currently no active RWA loans in the system. Check back later or create a new invoice to get started.
</p>
<button
onClick={() => console.log('Create new invoice')}
className="bg-tradeflow-accent hover:bg-blue-600 text-white font-medium px-6 py-2 rounded-lg transition-colors"
>
Create New Invoice
</button>
</div>
</div>
</div>
);
}
return (
<div className="bg-tradeflow-secondary rounded-2xl border border-tradeflow-muted overflow-hidden">
{/* Header */}
<div className="p-6 border-b border-slate-700">
<div className="flex items-center justify-between">
<h2 className="text-xl font-semibold">Active RWA Loans</h2>
<div className="text-sm text-slate-400">
{loans.length} {loans.length === 1 ? 'loan' : 'loans'} available
</div>
</div>
</div>
{/* Table */}
<div className="overflow-x-auto">
<table className="w-full text-left">
<thead className="bg-tradeflow-dark/50 text-tradeflow-muted text-sm uppercase">
<tr>
<th className="p-4 font-semibold">
<div className="flex items-center gap-2">
<FileText size={16} />
Invoice ID
</div>
</th>
<th className="p-4 font-semibold">
<div className="flex items-center gap-2">
<Building size={16} />
Debtor
</div>
</th>
<th className="p-4 font-semibold">
<button
onClick={() => handleSort('amount')}
className="flex items-center gap-2 hover:text-blue-400 transition-colors"
>
<DollarSign size={16} />
Amount
{getSortIcon('amount')}
</button>
</th>
<th className="p-4 font-semibold">
<button
onClick={() => handleSort('apy')}
className="flex items-center gap-2 hover:text-blue-400 transition-colors"
>
<Percent size={16} />
APY
{getSortIcon('apy')}
</button>
</th>
<th className="p-4 font-semibold">
<div className="flex items-center gap-2">
<Calendar size={16} />
Maturity Date
</div>
</th>
<th className="p-4 font-semibold">
<div className="flex items-center gap-2">
Status
</div>
</th>
</tr>
</thead>
<tbody className="divide-y divide-tradeflow-muted/20">
{sortedLoans.map((loan) => (
<tr
key={loan.id}
className="hover:bg-tradeflow-muted/10 transition-colors"
>
<td className="p-4">
<div className="flex items-center gap-2">
<span className="font-mono text-sm text-blue-300">
#{loan.invoiceId.slice(-6)}
</span>
<span className="text-xs text-slate-500">
({loan.id})
</span>
</div>
</td>
<td className="p-4">
<div className="font-medium text-white">
{loan.debtor}
</div>
</td>
<td className="p-4">
<div className="font-bold text-lg text-white">
{formatCurrency(loan.amount)}
</div>
</td>
<td className="p-4">
<div className="font-medium text-green-400">
{loan.apy.toFixed(2)}%
</div>
</td>
<td className="p-4">
<div className="text-sm text-slate-300">
{formatDate(loan.maturityDate)}
</div>
</td>
<td className="p-4">
<StatusBadge status={loan.status} />
</td>
</tr>
))}
</tbody>
</table>
</div>
{/* Footer */}
<div className="p-4 border-t border-tradeflow-muted/20 bg-tradeflow-dark/30">
<div className="flex items-center justify-between text-sm text-slate-400">
<div>
Showing {sortedLoans.length} of {loans.length} loans
</div>
<div>
Total Value: {formatCurrency(loans.reduce((sum, loan) => sum + loan.amount, 0))}
</div>
</div>
</div>
</div>
);
}
// Inconsequential change for repo health
// Maintenance: minor update