api client refactor
This commit is contained in:
36
apps/website/lib/view-models/WalletViewModel.ts
Normal file
36
apps/website/lib/view-models/WalletViewModel.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { WalletDto, WalletTransactionDto } from '../dtos';
|
||||
import { WalletTransactionViewModel } from './WalletTransactionViewModel';
|
||||
|
||||
export class WalletViewModel implements WalletDto {
|
||||
driverId: string;
|
||||
balance: number;
|
||||
currency: string;
|
||||
transactions: WalletTransactionViewModel[];
|
||||
|
||||
constructor(dto: WalletDto & { transactions: WalletTransactionDto[] }) {
|
||||
this.driverId = dto.driverId;
|
||||
this.balance = dto.balance;
|
||||
this.currency = dto.currency;
|
||||
this.transactions = dto.transactions.map(t => new WalletTransactionViewModel(t));
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user