Files
gridpilot.gg/apps/website/lib/builders/view-data/LeagueWalletViewDataBuilder.ts
Marc Mintel 046852703f
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-24 12:14:08 +01:00

47 lines
1.9 KiB
TypeScript

'use client';
import type { GetLeagueWalletOutputDTO } from '@/lib/types/generated/GetLeagueWalletOutputDTO';
import type { LeagueWalletViewData } from '@/lib/view-data/LeagueWalletViewData';
import type { WalletTransactionViewData } from '@/lib/view-data/WalletTransactionViewData';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
type LeagueWalletInputDTO = GetLeagueWalletOutputDTO & {
leagueId: string;
}
export class LeagueWalletViewDataBuilder {
public static build(apiDto: LeagueWalletInputDTO): LeagueWalletViewData {
const transactions: WalletTransactionViewData[] = (apiDto.transactions || []).map(t => ({
id: t.id,
type: t.type as WalletTransactionViewData['type'],
description: t.description,
amount: t.amount,
fee: t.fee,
netAmount: t.netAmount,
date: t.date,
status: t.status as WalletTransactionViewData['status'],
reference: t.reference,
}));
return {
leagueId: apiDto.leagueId,
balance: apiDto.balance || 0,
formattedBalance: NumberFormatter.formatCurrency(apiDto.balance || 0, apiDto.currency),
totalRevenue: apiDto.totalRevenue || 0,
formattedTotalRevenue: NumberFormatter.formatCurrency(apiDto.totalRevenue || 0, apiDto.currency),
totalFees: apiDto.totalFees || 0,
formattedTotalFees: NumberFormatter.formatCurrency(apiDto.totalFees || 0, apiDto.currency),
totalWithdrawals: apiDto.totalWithdrawals || 0,
pendingPayouts: apiDto.pendingPayouts || 0,
formattedPendingPayouts: NumberFormatter.formatCurrency(apiDto.pendingPayouts || 0, apiDto.currency),
currency: apiDto.currency,
transactions,
canWithdraw: apiDto.canWithdraw || false,
withdrawalBlockReason: apiDto.withdrawalBlockReason,
};
}
}
LeagueWalletViewDataBuilder satisfies ViewDataBuilder<LeagueWalletInputDTO, LeagueWalletViewData>;