45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { WalletTransactionViewModel } from './WalletTransactionViewModel';
|
|
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import { CurrencyDisplay } from "../display-objects/CurrencyDisplay";
|
|
import type { WalletViewData } from "../view-data/WalletViewData";
|
|
|
|
export class WalletViewModel extends ViewModel {
|
|
private readonly data: WalletViewData;
|
|
readonly transactions: WalletTransactionViewModel[];
|
|
|
|
constructor(data: WalletViewData) {
|
|
super();
|
|
this.data = data;
|
|
this.transactions = data.transactions?.map(t => new WalletTransactionViewModel(t)) || [];
|
|
}
|
|
|
|
get id(): string { return this.data.id; }
|
|
get leagueId(): string { return this.data.leagueId; }
|
|
get balance(): number { return this.data.balance; }
|
|
get totalRevenue(): number { return this.data.totalRevenue; }
|
|
get totalPlatformFees(): number { return this.data.totalPlatformFees; }
|
|
get totalWithdrawn(): number { return this.data.totalWithdrawn; }
|
|
get createdAt(): string { return this.data.createdAt; }
|
|
get currency(): string { return this.data.currency; }
|
|
|
|
/** UI-specific: Formatted balance */
|
|
get formattedBalance(): string {
|
|
return CurrencyDisplay.format(this.balance, this.currency);
|
|
}
|
|
|
|
/** UI-specific: Balance color */
|
|
get balanceColor(): string {
|
|
return this.balance >= 0 ? 'green' : 'red';
|
|
}
|
|
|
|
/** UI-specific: Recent transactions (last 5) */
|
|
get recentTransactions(): WalletTransactionViewModel[] {
|
|
return this.transactions.slice(0, 5);
|
|
}
|
|
|
|
/** UI-specific: Total transactions count */
|
|
get totalTransactions(): number {
|
|
return this.transactions.length;
|
|
}
|
|
}
|