diff --git a/frontend/mining-app/lib/presentation/pages/trading/trading_page.dart b/frontend/mining-app/lib/presentation/pages/trading/trading_page.dart index 497c1f23..dddac8db 100644 --- a/frontend/mining-app/lib/presentation/pages/trading/trading_page.dart +++ b/frontend/mining-app/lib/presentation/pages/trading/trading_page.dart @@ -810,21 +810,32 @@ class _TradingPageState extends ConsumerState { ); } + /// 计算预估获得/支出 + /// 卖出公式:卖出交易额 = (卖出量 + 卖出销毁量) × 价格 × 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 { // 卖出时显示确认弹窗 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( context: context, @@ -1052,10 +1074,14 @@ class _TradingPageState extends ConsumerState { 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),