export type WalletTransactionStats = { netAmount?: string; byType?: Array<{ transactionType?: string; totalAmount?: string }>; }; const CASHBACK_TYPES = new Set(['CASHBACK', 'CASHBACK_DEPOSIT']); /** Sum wallet credits from cashback transaction types (matches WalletDetailView fallback). */ export function sumCashbackFromStats(stats: WalletTransactionStats | null | undefined): number { let sum = 0; for (const group of stats?.byType ?? []) { const type = group.transactionType?.toUpperCase() ?? ''; if (CASHBACK_TYPES.has(type)) { sum += Math.abs(parseFloat(group.totalAmount ?? '0') || 0); } } return sum; }