49 lines
1.4 KiB
TypeScript
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?: FullTransactionDto[] }) {
|
|
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;
|
|
}
|
|
} |