diff --git a/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart b/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart index 5bbbafa2..d0d42d0c 100644 --- a/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart +++ b/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart @@ -117,15 +117,25 @@ class _AssetPageState extends ConsumerState { _timerStarted = false; } - /// 计算当前实时资产显示值 - /// 使用 WebSocket 推送的实时价格 - /// 资产显示值 = 当前积分股余额 × (1 + burnMultiplier) × price - double get _currentDisplayValue { + /// 计算当前实时总资产显示值 + /// 总资产 = 积分股价值 + 积分值余额 + /// 积分股价值 = 当前积分股余额 × (1 + burnMultiplier) × price + /// 积分值余额 = 可用积分值 + 冻结积分值 + double _calculateTotalAssetValue(AssetDisplay? asset) { // 优先使用 WebSocket 推送的价格,否则使用 API 返回的价格 final price = double.tryParse(_currentPrice) ?? 0; final burnMultiplier = double.tryParse(_currentBurnMultiplier) ?? 0; final multiplierFactor = 1 + burnMultiplier; - return _currentShareBalance * multiplierFactor * price; + + // 积分股价值 + final shareValue = _currentShareBalance * multiplierFactor * price; + + // 积分值余额(现金 = 可用 + 冻结) + final availableCash = double.tryParse(asset?.availableCash ?? '0') ?? 0; + final frozenCash = double.tryParse(asset?.frozenCash ?? '0') ?? 0; + final totalCash = availableCash + frozenCash; + + return shareValue + totalCash; } /// 计算当前实时积分股余额 @@ -210,7 +220,7 @@ class _AssetPageState extends ConsumerState { children: [ const SizedBox(height: 8), // 总资产卡片 - 始终显示,数字部分闪烁,实时刷新 - _buildTotalAssetCard(asset, isLoading, _currentDisplayValue, _currentShareBalance, perSecondEarning), + _buildTotalAssetCard(asset, isLoading, _calculateTotalAssetValue(asset), _currentShareBalance, perSecondEarning), const SizedBox(height: 24), // 快捷操作按钮 _buildQuickActions(context), @@ -255,13 +265,13 @@ class _AssetPageState extends ConsumerState { ); } - Widget _buildTotalAssetCard(AssetDisplay? asset, bool isLoading, double currentDisplayValue, double currentShareBalance, String perSecondEarning) { + Widget _buildTotalAssetCard(AssetDisplay? asset, bool isLoading, double totalAssetValue, double currentShareBalance, String perSecondEarning) { // 使用传入的每秒增长值(来自 mining-service) final growthPerSecond = double.tryParse(perSecondEarning) ?? 0.0; - // 使用实时计算的资产值(含倍数) - final displayValue = asset != null && currentDisplayValue > 0 - ? currentDisplayValue.toString() + // 使用实时计算的总资产值(积分股价值 + 积分值余额) + final displayValue = asset != null && totalAssetValue > 0 + ? totalAssetValue.toString() : asset?.displayAssetValue; // 计算有效积分股(含倍数)= 实时积分股余额 × (1 + burnMultiplier)