fix(trading): 流通池改为显示已挖矿产出总量,解决显示为0的问题
前端"流通池"原来读取 circulationPool(交易流通池),因系统尚无卖出交易故为 0。 现改为读取 totalMined(全网已挖矿产出的积分股总量 = 用户已挖 + 系统已挖)。 后端新增 getTotalMinedFromMiningService() 方法,调用 mining-service 的 GET /mining/progress 接口获取 totalDistributed。 注意:价格公式中的 circulationPool 保持不变,仍用交易流通池参与计算。 新增的 totalMined 字段仅用于前端展示。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
27db2a5aa2
commit
a5a69645b4
|
|
@ -221,6 +221,38 @@ export class AssetService {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 mining-service 获取全网已挖矿产出的积分股总量
|
||||
*
|
||||
* 调用 mining-service 的 GET /mining/progress 接口,返回 totalDistributed
|
||||
* (用户已挖 + 系统已挖的总和)。
|
||||
*
|
||||
* 该值用于前端"流通池"展示,表示已经通过挖矿产出并进入流通的积分股数量。
|
||||
* 注意:此值不参与价格公式计算,价格公式使用的是交易流通池(circulationPool)。
|
||||
*/
|
||||
private async getTotalMinedFromMiningService(): Promise<Money> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${this.miningServiceUrl}/api/v2/mining/progress`,
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
this.logger.warn(`Failed to fetch mining progress: HTTP ${response.status}`);
|
||||
return Money.zero();
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
// totalDistributed = 用户已挖总量 + 系统已挖总量
|
||||
if (result?.totalDistributed) {
|
||||
return new Money(result.totalDistributed);
|
||||
}
|
||||
return Money.zero();
|
||||
} catch (error) {
|
||||
this.logger.warn(`Failed to fetch total mined from mining-service: ${error}`);
|
||||
return Money.zero();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取做市商积分值余额(即价格公式中的"绿积分")
|
||||
*/
|
||||
|
|
@ -241,27 +273,37 @@ export class AssetService {
|
|||
|
||||
/**
|
||||
* 获取市场概览
|
||||
*
|
||||
* 返回字段说明:
|
||||
* - circulationPool: 价格公式中的流通池(卖出交易产生的积分股),用于价格/倍数计算
|
||||
* - totalMined: 全网已挖矿产出的积分股总量(用户+系统),前端"流通池"展示此值
|
||||
*
|
||||
* 注意:前端"流通池"显示的是 totalMined(已产出积分股),而非 circulationPool。
|
||||
* circulationPool 仅在交易发生后才有值,目前系统尚无交易,其值为 0。
|
||||
* 用户期望在"流通池"位置看到的是已经挖矿产出的积分股数量,因此新增 totalMined 字段。
|
||||
*/
|
||||
async getMarketOverview(): Promise<{
|
||||
price: string;
|
||||
greenPoints: string;
|
||||
blackHoleAmount: string;
|
||||
circulationPool: string;
|
||||
totalMined: string;
|
||||
effectiveDenominator: string;
|
||||
burnMultiplier: string;
|
||||
totalShares: string;
|
||||
burnTarget: string;
|
||||
burnProgress: string;
|
||||
}> {
|
||||
const [greenPoints, blackHole, circulationPool] = await Promise.all([
|
||||
const [greenPoints, blackHole, circulationPool, totalMined] = await Promise.all([
|
||||
this.getGreenPoints(),
|
||||
this.blackHoleRepository.getBlackHole(),
|
||||
this.circulationPoolRepository.getPool(),
|
||||
this.getTotalMinedFromMiningService(),
|
||||
]);
|
||||
const blackHoleAmount = blackHole?.totalBurned || Money.zero();
|
||||
const circulationPoolAmount = circulationPool?.totalShares || Money.zero();
|
||||
|
||||
// 计算价格
|
||||
// 计算价格(使用交易流通池,非已挖总量)
|
||||
const price = this.calculator.calculatePrice(greenPoints, blackHoleAmount, circulationPoolAmount);
|
||||
|
||||
// 计算有效分母
|
||||
|
|
@ -285,6 +327,7 @@ export class AssetService {
|
|||
greenPoints: greenPoints.toFixed(8),
|
||||
blackHoleAmount: blackHoleAmount.toFixed(8),
|
||||
circulationPool: circulationPoolAmount.toFixed(8),
|
||||
totalMined: totalMined.toFixed(8),
|
||||
effectiveDenominator: effectiveDenominator.toFixed(8),
|
||||
burnMultiplier: burnMultiplier.toFixed(18),
|
||||
totalShares: TradingCalculatorService.TOTAL_SHARES.toFixed(8),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class MarketOverviewModel extends MarketOverview {
|
|||
required super.greenPoints,
|
||||
required super.blackHoleAmount,
|
||||
required super.circulationPool,
|
||||
required super.totalMined,
|
||||
required super.effectiveDenominator,
|
||||
required super.burnMultiplier,
|
||||
required super.totalShares,
|
||||
|
|
@ -19,6 +20,7 @@ class MarketOverviewModel extends MarketOverview {
|
|||
greenPoints: json['greenPoints']?.toString() ?? '0',
|
||||
blackHoleAmount: json['blackHoleAmount']?.toString() ?? '0',
|
||||
circulationPool: json['circulationPool']?.toString() ?? '0',
|
||||
totalMined: json['totalMined']?.toString() ?? '0',
|
||||
effectiveDenominator: json['effectiveDenominator']?.toString() ?? '0',
|
||||
burnMultiplier: json['burnMultiplier']?.toString() ?? '0',
|
||||
totalShares: json['totalShares']?.toString() ?? '0',
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ class MarketOverview extends Equatable {
|
|||
final String greenPoints;
|
||||
/// 黑洞销毁量
|
||||
final String blackHoleAmount;
|
||||
/// 流通池
|
||||
/// 流通池(价格公式用,卖出交易产生的积分股)
|
||||
final String circulationPool;
|
||||
/// 已挖矿产出总量(用户+系统),前端"流通池"展示此值
|
||||
final String totalMined;
|
||||
/// 有效分母
|
||||
final String effectiveDenominator;
|
||||
/// 销毁倍数
|
||||
|
|
@ -26,6 +28,7 @@ class MarketOverview extends Equatable {
|
|||
required this.greenPoints,
|
||||
required this.blackHoleAmount,
|
||||
required this.circulationPool,
|
||||
required this.totalMined,
|
||||
required this.effectiveDenominator,
|
||||
required this.burnMultiplier,
|
||||
required this.totalShares,
|
||||
|
|
@ -39,6 +42,7 @@ class MarketOverview extends Equatable {
|
|||
greenPoints,
|
||||
blackHoleAmount,
|
||||
circulationPool,
|
||||
totalMined,
|
||||
effectiveDenominator,
|
||||
burnMultiplier,
|
||||
totalShares,
|
||||
|
|
|
|||
|
|
@ -363,9 +363,11 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
),
|
||||
Container(width: 1, height: 24, color: bgGray),
|
||||
const SizedBox(width: 16),
|
||||
// 流通池:显示全网已挖矿产出的积分股总量(totalMined),
|
||||
// 而非交易流通池(circulationPool,目前无交易故为0)
|
||||
_buildMarketDataItem(
|
||||
'流通池',
|
||||
market != null ? formatCompact(market.circulationPool) : null,
|
||||
market != null ? formatCompact(market.totalMined) : null,
|
||||
_orange,
|
||||
isLoading,
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in New Issue