Files
gridpilot.gg/apps/website/lib/view-models/LeagueWalletViewModel.ts
2026-01-23 15:30:23 +01:00

50 lines
2.0 KiB
TypeScript

import { WalletTransactionViewModel } from './WalletTransactionViewModel';
import { ViewModel } from "../contracts/view-models/ViewModel";
import { CurrencyDisplay } from "../display-objects/CurrencyDisplay";
import type { LeagueWalletViewData } from "../view-data/LeagueWalletViewData";
export class LeagueWalletViewModel extends ViewModel {
private readonly data: LeagueWalletViewData;
readonly transactions: WalletTransactionViewModel[];
constructor(data: LeagueWalletViewData) {
super();
this.data = data;
this.transactions = data.transactions.map(t => new WalletTransactionViewModel(t));
}
get balance(): number { return this.data.balance; }
get currency(): string { return this.data.currency; }
get totalRevenue(): number { return this.data.totalRevenue; }
get totalFees(): number { return this.data.totalFees; }
get totalWithdrawals(): number { return this.data.totalWithdrawals; }
get pendingPayouts(): number { return this.data.pendingPayouts; }
get canWithdraw(): boolean { return this.data.canWithdraw; }
get withdrawalBlockReason(): string | undefined { return this.data.withdrawalBlockReason; }
/** UI-specific: Formatted balance */
get formattedBalance(): string {
return CurrencyDisplay.format(this.balance, this.currency);
}
/** UI-specific: Formatted total revenue */
get formattedTotalRevenue(): string {
return CurrencyDisplay.format(this.totalRevenue, this.currency);
}
/** UI-specific: Formatted total fees */
get formattedTotalFees(): string {
return CurrencyDisplay.format(this.totalFees, this.currency);
}
/** UI-specific: Formatted pending payouts */
get formattedPendingPayouts(): string {
return CurrencyDisplay.format(this.pendingPayouts, this.currency);
}
/** UI-specific: Filtered transactions by type */
getFilteredTransactions(type: 'all' | 'sponsorship' | 'membership' | 'withdrawal' | 'prize'): WalletTransactionViewModel[] {
return type === 'all' ? this.transactions : this.transactions.filter(t => t.type === type);
}
}