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:
parent
f9222fed50
commit
30f3487bd3
|
|
@ -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 {
|
String get description {
|
||||||
if (feeType == FeeType.fixed) {
|
if (feeType == FeeType.fixed) {
|
||||||
|
|
|
||||||
|
|
@ -167,9 +167,18 @@ class _WithdrawUsdtPageState extends ConsumerState<WithdrawUsdtPage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 设置全部金额
|
/// 设置全部金额(扣除手续费后的最大可转金额)
|
||||||
void _setMaxAmount() {
|
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(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue