Files
gridpilot.gg/apps/website/lib/view-models/WalletTransactionViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

65 lines
1.7 KiB
TypeScript

// Export the DTO type that WalletTransactionViewModel expects
export type FullTransactionDto = {
id: string;
type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize' | 'deposit';
description: string;
amount: number;
fee: number;
netAmount: number;
date: Date;
status: 'completed' | 'pending' | 'failed';
reference?: string;
};
import { ViewModel } from "../contracts/view-models/ViewModel";
export class WalletTransactionViewModel extends ViewModel {
id: string;
type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize' | 'deposit';
description: string;
amount: number;
fee: number;
netAmount: number;
date: Date;
status: 'completed' | 'pending' | 'failed';
reference?: string;
constructor(dto: FullTransactionDto) {
super();
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;
}
}