92 lines
2.4 KiB
Dart
92 lines
2.4 KiB
Dart
/// Display helpers for wallet transaction history (labels, credit vs debit).
|
|
library;
|
|
|
|
import '../../../data/models/transaction_model.dart';
|
|
import '../../../l10n/app_strings.dart';
|
|
|
|
const _creditTypes = {
|
|
'deposit',
|
|
'game_payout',
|
|
'game_refund',
|
|
'bonus',
|
|
'admin_adjustment',
|
|
};
|
|
|
|
/// Whether the amount increases the user's balance (shown with + and credit color).
|
|
bool isTransactionCredit(TransactionModel tx) {
|
|
if (tx.type == 'transfer') {
|
|
return tx.metadata?['direction']?.toString() == 'in';
|
|
}
|
|
if (tx.type == 'withdrawal' || tx.type == 'game_stake') return false;
|
|
return _creditTypes.contains(tx.type);
|
|
}
|
|
|
|
/// Human-readable label for a wallet transaction row.
|
|
String transactionLabel(TransactionModel tx, AppStrings s) {
|
|
switch (tx.type) {
|
|
case 'deposit':
|
|
return s.txTypeDeposit;
|
|
case 'withdrawal':
|
|
return s.txTypeWithdrawal;
|
|
case 'transfer':
|
|
return tx.metadata?['direction']?.toString() == 'in'
|
|
? s.txTypeTransferIn
|
|
: s.txTypeTransferOut;
|
|
case 'game_stake':
|
|
return s.txTypeGameStake;
|
|
case 'game_payout':
|
|
return s.txTypeGamePayout;
|
|
case 'game_refund':
|
|
return s.txTypeGameRefund;
|
|
case 'bonus':
|
|
return s.txTypeBonus;
|
|
case 'admin_adjustment':
|
|
return s.txTypeAdminAdjustment;
|
|
default:
|
|
return tx.type;
|
|
}
|
|
}
|
|
|
|
/// Localized transaction status label.
|
|
String transactionStatusLabel(String status, AppStrings s) {
|
|
switch (status) {
|
|
case 'pending':
|
|
return s.txStatusPending;
|
|
case 'completed':
|
|
return s.txStatusCompleted;
|
|
case 'confirmed':
|
|
return s.txStatusConfirmed;
|
|
case 'rejected':
|
|
return s.txStatusRejected;
|
|
case 'failed':
|
|
return s.txStatusFailed;
|
|
case 'cancelled':
|
|
case 'canceled':
|
|
return s.txStatusCancelled;
|
|
case 'broadcasting':
|
|
return s.txStatusBroadcasting;
|
|
default:
|
|
return status;
|
|
}
|
|
}
|
|
|
|
/// Stake account kind from prediction transaction metadata (`main` / `bonus` / `test`).
|
|
String? stakeAccountKind(TransactionModel tx) {
|
|
final raw = tx.metadata?['stake_account_kind']?.toString();
|
|
if (raw == null || raw.isEmpty) return null;
|
|
return raw;
|
|
}
|
|
|
|
String stakeAccountKindLabel(String? kind, AppStrings s) {
|
|
switch (kind) {
|
|
case 'bonus':
|
|
return s.walletBonus;
|
|
case 'test':
|
|
return s.walletTest;
|
|
case 'main':
|
|
return s.walletMain;
|
|
default:
|
|
return '—';
|
|
}
|
|
}
|