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

34 lines
905 B
TypeScript

import { WalletTransactionDto } from '../dtos';
export class WalletTransactionViewModel implements WalletTransactionDto {
id: string;
type: 'deposit' | 'withdrawal';
amount: number;
description?: string;
createdAt: string;
constructor(dto: WalletTransactionDto) {
Object.assign(this, dto);
}
/** UI-specific: Formatted amount with sign */
get formattedAmount(): string {
const sign = this.type === 'deposit' ? '+' : '-';
return `${sign}$${this.amount.toFixed(2)}`;
}
/** UI-specific: Amount color */
get amountColor(): string {
return this.type === 'deposit' ? 'green' : 'red';
}
/** UI-specific: Type display */
get typeDisplay(): string {
return this.type.charAt(0).toUpperCase() + this.type.slice(1);
}
/** UI-specific: Formatted created date */
get formattedCreatedAt(): string {
return new Date(this.createdAt).toLocaleString();
}
}