Files
gridpilot.gg/apps/website/lib/services/payments/WalletService.ts
2025-12-25 00:19:36 +01:00

37 lines
1.3 KiB
TypeScript

import { WalletViewModel } from '@/lib/view-models/WalletViewModel';
import { PaymentsApiClient } from '../../api/payments/PaymentsApiClient';
import { FullTransactionDto } from '../../view-models/WalletTransactionViewModel';
/**
* Wallet Service
*
* Orchestrates wallet operations by coordinating API calls and view model creation.
* All dependencies are injected via constructor.
*/
export class WalletService {
constructor(
private readonly apiClient: PaymentsApiClient
) {}
/**
* Get wallet by driver ID with view model transformation
*/
async getWallet(leagueId?: string): Promise<WalletViewModel> {
const { wallet, transactions } = await this.apiClient.getWallet({ leagueId });
// Convert TransactionDTO to FullTransactionDto format
const convertedTransactions: FullTransactionDto[] = transactions.map(t => ({
id: t.id,
type: t.type as 'sponsorship' | 'membership' | 'withdrawal' | 'prize',
description: t.description,
amount: t.amount,
fee: t.amount * 0.05, // Calculate fee (5%)
netAmount: t.amount * 0.95, // Calculate net amount
date: new Date(t.createdAt),
status: 'completed',
referenceId: t.referenceId
}));
return new WalletViewModel({ ...wallet, transactions: convertedTransactions });
}
}