view data fixes
This commit is contained in:
@@ -1,63 +1,49 @@
|
||||
import { WalletTransactionViewModel } from './WalletTransactionViewModel';
|
||||
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import { CurrencyDisplay } from "../display-objects/CurrencyDisplay";
|
||||
import type { LeagueWalletViewData } from "../view-data/LeagueWalletViewData";
|
||||
|
||||
export class LeagueWalletViewModel extends ViewModel {
|
||||
balance: number;
|
||||
currency: string;
|
||||
totalRevenue: number;
|
||||
totalFees: number;
|
||||
totalWithdrawals: number;
|
||||
pendingPayouts: number;
|
||||
transactions: WalletTransactionViewModel[];
|
||||
canWithdraw: boolean;
|
||||
withdrawalBlockReason?: string;
|
||||
private readonly data: LeagueWalletViewData;
|
||||
readonly transactions: WalletTransactionViewModel[];
|
||||
|
||||
constructor(dto: {
|
||||
balance: number;
|
||||
currency: string;
|
||||
totalRevenue: number;
|
||||
totalFees: number;
|
||||
totalWithdrawals: number;
|
||||
pendingPayouts: number;
|
||||
transactions: WalletTransactionViewModel[];
|
||||
canWithdraw: boolean;
|
||||
withdrawalBlockReason?: string;
|
||||
}) {
|
||||
constructor(data: LeagueWalletViewData) {
|
||||
super();
|
||||
this.balance = dto.balance;
|
||||
this.currency = dto.currency;
|
||||
this.totalRevenue = dto.totalRevenue;
|
||||
this.totalFees = dto.totalFees;
|
||||
this.totalWithdrawals = dto.totalWithdrawals;
|
||||
this.pendingPayouts = dto.pendingPayouts;
|
||||
this.transactions = dto.transactions;
|
||||
this.canWithdraw = dto.canWithdraw;
|
||||
this.withdrawalBlockReason = dto.withdrawalBlockReason;
|
||||
this.data = data;
|
||||
this.transactions = data.transactions.map(t => new WalletTransactionViewModel(t));
|
||||
}
|
||||
|
||||
get balance(): number { return this.data.balance; }
|
||||
get currency(): string { return this.data.currency; }
|
||||
get totalRevenue(): number { return this.data.totalRevenue; }
|
||||
get totalFees(): number { return this.data.totalFees; }
|
||||
get totalWithdrawals(): number { return this.data.totalWithdrawals; }
|
||||
get pendingPayouts(): number { return this.data.pendingPayouts; }
|
||||
get canWithdraw(): boolean { return this.data.canWithdraw; }
|
||||
get withdrawalBlockReason(): string | undefined { return this.data.withdrawalBlockReason; }
|
||||
|
||||
/** UI-specific: Formatted balance */
|
||||
get formattedBalance(): string {
|
||||
return `$${this.balance.toFixed(2)}`;
|
||||
return CurrencyDisplay.format(this.balance, this.currency);
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted total revenue */
|
||||
get formattedTotalRevenue(): string {
|
||||
return `$${this.totalRevenue.toFixed(2)}`;
|
||||
return CurrencyDisplay.format(this.totalRevenue, this.currency);
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted total fees */
|
||||
get formattedTotalFees(): string {
|
||||
return `$${this.totalFees.toFixed(2)}`;
|
||||
return CurrencyDisplay.format(this.totalFees, this.currency);
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted pending payouts */
|
||||
get formattedPendingPayouts(): string {
|
||||
return `$${this.pendingPayouts.toFixed(2)}`;
|
||||
return CurrencyDisplay.format(this.pendingPayouts, this.currency);
|
||||
}
|
||||
|
||||
/** UI-specific: Filtered transactions by type */
|
||||
getFilteredTransactions(type: 'all' | 'sponsorship' | 'membership' | 'withdrawal' | 'prize'): WalletTransactionViewModel[] {
|
||||
return type === 'all' ? this.transactions : this.transactions.filter(t => t.type === type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user