fix(mobile-app): 点击"全部"时扣除手续费计算最大可转金额

- FeeConfig 新增 calculateMaxAmount 方法计算扣除手续费后的最大金额
- 修改提取页面 _setMaxAmount,点击"全部"时显示扣费后金额
- 固定费率:maxAmount = balance - fixedFee
- 百分比费率:maxAmount = balance / (1 + rate)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-22 22:36:20 -08:00
parent f9222fed50
commit 30f3487bd3
2 changed files with 41 additions and 2 deletions

View File

@ -181,6 +181,36 @@ class FeeConfig {
}
}
///
/// = +
/// 使 + <= balance
double calculateMaxAmount(double balance) {
if (balance <= 0) return 0;
if (feeType == FeeType.fixed) {
// : maxAmount = balance - fixedFee
final maxAmount = balance - feeValue;
return maxAmount > 0 ? maxAmount : 0;
} else {
// : = amount * (1 + rate)
// maxAmount = balance / (1 + rate)
final maxAmount = balance / (1 + feeValue);
// /
final fee = calculateFee(maxAmount);
final actualTotal = maxAmount + fee;
// minFee
if (actualTotal > balance && minFee > 0) {
// 使 minFee : maxAmount = balance - minFee
final adjustedMax = balance - minFee;
return adjustedMax > 0 ? adjustedMax : 0;
}
return maxAmount > 0 ? maxAmount : 0;
}
}
///
String get description {
if (feeType == FeeType.fixed) {

View File

@ -167,9 +167,18 @@ class _WithdrawUsdtPageState extends ConsumerState<WithdrawUsdtPage> {
});
}
///
///
void _setMaxAmount() {
_amountController.text = _usdtBalance.toStringAsFixed(2);
double maxAmount;
if (_feeConfig != null) {
maxAmount = _feeConfig!.calculateMaxAmount(_usdtBalance);
} else {
// 2 绿
maxAmount = _usdtBalance - 2;
}
//
if (maxAmount < 0) maxAmount = 0;
_amountController.text = maxAmount.toStringAsFixed(2);
setState(() {});
}