Files
gridpilot.gg/apps/website/lib/view-models/WalletViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

51 lines
1.5 KiB
TypeScript

import { WalletDTO } from '@/lib/types/generated/WalletDTO';
import { WalletTransactionViewModel } from './WalletTransactionViewModel';
import { ViewModel } from "../contracts/view-models/ViewModel";
export class WalletViewModel extends ViewModel {
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;
}
}