games_app/prediqo_mobile/lib/data/models/balance_model.dart
2026-07-25 22:48:54 +02:00

44 lines
1.3 KiB
Dart

/// User balance for a single wallet type.
///
/// Combines wallet metadata with available and locked amounts in raw units.
library;
import 'wallet_type_model.dart';
/// Balance snapshot for one asset, including nested wallet type details.
class BalanceModel {
const BalanceModel({
required this.walletType,
required this.available,
required this.locked,
this.bonusAvailable = '0',
this.testAvailable = '0',
});
final WalletTypeModel walletType;
/// Spendable main balance in smallest units as a string.
final String available;
/// Locked balance (e.g. pending withdrawals) in smallest units.
final String locked;
/// Bonus account available balance in smallest units.
final String bonusAvailable;
/// Test account available balance in smallest units.
final String testAvailable;
/// Parses a balance entry from the `/api/v1/balances` response.
factory BalanceModel.fromJson(Map<String, dynamic> json) {
final wt = json['walletType'] as Map<String, dynamic>;
return BalanceModel(
walletType: WalletTypeModel.fromJson(wt),
available: (json['available'] ?? '0').toString(),
locked: (json['locked'] ?? '0').toString(),
bonusAvailable: (json['bonusAvailable'] ?? '0').toString(),
testAvailable: (json['testAvailable'] ?? '0').toString(),
);
}
}