Files
gridpilot.gg/apps/website/lib/view-models/WalletViewModel.ts
2025-12-24 14:01:52 +01:00

49 lines
1.4 KiB
TypeScript

import { WalletDTO } from '../types/generated/WalletDTO';
import { FullTransactionDto, WalletTransactionViewModel } from './WalletTransactionViewModel';
export class WalletViewModel {
id: string;
leagueId: string;
balance: number;
totalRevenue: number;
totalPlatformFees: number;
totalWithdrawn: number;
createdAt: string;
currency: string;
constructor(dto: WalletDTO & { transactions?: any[] }) {
this.id = dto.id;
this.leagueId = dto.leagueId;
this.balance = dto.balance;
this.totalRevenue = dto.totalRevenue;
this.totalPlatformFees = dto.totalPlatformFees;
this.totalWithdrawn = dto.totalWithdrawn;
this.createdAt = dto.createdAt;
this.currency = dto.currency;
// Map transactions if provided
this.transactions = dto.transactions?.map(t => new WalletTransactionViewModel(t)) || [];
}
transactions: WalletTransactionViewModel[] = [];
/** UI-specific: Formatted balance */
get formattedBalance(): string {
return `${this.currency} ${this.balance.toFixed(2)}`;
}
/** 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;
}
}