Commit Graph

1826 Commits

Author SHA1 Message Date
hailin 7bc8547a96 fix(mining-app): rename ContributionRecordsListPage to avoid name conflict
- Rename page class from ContributionRecordsPage to ContributionRecordsListPage
- Add typedef RecordsPageData for ContributionRecordsPage data model
- Fix import statements and unused variable

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 19:08:09 -08:00
hailin caffb124d2 feat(mining-app): add contribution records page with category summary
- Create contribution_records_page.dart with full list view
  - Pagination support with page navigation
  - Filter by source type (personal, team level, team bonus)
  - Show detailed info: tree count, base contribution, rate, amount
  - Display effective/expire dates and status badges

- Update contribution_page.dart detail card
  - Show category summary instead of record list
  - Display three categories with icons: personal, team level, team bonus
  - Add navigation to full records page via "查看全部"

- Add route configuration for /contribution-records

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 19:02:30 -08:00
hailin 141db46356 fix(contribution-service): use real contributionPerTree from rate service
Previously, adoptions were synced with hardcoded contributionPerTree=1,
resulting in contribution values like 0.7 instead of the expected 15831.9.

Now the handler fetches the actual contribution rate from ContributionRateService
based on the adoption date, storing values like:
- Personal (70%): 22617 × 70% = 15831.9
- Team Level (0.5%): 22617 × 0.5% = 113.085
- Team Bonus (2.5%): 22617 × 2.5% = 565.425

Note: Historical data may need migration to apply the correct multiplier.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 18:01:30 -08:00
hailin f57b0f9c26 chore(mining-app): configure release build
- Add kDebugMode check to LoggingInterceptor to suppress logs in release
- Remove debug print statements from contribution_providers
- Add Play Core proguard rules to fix R8 missing classes error

Build command: flutter build apk --release --split-per-abi --target-platform android-arm,android-arm64
Output:
- app-arm64-v8a-release.apk: 18MB
- app-armeabi-v7a-release.apk: 16MB

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 17:24:42 -08:00
hailin c852f24a72 fix(auth-service): add 'auth/' prefix to controller routes for Kong compatibility
Kong routes /api/v2/auth/* to auth-service without stripping the path,
so controllers need 'auth/' prefix to match frontend requests:
- SmsController: 'sms' -> 'auth/sms'
- PasswordController: 'password' -> 'auth/password'
- UserController: 'user' -> 'auth/user'

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:53:48 -08:00
hailin cb3c7623dc fix(mining-app): fix Riverpod ref usage in router redirect callback
Use cached auth state from AuthNotifier instead of ref.read() to avoid
"Cannot use ref functions after provider changed" exception during rebuild.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:49:52 -08:00
hailin f2692a50ed fix(contribution-service): fix toRecordDto using wrong property name
- Changed `record.finalContribution` to `record.amount` for getting final contribution value
- Added optional chaining to prevent undefined errors
- Added default values for safety

The ContributionRecordAggregate uses `amount` property, not `finalContribution`.
This was causing "Cannot read properties of undefined (reading 'value')" errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:43:14 -08:00
hailin ed9f817fae feat(mining-app): add estimated earnings and contribution stats API
- Add ContributionStats entity and model for network-wide statistics
- Add /api/v2/contribution/stats endpoint
- Implement estimatedEarningsProvider to calculate daily earnings
- Formula: (user contribution / total contribution) × daily allocation
- Update contribution page to display real estimated earnings
- Add debug logs for contribution records API

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:37:30 -08:00
hailin 6bcb4af028 feat(mining-app): integrate real APIs for Asset and Profile pages
- Asset page now uses trading-service /asset/my endpoint
- Profile page integrates auth-service /user/profile and contribution-service
- Add new entities: AssetDisplay, PriceInfo, MarketOverview, TradingAccount
- Add corresponding models with JSON parsing
- Create asset_providers and profile_providers for state management
- Update trading_providers with real API integration
- Extend UserState and UserInfo with additional profile fields
- Remove obsolete buy_shares and sell_shares use cases
- Fix compilation errors in get_current_price and trading_page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:22:40 -08:00
hailin 106a287260 fix(mining-service): make health endpoints public 2026-01-14 07:35:42 -08:00
hailin 30dc2f6665 fix(trading-service): make health endpoints public 2026-01-14 07:28:24 -08:00
hailin e1fb70e2ee feat(trading-service): add burn system, Kafka events, and idempotency
- Add trading burn system with black hole, share pool, and price calculation
- Implement per-minute auto burn and sell burn with multiplier
- Add Kafka event publishing via outbox pattern (order, trade, burn events)
- Add user.registered consumer to auto-create trading accounts
- Implement Redis + DB dual idempotency for event processing
- Add price, burn, and asset API controllers
- Add migrations for burn tables and processed events

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 07:15:41 -08:00
hailin f3d4799efc feat(mining-wallet): add UserWalletCreated/Updated events for CDC sync
- Publish UserWalletCreated when a new wallet is created
- Publish UserWalletUpdated when wallet balance changes
- Events sent to cdc.mining-wallet.outbox topic for mining-admin-service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 06:13:34 -08:00
hailin 839feab97d fix(mining-admin): handle CONTRIBUTION_CREDITED event for wallet sync
Add handler for CONTRIBUTION_CREDITED events from mining-wallet-service
to sync user wallet data to synced_user_wallets table.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 06:11:49 -08:00
hailin 465e398040 fix(mining-admin): fix wallet ledger API to match frontend expected format
- Return usdtAvailable, usdtFrozen, pendingUsdt, settleableUsdt,
  settledTotalUsdt, expiredTotalUsdt instead of old field names
- Query SyncedUserWallet table for GREEN_POINTS wallet data
- Use miningAccount.availableBalance for pendingUsdt

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 05:56:24 -08:00
hailin c6c875849a fix(mining-service): make mining API public for service-to-service calls
Add @Public() decorator to MiningController to allow mining-admin-service
to fetch mining records without authentication.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 05:46:11 -08:00
hailin ce95c40c84 fix(mining-service): listen to correct CDC topic for contribution sync
Changed event handler to:
- Listen to 'cdc.contribution.outbox' topic (CDC/Debezium format)
- Handle 'ContributionAccountUpdated' events instead of 'ContributionCalculated'
- Use effectiveContribution for mining power calculation

This fixes the issue where mining accounts had zero totalContribution
because they weren't receiving contribution sync events.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 05:30:38 -08:00
hailin e6d966e89f fix(mining-admin): fetch mining records from mining-service
Update getUserMiningRecords to call mining-service API instead of
returning empty records. This enables the admin dashboard to display
actual user mining records.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 05:14:03 -08:00
hailin 270c17829e fix(mining-admin-service): move mining routes before :category/:key parameter route
NestJS matches routes in definition order. The :category/:key route was
matching mining/status before the specific mining routes. Moved mining
routes before the parameter routes to fix routing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 04:57:25 -08:00
hailin 289ac0190c fix(mining-admin-service): add logging and fix null data handling in getMiningStatus
- Add debug logging to trace mining service calls
- Return error object instead of null when data is missing
- Include error message in response for debugging

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 04:42:01 -08:00
hailin 467d637ccc fix(mining-admin-web): prevent duplicate /api/v2 in rewrite destination
Clean NEXT_PUBLIC_API_URL to remove trailing /api/v2 if present,
preventing paths like /api/v2/api/v2/configs/mining/status

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 04:37:32 -08:00
hailin c9690b0d36 Revert "fix(mining-admin-web): always use /api proxy instead of direct API URL"
This reverts commit 7a65ab3319.
2026-01-14 04:34:22 -08:00
hailin 7a65ab3319 fix(mining-admin-web): always use /api proxy instead of direct API URL
Browser cannot access Docker internal URLs like http://mining-admin-service:3023.
Always use /api which is proxied by Next.js rewrites to the backend service.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 04:32:59 -08:00
hailin e99b5347da feat(mining-admin-service): add transfer-enabled API endpoints
Add GET and POST /configs/transfer-enabled endpoints to control
the transfer switch. Routes are placed before :category/:key to
avoid being matched as path parameters.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 04:22:11 -08:00
hailin 29dd1affe1 fix(mining-admin-web): extract data from response wrapper
mining-admin-service uses TransformInterceptor which wraps all responses
with { success, data, timestamp } format. Frontend needs to access
response.data.data to get the actual data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 04:18:51 -08:00
hailin a15dcafc03 fix(mining-admin-service): 解包mining-service返回的data字段 2026-01-14 04:09:02 -08:00
hailin d404521841 fix(mining-admin-service): 修复mining-service API路径为v2 2026-01-14 03:58:02 -08:00
hailin 09b15da3cb fix(mining-service): Redis锁使用毫秒PX代替秒EX支持小数TTL 2026-01-14 03:52:22 -08:00
hailin 901247366d fix(mining-service): 添加tsconfig include/exclude配置修复构建 2026-01-14 03:48:18 -08:00
hailin 0abc04b9cb fix(mining-service): 添加Dockerfile构建验证步骤 2026-01-14 03:45:51 -08:00
hailin 2b083991d0 feat(mining-service): 添加migration将minuteDistribution改为secondDistribution
支持每秒挖矿分配功能

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 03:40:41 -08:00
hailin 8f616dd45b fix(mining-service): 修复Dockerfile支持prisma seed
- 添加ts-node/typescript到生产环境以支持seed执行
- 启动脚本中添加prisma db seed执行
- 复制tsconfig.json到生产环境

参考mining-wallet-service的Dockerfile配置

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 03:35:34 -08:00
hailin 1008672af9 Revert "fix(mining-service): 修复Docker构建问题"
This reverts commit f4380604d9.
2026-01-14 03:34:58 -08:00
hailin f4380604d9 fix(mining-service): 修复Docker构建问题
- tsconfig.json 添加 include/exclude 排除 prisma 文件夹
- 添加 .dockerignore 排除 seed.ts
- Dockerfile 添加构建验证

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 03:34:04 -08:00
hailin 3b61f2e095 feat(mining): 实现每秒挖矿分配系统
核心改动:
- 调度器从每分钟改为每秒执行,用户每秒看到挖矿收益
- 每秒更新账户余额,但MiningRecord每分钟汇总写入一次(减少数据量)
- seed自动执行(prisma.seed配置),初始化后isActive=false
- 只有一个手动操作:管理员在后台点击"启动挖矿"

技术细节:
- 每秒分配量:100万/63,072,000秒 ≈ 0.01585 shares/秒
- Redis累积器:每秒挖矿数据累积到Redis,每分钟末写入数据库
- 分布式锁:0.9秒锁定时间,支持多实例部署
- 后台管理界面:添加挖矿状态卡片和激活/停用按钮

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 03:25:47 -08:00
hailin 25608babd6 feat(mining-service): add initialization APIs and seed script
Add admin endpoints:
- GET /admin/status - Get mining system status
- POST /admin/initialize - Initialize mining config (one-time)
- POST /admin/activate - Activate mining distribution

Add prisma seed script for database initialization:
- MiningConfig: 100.02B total shares, 200万 distribution pool
- BlackHole: 100亿 burn target
- MiningEra: First era with 100万 distribution
- PoolAccounts: SHARE_POOL, BLACK_HOLE_POOL, CIRCULATION_POOL

Based on requirements:
- 第一个两年分配100万积分股
- 第二个两年分配50万积分股(减半)
- 100亿通过10年销毁到黑洞

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 02:36:52 -08:00
hailin bd0f98cfb3 fix(mining-admin-web): fix audit logs page crash
- Use 'all' instead of empty string for SelectItem value (Radix requirement)
- Add null safety for items array with fallback to empty array
- Fix potential undefined access on data.items

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 02:30:07 -08:00
hailin a2adddbf3d fix(mining-admin): transform dashboard API response to match frontend expected format
Frontend expects flat DashboardStats and RealtimeData interfaces.
Transform backend nested response to:
- totalUsers, adoptedUsers, networkEffectiveContribution, etc.
- currentMinuteDistribution, activeOrders, pendingTrades, etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 02:23:54 -08:00
hailin d6064294d7 refactor(mining-admin): remove initialization feature
System initialization is now handled by seed scripts and CDC sync,
so the manual initialization UI is no longer needed.

Removed:
- Frontend: initialization page and sidebar menu item
- Backend: InitializationController and InitializationService

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 02:22:23 -08:00
hailin 36c3ada6a6 fix(mining-admin): fix audit logs API path and response format
- Change controller path from /audit-logs to /audit to match frontend
- Transform response to frontend expected format (items, totalPages, etc.)
- Map admin.username to adminUsername field
- Add keyword query parameter support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 02:18:53 -08:00
hailin 13e94db450 feat(mining-admin): add /reports/daily endpoint for frontend reports page
Add ReportsController with /reports/daily endpoint that maps the
dashboard service data to the format expected by the frontend.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 02:10:47 -08:00
hailin feb871bcf1 feat(mining-admin): add daily report generation service
Add DailyReportService that:
- Generates daily reports on startup
- Updates reports every hour
- Collects stats from synced tables (users, adoptions, contributions, mining, trading)
- Supports historical report generation for backfilling

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 02:03:21 -08:00
hailin 4292d5da66 fix(mining-admin-web): fix TypeScript type for empty mainPools array 2026-01-14 01:55:58 -08:00
hailin a7a2282ba7 fix(mining-admin-web): update account type categorization to match backend
Update categorizeAccounts to use correct account types returned by backend:
- Core accounts: HEADQUARTERS, OPERATION, FEE
- Region accounts: PROVINCE, CITY

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 01:53:11 -08:00
hailin fa6826dde3 fix(mining-admin): use CDC synced tables for system accounts API
Change SystemAccountsService to read from syncedWalletSystemAccount and
syncedWalletPoolAccount tables instead of local tables. This fixes the
issue where the frontend shows "暂无数据" despite data being synced.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 01:44:22 -08:00
hailin eff71a6b22 feat(mining-wallet): publish outbox events for system/pool accounts
Add WalletSystemAccountCreated and WalletPoolAccountCreated events:
- seed.ts: publish events when creating HQ/OP/FEE and pool accounts
- contribution-wallet.service.ts: publish events when auto-creating
  province/city system accounts

This enables mining-admin-service to sync system accounts via CDC.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 01:28:48 -08:00
hailin 0bbb52284c fix(contribution): avoid nested transaction timeout in BonusClaimService
Use unitOfWork.isInTransaction() to detect if already in a transaction
context (called from ContributionCalculationService). If so, reuse the
existing transaction instead of opening a new one, preventing Prisma
interactive transaction timeout errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 01:02:08 -08:00
hailin 7588d18fff fix(mining-wallet): fix province/city creation and add seed on startup
- Use provinceCode directly instead of inferring from cityCode
- Use code as name for province/city records
- Add ts-node to production for seed execution
- Run prisma db seed on container startup

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 00:40:49 -08:00
hailin e6e44d9a43 Revert "fix(mining-wallet): auto-create HEADQUARTERS account, skip DEFAULT province/city"
This reverts commit bf004bab52.
2026-01-14 00:19:12 -08:00
hailin bf004bab52 fix(mining-wallet): auto-create HEADQUARTERS account, skip DEFAULT province/city 2026-01-14 00:18:53 -08:00