Files
gridpilot.gg/apps/website/lib/view-models/WalletTransactionViewModel.ts
2025-12-19 21:58:03 +01:00

59 lines
1.5 KiB
TypeScript

export class WalletTransactionViewModel {
id: string;
type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize';
description: string;
amount: number;
fee: number;
netAmount: number;
date: Date;
status: 'completed' | 'pending' | 'failed';
reference?: string;
constructor(dto: {
id: string;
type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize';
description: string;
amount: number;
fee: number;
netAmount: number;
date: Date;
status: 'completed' | 'pending' | 'failed';
reference?: string;
}) {
this.id = dto.id;
this.type = dto.type;
this.description = dto.description;
this.amount = dto.amount;
this.fee = dto.fee;
this.netAmount = dto.netAmount;
this.date = dto.date;
this.status = dto.status;
this.reference = dto.reference;
}
/** UI-specific: Formatted amount with sign */
get formattedAmount(): string {
const sign = this.amount > 0 ? '+' : '';
return `${sign}$${Math.abs(this.amount).toFixed(2)}`;
}
/** UI-specific: Amount color */
get amountColor(): string {
return this.amount > 0 ? 'green' : 'red';
}
/** UI-specific: Type display */
get typeDisplay(): string {
return this.type.charAt(0).toUpperCase() + this.type.slice(1);
}
/** UI-specific: Formatted date */
get formattedDate(): string {
return this.date.toLocaleDateString();
}
/** UI-specific: Is incoming */
get isIncoming(): boolean {
return this.amount > 0;
}
}