Skip to content

Commit 71d2336

Browse files
authored
feat: requested UI and UX improvements (#524)
1 parent 849c36f commit 71d2336

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed

platforms/eCurrency-api/src/controllers/LedgerController.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class LedgerController {
4444
id: b.currency.id,
4545
name: b.currency.name,
4646
ename: b.currency.ename,
47+
allowNegative: b.currency.allowNegative,
4748
},
4849
balance: b.balance,
4950
})));
@@ -353,5 +354,21 @@ export class LedgerController {
353354
res.status(500).json({ error: "Internal server error" });
354355
}
355356
};
357+
358+
getTotalSupply = async (req: Request, res: Response) => {
359+
try {
360+
if (!req.user) {
361+
return res.status(401).json({ error: "Authentication required" });
362+
}
363+
364+
const { currencyId } = req.params;
365+
const totalSupply = await this.ledgerService.getTotalSupply(currencyId);
366+
367+
res.json({ currencyId, totalSupply });
368+
} catch (error) {
369+
console.error("Error getting total supply:", error);
370+
res.status(500).json({ error: "Internal server error" });
371+
}
372+
};
356373
}
357374

platforms/eCurrency-api/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ app.get("/api/ledger/history", authGuard, ledgerController.getHistory);
121121
app.get("/api/ledger/history/:currencyId", authGuard, ledgerController.getHistory);
122122
app.get("/api/ledger/transaction/:id", authGuard, ledgerController.getTransactionById);
123123
app.get("/api/ledger/account-details/:currencyId", authGuard, ledgerController.getAccountDetails);
124+
app.get("/api/ledger/total-supply/:currencyId", authGuard, ledgerController.getTotalSupply);
124125
app.post("/api/ledger/initialize", authGuard, ledgerController.initializeAccount);
125126

126127
// Start server

platforms/eCurrency-api/src/services/LedgerService.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,5 +293,32 @@ export class LedgerService {
293293
return await groupRepository.findOne({ where: { id: accountId } });
294294
}
295295
}
296+
297+
/**
298+
* Get total supply for a currency by summing all account balances
299+
*/
300+
async getTotalSupply(currencyId: string): Promise<number> {
301+
// Get all unique account combinations for this currency
302+
const distinctAccounts = await this.ledgerRepository
303+
.createQueryBuilder("ledger")
304+
.select("ledger.accountId", "accountId")
305+
.addSelect("ledger.accountType", "accountType")
306+
.where("ledger.currencyId = :currencyId", { currencyId })
307+
.distinct(true)
308+
.getRawMany();
309+
310+
// Sum all balances
311+
let totalSupply = 0;
312+
for (const account of distinctAccounts) {
313+
const balance = await this.getAccountBalance(
314+
currencyId,
315+
account.accountId,
316+
account.accountType as AccountType
317+
);
318+
totalSupply += Number(balance);
319+
}
320+
321+
return totalSupply;
322+
}
296323
}
297324

platforms/eCurrency/client/src/components/user-menu-dropdown.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export default function UserMenuDropdown({ accountContext, onAccountContextChang
2525
const adminGroups = groups?.filter((g: any) => g.isAdmin) || [];
2626
const hasAdminGroups = adminGroups.length > 0;
2727

28-
const currentLabel = accountContext?.type === "user"
29-
? "My Account"
30-
: adminGroups.find((g: any) => g.id === accountContext?.id)?.name || "My Account";
28+
const currentAccountName = accountContext?.type === "user"
29+
? (user?.name || user?.ename || "Personal Account")
30+
: (groups?.find((g: any) => g.id === accountContext?.id)?.name || "Group");
3131

3232
if (!user) {
3333
return null;
@@ -39,7 +39,7 @@ export default function UserMenuDropdown({ accountContext, onAccountContextChang
3939
onClick={() => setIsOpen(!isOpen)}
4040
className="flex items-center gap-2 px-4 py-2 border rounded-lg hover:bg-gray-50"
4141
>
42-
<span className="text-sm font-medium">{user?.name || user?.ename || "Account"}</span>
42+
<span className="text-sm font-medium">Currently managing: {currentAccountName}</span>
4343
<ChevronDown className={`h-4 w-4 transition-transform ${isOpen ? "rotate-180" : ""}`} />
4444
</button>
4545

platforms/eCurrency/client/src/pages/currency-detail.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ export default function CurrencyDetail() {
104104
},
105105
});
106106

107+
const { data: totalSupplyData, isLoading: totalSupplyLoading } = useQuery({
108+
queryKey: ["totalSupply", currencyId],
109+
queryFn: async () => {
110+
const response = await apiClient.get(`/api/ledger/total-supply/${currencyId}`);
111+
return response.data;
112+
},
113+
enabled: !!currencyId,
114+
});
115+
116+
const totalSupply = totalSupplyData?.totalSupply ?? 0;
117+
107118
const { data: transactions, isLoading: transactionsLoading } = useQuery({
108119
queryKey: ["history", currencyId, accountContext, transactionOffset],
109120
queryFn: async () => {
@@ -198,6 +209,27 @@ export default function CurrencyDetail() {
198209
: "0.00"}
199210
</p>
200211
</div>
212+
<div>
213+
<h3 className="text-sm font-medium text-muted-foreground mb-1">Negative Balance Allowed</h3>
214+
<p className={`text-lg font-medium ${
215+
currency.allowNegative ? "text-yellow-600" : "text-green-600"
216+
}`}>
217+
{currency.allowNegative ? "Yes" : "No"}
218+
</p>
219+
</div>
220+
<div>
221+
<h3 className="text-sm font-medium text-muted-foreground mb-1">Total Currency Supply</h3>
222+
<p className="text-lg font-semibold">
223+
{totalSupplyLoading ? (
224+
<span className="text-muted-foreground">Loading...</span>
225+
) : (
226+
Number(totalSupply).toLocaleString(undefined, {
227+
minimumFractionDigits: 2,
228+
maximumFractionDigits: 2,
229+
})
230+
)}
231+
</p>
232+
</div>
201233
</div>
202234
</div>
203235
)}

platforms/eCurrency/client/src/pages/dashboard.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ export default function Dashboard() {
205205
})}
206206
</div>
207207
<div className="text-xs text-white/80 mt-1">{formatEName(balance.currency.ename)}</div>
208+
{balance.currency.allowNegative !== undefined && (
209+
<div className="text-xs px-2 py-0.5 rounded bg-white/20 text-white/90 mt-1 inline-block">
210+
{balance.currency.allowNegative ? "Negative Allowed" : "No Negative"}
211+
</div>
212+
)}
208213
</div>
209214
))}
210215
</div>

0 commit comments

Comments
 (0)