fix(trading): 修复卖出预估计算,加入销毁倍数
卖出预估计算现在使用与后端一致的公式: - 有效积分股 = 卖出量 × (1 + burnMultiplier) - 卖出交易额 = 有效积分股 × 价格 × 0.9 修复的位置: 1. _calculateEstimate() 方法 - 预计获得显示 2. _handleTrade() 确认弹窗 - 显示销毁倍数和有效积分股明细 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6109bf4584
commit
7df57b9de5
|
|
@ -810,21 +810,32 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
);
|
||||
}
|
||||
|
||||
/// 计算预估获得/支出
|
||||
/// 卖出公式:卖出交易额 = (卖出量 + 卖出销毁量) × 价格 × 0.9
|
||||
/// = 卖出量 × (1 + burnMultiplier) × 价格 × 0.9
|
||||
String _calculateEstimate() {
|
||||
final price = double.tryParse(_priceController.text) ?? 0;
|
||||
final quantity = double.tryParse(_quantityController.text) ?? 0;
|
||||
final total = price * quantity;
|
||||
|
||||
if (total == 0) {
|
||||
if (price == 0 || quantity == 0) {
|
||||
return '0.00 积分值';
|
||||
}
|
||||
|
||||
if (_selectedTab == 1) {
|
||||
// 卖出时扣除10%销毁
|
||||
final afterBurn = total * 0.9;
|
||||
return '${formatAmount(afterBurn.toString())} 积分值';
|
||||
// 卖出时:有效积分股 = 卖出量 × (1 + burnMultiplier)
|
||||
// 卖出交易额 = 有效积分股 × 价格 × 0.9(扣除10%手续费)
|
||||
final marketAsync = ref.read(marketOverviewProvider);
|
||||
final burnMultiplier = double.tryParse(
|
||||
marketAsync.valueOrNull?.burnMultiplier ?? '0',
|
||||
) ?? 0;
|
||||
final effectiveQuantity = quantity * (1 + burnMultiplier);
|
||||
final grossAmount = effectiveQuantity * price;
|
||||
final netAmount = grossAmount * 0.9; // 扣除10%手续费
|
||||
return '${formatAmount(netAmount.toString())} 积分值';
|
||||
}
|
||||
|
||||
// 买入时:支出 = 价格 × 数量
|
||||
final total = price * quantity;
|
||||
return '${formatAmount(total.toString())} 积分值';
|
||||
}
|
||||
|
||||
|
|
@ -1036,9 +1047,20 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
|
||||
// 卖出时显示确认弹窗
|
||||
if (!isBuy) {
|
||||
final total = price * quantity;
|
||||
final burned = total * 0.1;
|
||||
final received = total * 0.9;
|
||||
// 获取销毁倍数,使用与后端一致的公式计算
|
||||
final marketAsync = ref.read(marketOverviewProvider);
|
||||
final burnMultiplier = double.tryParse(
|
||||
marketAsync.valueOrNull?.burnMultiplier ?? '0',
|
||||
) ?? 0;
|
||||
|
||||
// 有效积分股 = 卖出量 × (1 + burnMultiplier)
|
||||
final effectiveQuantity = quantity * (1 + burnMultiplier);
|
||||
// 交易总额 = 有效积分股 × 价格
|
||||
final grossAmount = effectiveQuantity * price;
|
||||
// 手续费 = 交易总额 × 10%
|
||||
final tradeFee = grossAmount * 0.1;
|
||||
// 实际获得 = 交易总额 × 90%
|
||||
final received = grossAmount * 0.9;
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
|
|
@ -1052,10 +1074,14 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
const SizedBox(height: 8),
|
||||
Text('卖出价格: ${formatPrice(price.toString())} 积分值'),
|
||||
const SizedBox(height: 8),
|
||||
Text('交易总额: ${formatAmount(total.toString())} 积分值'),
|
||||
Text('销毁倍数: ${burnMultiplier.toStringAsFixed(4)}'),
|
||||
const SizedBox(height: 8),
|
||||
Text('有效积分股: ${formatAmount(effectiveQuantity.toString())}'),
|
||||
const SizedBox(height: 8),
|
||||
Text('交易总额: ${formatAmount(grossAmount.toString())} 积分值'),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'进入积分股池: ${formatAmount(burned.toString())} 积分值 (10%)',
|
||||
'进入积分股池: ${formatAmount(tradeFee.toString())} 积分值 (10%)',
|
||||
style: const TextStyle(color: _green),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
|
|
|||
Loading…
Reference in New Issue