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 { TradingCalculatorService } from '../../domain/services/trading-calculator.service';
|
||||||
import { BlackHoleRepository } from '../../infrastructure/persistence/repositories/black-hole.repository';
|
import { BlackHoleRepository } from '../../infrastructure/persistence/repositories/black-hole.repository';
|
||||||
import { CirculationPoolRepository } from '../../infrastructure/persistence/repositories/circulation-pool.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 { TradingConfigRepository } from '../../infrastructure/persistence/repositories/trading-config.repository';
|
||||||
import { OutboxRepository } from '../../infrastructure/persistence/repositories/outbox.repository';
|
import { OutboxRepository } from '../../infrastructure/persistence/repositories/outbox.repository';
|
||||||
import { RedisService } from '../../infrastructure/redis/redis.service';
|
import { RedisService } from '../../infrastructure/redis/redis.service';
|
||||||
|
|
@ -38,6 +39,7 @@ export class BurnService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly blackHoleRepository: BlackHoleRepository,
|
private readonly blackHoleRepository: BlackHoleRepository,
|
||||||
private readonly circulationPoolRepository: CirculationPoolRepository,
|
private readonly circulationPoolRepository: CirculationPoolRepository,
|
||||||
|
private readonly sharePoolRepository: SharePoolRepository,
|
||||||
private readonly tradingConfigRepository: TradingConfigRepository,
|
private readonly tradingConfigRepository: TradingConfigRepository,
|
||||||
private readonly outboxRepository: OutboxRepository,
|
private readonly outboxRepository: OutboxRepository,
|
||||||
private readonly redis: RedisService,
|
private readonly redis: RedisService,
|
||||||
|
|
@ -238,13 +240,16 @@ export class BurnService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化黑洞和配置
|
* 初始化交易系统(黑洞、配置、积分股池、流通池)
|
||||||
*/
|
*/
|
||||||
async initialize(): Promise<void> {
|
async initialize(): Promise<void> {
|
||||||
const [existingConfig, existingBlackHole] = await Promise.all([
|
const [existingConfig, existingBlackHole, existingSharePool, existingCirculationPool] =
|
||||||
this.tradingConfigRepository.getConfig(),
|
await Promise.all([
|
||||||
this.blackHoleRepository.getBlackHole(),
|
this.tradingConfigRepository.getConfig(),
|
||||||
]);
|
this.blackHoleRepository.getBlackHole(),
|
||||||
|
this.sharePoolRepository.getPool(),
|
||||||
|
this.circulationPoolRepository.getPool(),
|
||||||
|
]);
|
||||||
|
|
||||||
if (!existingConfig) {
|
if (!existingConfig) {
|
||||||
await this.tradingConfigRepository.initializeConfig();
|
await this.tradingConfigRepository.initializeConfig();
|
||||||
|
|
@ -257,6 +262,19 @@ export class BurnService {
|
||||||
);
|
);
|
||||||
this.logger.log('Black hole initialized');
|
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 price = priceInfo?.price ?? '0';
|
||||||
final greenPoints = priceInfo?.greenPoints ?? '0';
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.all(16),
|
margin: const EdgeInsets.all(16),
|
||||||
|
|
@ -169,24 +168,13 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
const Text(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
'当前积分股价格',
|
||||||
children: [
|
style: TextStyle(
|
||||||
const Text(
|
fontSize: 12,
|
||||||
'当前积分股价格',
|
fontWeight: FontWeight.w500,
|
||||||
style: TextStyle(
|
color: _grayText,
|
||||||
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 SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Row(
|
Row(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue