54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { WalletDto } from '../types/generated/WalletDto';
|
|
import { WalletTransactionViewModel } from './WalletTransactionViewModel';
|
|
|
|
export class WalletViewModel implements WalletDto {
|
|
id: string;
|
|
leagueId: string;
|
|
balance: number;
|
|
totalRevenue: number;
|
|
totalPlatformFees: number;
|
|
totalWithdrawn: number;
|
|
createdAt: string;
|
|
currency: string;
|
|
|
|
constructor(dto: WalletDto & { transactions?: any[] }) {
|
|
this.id = dto.id;
|
|
this.leagueId = dto.leagueId;
|
|
this.balance = dto.balance;
|
|
this.totalRevenue = dto.totalRevenue;
|
|
this.totalPlatformFees = dto.totalPlatformFees;
|
|
this.totalWithdrawn = dto.totalWithdrawn;
|
|
this.createdAt = dto.createdAt;
|
|
this.currency = dto.currency;
|
|
|
|
// Map transactions if provided
|
|
if (dto.transactions) {
|
|
this.transactions = dto.transactions.map(t => new WalletTransactionViewModel(t));
|
|
}
|
|
}
|
|
|
|
// Note: The generated DTO doesn't have driverId or transactions
|
|
// These will need to be added when the OpenAPI spec is updated
|
|
driverId: string = '';
|
|
transactions: WalletTransactionViewModel[] = [];
|
|
|
|
/** UI-specific: Formatted balance */
|
|
get formattedBalance(): string {
|
|
return `${this.currency} ${this.balance.toFixed(2)}`;
|
|
}
|
|
|
|
/** UI-specific: Balance color */
|
|
get balanceColor(): string {
|
|
return this.balance >= 0 ? 'green' : 'red';
|
|
}
|
|
|
|
/** UI-specific: Recent transactions (last 5) */
|
|
get recentTransactions(): WalletTransactionViewModel[] {
|
|
return this.transactions.slice(0, 5);
|
|
}
|
|
|
|
/** UI-specific: Total transactions count */
|
|
get totalTransactions(): number {
|
|
return this.transactions.length;
|
|
}
|
|
} |