Files
gridpilot.gg/apps/website/lib/view-models/WalletViewModel.ts
2025-12-17 18:01:47 +01:00

36 lines
1.1 KiB
TypeScript

import { WalletDto, WalletTransactionDto } from '../dtos';
import { WalletTransactionViewModel } from './WalletTransactionViewModel';
export class WalletViewModel implements WalletDto {
driverId: string;
balance: number;
currency: string;
transactions: WalletTransactionViewModel[];
constructor(dto: WalletDto & { transactions: WalletTransactionDto[] }) {
this.driverId = dto.driverId;
this.balance = dto.balance;
this.currency = dto.currency;
this.transactions = dto.transactions.map(t => new WalletTransactionViewModel(t));
}
/** 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;
}
}