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

47 lines
1.3 KiB
TypeScript

import { TransactionDto } from '../types/generated/TransactionDto';
export class WalletTransactionViewModel implements TransactionDto {
id: string;
walletId: string;
amount: number;
description: string;
createdAt: string;
constructor(dto: TransactionDto) {
this.id = dto.id;
this.walletId = dto.walletId;
this.amount = dto.amount;
this.description = dto.description;
this.createdAt = dto.createdAt;
}
// Note: The generated DTO doesn't have type field
// This will need to be added when the OpenAPI spec is updated
type: 'deposit' | 'withdrawal' = 'deposit';
/** 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: Amount color */
get amountColor(): string {
return this.type === 'deposit' ? 'green' : 'red';
}
/** UI-specific: Formatted created date */
get formattedCreatedAt(): string {
return new Date(this.createdAt).toLocaleString();
}
}