games_app/prediqo_mobile/lib/features/wallet/utils/withdraw_eligibility.dart
2026-08-26 14:24:35 +02:00

68 lines
1.8 KiB
Dart

/// Shared withdraw eligibility (global kill-switch, rails, fee vs balance).
library;
enum WithdrawBlockReason { globalOff, noNetwork, insufficientForFee }
class WithdrawEligibility {
const WithdrawEligibility({
required this.allowed,
this.reason,
required this.maxReceivableRaw,
required this.feeRaw,
required this.availableRaw,
});
final bool allowed;
final WithdrawBlockReason? reason;
final BigInt maxReceivableRaw;
final BigInt feeRaw;
final BigInt availableRaw;
}
/// Ledger amounts are 6-decimal micro-USDT. Allowed when global on, ≥1 rail,
/// and available > fee (at least 1 micro receivable after fee).
WithdrawEligibility computeWithdrawEligibility({
required bool withdrawalsEnabled,
required bool hasWithdrawNetwork,
required String availableRaw,
required String feeRaw,
}) {
final available = BigInt.tryParse(availableRaw.trim()) ?? BigInt.zero;
final fee = BigInt.tryParse(feeRaw.trim()) ?? BigInt.zero;
final maxReceivable = available > fee ? available - fee : BigInt.zero;
if (!withdrawalsEnabled) {
return WithdrawEligibility(
allowed: false,
reason: WithdrawBlockReason.globalOff,
maxReceivableRaw: maxReceivable,
feeRaw: fee,
availableRaw: available,
);
}
if (!hasWithdrawNetwork) {
return WithdrawEligibility(
allowed: false,
reason: WithdrawBlockReason.noNetwork,
maxReceivableRaw: maxReceivable,
feeRaw: fee,
availableRaw: available,
);
}
if (maxReceivable <= BigInt.zero) {
return WithdrawEligibility(
allowed: false,
reason: WithdrawBlockReason.insufficientForFee,
maxReceivableRaw: maxReceivable,
feeRaw: fee,
availableRaw: available,
);
}
return WithdrawEligibility(
allowed: true,
maxReceivableRaw: maxReceivable,
feeRaw: fee,
availableRaw: available,
);
}