@@ -7,9 +7,13 @@ import { backendFetch } from '../../src/lib/backend';
77type Group = { id : string ; name : string ; currency : string } ;
88type Balance = { id : string ; userId : string ; counterpartyUserId : string ; amountCents : string } ;
99
10- function formatUsd ( cents : bigint ) : string {
11- const dollars = Number ( cents ) / 100 ;
12- return dollars . toLocaleString ( undefined , { style : 'currency' , currency : 'USD' } ) ;
10+ function formatMoney ( cents : bigint , currency : string | null ) : string {
11+ if ( ! currency ) {
12+ return '—' ;
13+ }
14+
15+ const amount = Number ( cents ) / 100 ;
16+ return amount . toLocaleString ( undefined , { style : 'currency' , currency } ) ;
1317}
1418
1519export default async function DashboardPage ( ) {
@@ -18,7 +22,9 @@ export default async function DashboardPage() {
1822 backendFetch < Group [ ] > ( '/groups' ) . catch ( ( ) => [ ] as Group [ ] ) ,
1923 ] ) ;
2024
21- const activeGroupId = groups [ 0 ] ?. id ;
25+ const activeGroup = groups [ 0 ] ?? null ;
26+ const activeGroupId = activeGroup ?. id ;
27+ const activeCurrency = activeGroup ?. currency ?? null ;
2228
2329 const [ balances , activity ] = await Promise . all ( [
2430 activeGroupId
@@ -47,21 +53,21 @@ export default async function DashboardPage() {
4753 < div className = "flex items-center justify-between" >
4854 < h2 className = "text-lg font-bold text-[var(--fs-text-primary)]" > Balance summary</ h2 >
4955 < span className = "text-[11px] font-semibold uppercase tracking-[0.12em] text-[var(--fs-text-muted)]" >
50- Updated realtime
56+ Updated on refresh
5157 </ span >
5258 </ div >
5359 < div className = "grid gap-6 md:grid-cols-3" >
54- < SummaryCard title = "Active groups" value = { groups . length } hint = "Registered ensembles" />
55- < SummaryCard
56- title = "Liabilities"
57- value = { formatUsd ( oweCents ) }
58- hint = { activeGroupId ? `Group ref: ${ activeGroupId . slice ( 0 , 8 ) } ... ` : 'No active group' }
59- />
60- < SummaryCard
61- title = "Assets"
62- value = { formatUsd ( owedToMeCents ) }
63- hint = { me ? `Linked to: ${ me . email } ` : 'Sign in to track personal totals' }
64- />
60+ < SummaryCard title = "Active groups" value = { groups . length } hint = "Registered ensembles" />
61+ < SummaryCard
62+ title = "Liabilities"
63+ value = { formatMoney ( oweCents , activeCurrency ) }
64+ hint = { activeGroupId ? `${ activeGroup ?. name } · ${ activeCurrency } ` : 'No active group selected ' }
65+ />
66+ < SummaryCard
67+ title = "Assets"
68+ value = { formatMoney ( owedToMeCents , activeCurrency ) }
69+ hint = { activeGroupId ? `Shown in ${ activeCurrency } ` : 'Select a group to see currency-specific totals' }
70+ />
6571 </ div >
6672 </ section >
6773
0 commit comments