Files
gridpilot.gg/apps/website/lib/view-models/WalletTransactionViewModel.ts
2026-01-23 15:30:23 +01:00

51 lines
1.7 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import { CurrencyDisplay } from "../display-objects/CurrencyDisplay";
import { DateDisplay } from "../display-objects/DateDisplay";
import { TransactionTypeDisplay } from "../display-objects/TransactionTypeDisplay";
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}${CurrencyDisplay.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 TransactionTypeDisplay.format(this.type);
}
/** UI-specific: Formatted date */
get formattedDate(): string {
return DateDisplay.formatShort(this.date);
}
/** UI-specific: Is incoming */
get isIncoming(): boolean {
return this.amount > 0;
}
}