Files
gridpilot.gg/apps/website/lib/view-models/WalletTransactionViewModel.ts
2026-01-24 01:07:43 +01:00

51 lines
1.7 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import { CurrencyFormatter } from "../formatters/CurrencyFormatter";
import { DateFormatter } from "../formatters/DateFormatter";
import { TransactionTypeFormatter } from "../formatters/TransactionTypeFormatter";
import type { WalletTransactionViewData } from "../view-data/WalletTransactionViewData";
export class WalletTransactionViewModel extends ViewModel {
private readonly data: WalletTransactionViewData;
constructor(data: WalletTransactionViewData) {
super();
this.data = data;
}
get id(): string { return this.data.id; }
get type(): string { return this.data.type; }
get description(): string { return this.data.description; }
get amount(): number { return this.data.amount; }
get fee(): number { return this.data.fee; }
get netAmount(): number { return this.data.netAmount; }
get date(): string { return this.data.date; }
get status(): string { return this.data.status; }
get reference(): string | undefined { return this.data.reference; }
/** UI-specific: Formatted amount with sign */
get formattedAmount(): string {
const sign = this.amount > 0 ? '+' : '';
return `${sign}${CurrencyFormatter.format(Math.abs(this.amount))}`;
}
/** UI-specific: Amount color */
get amountColor(): string {
return this.amount > 0 ? 'green' : 'red';
}
/** UI-specific: Type display */
get typeDisplay(): string {
return TransactionTypeFormatter.format(this.type);
}
/** UI-specific: Formatted date */
get formattedDate(): string {
return DateFormatter.formatShort(this.date);
}
/** UI-specific: Is incoming */
get isIncoming(): boolean {
return this.amount > 0;
}
}