fix(trading): auto-initialize SharePool and CirculationPool on startup
- Add SharePool and CirculationPool initialization in BurnService.initialize() - Initialize SharePool with 5760 green points (fixes price showing as 0) - Remove misleading "= 5,760 积分值" display from trading page Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e611894b55
commit
ed715111ae
|
|
@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
|
|||
import { TradingCalculatorService } from '../../domain/services/trading-calculator.service';
|
||||
import { BlackHoleRepository } from '../../infrastructure/persistence/repositories/black-hole.repository';
|
||||
import { CirculationPoolRepository } from '../../infrastructure/persistence/repositories/circulation-pool.repository';
|
||||
import { SharePoolRepository } from '../../infrastructure/persistence/repositories/share-pool.repository';
|
||||
import { TradingConfigRepository } from '../../infrastructure/persistence/repositories/trading-config.repository';
|
||||
import { OutboxRepository } from '../../infrastructure/persistence/repositories/outbox.repository';
|
||||
import { RedisService } from '../../infrastructure/redis/redis.service';
|
||||
|
|
@ -38,6 +39,7 @@ export class BurnService {
|
|||
constructor(
|
||||
private readonly blackHoleRepository: BlackHoleRepository,
|
||||
private readonly circulationPoolRepository: CirculationPoolRepository,
|
||||
private readonly sharePoolRepository: SharePoolRepository,
|
||||
private readonly tradingConfigRepository: TradingConfigRepository,
|
||||
private readonly outboxRepository: OutboxRepository,
|
||||
private readonly redis: RedisService,
|
||||
|
|
@ -238,13 +240,16 @@ export class BurnService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 初始化黑洞和配置
|
||||
* 初始化交易系统(黑洞、配置、积分股池、流通池)
|
||||
*/
|
||||
async initialize(): Promise<void> {
|
||||
const [existingConfig, existingBlackHole] = await Promise.all([
|
||||
this.tradingConfigRepository.getConfig(),
|
||||
this.blackHoleRepository.getBlackHole(),
|
||||
]);
|
||||
const [existingConfig, existingBlackHole, existingSharePool, existingCirculationPool] =
|
||||
await Promise.all([
|
||||
this.tradingConfigRepository.getConfig(),
|
||||
this.blackHoleRepository.getBlackHole(),
|
||||
this.sharePoolRepository.getPool(),
|
||||
this.circulationPoolRepository.getPool(),
|
||||
]);
|
||||
|
||||
if (!existingConfig) {
|
||||
await this.tradingConfigRepository.initializeConfig();
|
||||
|
|
@ -257,6 +262,19 @@ export class BurnService {
|
|||
);
|
||||
this.logger.log('Black hole initialized');
|
||||
}
|
||||
|
||||
// 初始化积分股池(绿积分池),初始值 5760
|
||||
if (!existingSharePool) {
|
||||
const initialGreenPoints = new Money(5760);
|
||||
await this.sharePoolRepository.initializePool(initialGreenPoints);
|
||||
this.logger.log(`Share pool initialized with ${initialGreenPoints.toFixed(8)} green points`);
|
||||
}
|
||||
|
||||
// 初始化流通池
|
||||
if (!existingCirculationPool) {
|
||||
await this.circulationPoolRepository.initializePool();
|
||||
this.logger.log('Circulation pool initialized');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -157,7 +157,6 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
}
|
||||
|
||||
final price = priceInfo?.price ?? '0';
|
||||
final greenPoints = priceInfo?.greenPoints ?? '0';
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
|
|
@ -169,24 +168,13 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'当前积分股价格',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: _grayText,
|
||||
),
|
||||
),
|
||||
DataText(
|
||||
data: priceInfo != null ? '= ${formatCompact(greenPoints)} 积分值' : null,
|
||||
isLoading: isLoading,
|
||||
placeholder: '= -- 积分值',
|
||||
style: const TextStyle(fontSize: 12, color: _grayText),
|
||||
),
|
||||
],
|
||||
const Text(
|
||||
'当前积分股价格',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: _grayText,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
|
|
|
|||
Loading…
Reference in New Issue