135 lines
3.7 KiB
Dart
135 lines
3.7 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 tx.metadata?['bet_status']?.toString() == 'lost'
|
|
? s.txTypeGameLoss
|
|
: 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 (withdrawal statuses follow the backend state machine).
|
|
String transactionStatusLabel(String status, AppStrings s) {
|
|
switch (status) {
|
|
case 'pending':
|
|
case 'pending_approval':
|
|
return s.txStatusPending;
|
|
case 'processing':
|
|
case 'broadcasting':
|
|
case 'confirming':
|
|
case 'ledger_finalize_failed':
|
|
return s.txStatusProcessing;
|
|
case 'completed':
|
|
return s.txStatusCompleted;
|
|
case 'confirmed':
|
|
return s.txStatusConfirmed;
|
|
case 'rejected':
|
|
return s.txStatusRejected;
|
|
case 'failed':
|
|
case 'failed_refunded':
|
|
return s.txStatusFailed;
|
|
case 'cancelled':
|
|
case 'canceled':
|
|
return s.txStatusCancelled;
|
|
default:
|
|
return status;
|
|
}
|
|
}
|
|
|
|
/// Visual tone of a status chip.
|
|
enum TxStatusTone { success, warning, info, danger, neutral }
|
|
|
|
TxStatusTone transactionStatusTone(String status) {
|
|
switch (status) {
|
|
case 'completed':
|
|
case 'confirmed':
|
|
return TxStatusTone.success;
|
|
case 'pending':
|
|
case 'pending_approval':
|
|
return TxStatusTone.warning;
|
|
case 'processing':
|
|
case 'broadcasting':
|
|
case 'confirming':
|
|
case 'ledger_finalize_failed':
|
|
return TxStatusTone.info;
|
|
case 'rejected':
|
|
case 'failed':
|
|
case 'failed_refunded':
|
|
case 'cancelled':
|
|
case 'canceled':
|
|
return TxStatusTone.danger;
|
|
default:
|
|
return TxStatusTone.neutral;
|
|
}
|
|
}
|
|
|
|
/// A withdrawal the user can still cancel (not yet picked up for payout).
|
|
bool canCancelWithdrawal(TransactionModel tx) =>
|
|
tx.type == 'withdrawal' && tx.status == 'pending';
|
|
|
|
/// Withdrawal whose reserved amount was credited back to the user.
|
|
bool isRefundedWithdrawal(TransactionModel tx) =>
|
|
tx.type == 'withdrawal' &&
|
|
(tx.status == 'rejected' || tx.status == 'cancelled' || tx.status == 'failed_refunded');
|
|
|
|
/// 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 '—';
|
|
}
|
|
}
|