Commit Graph

1728 Commits

Author SHA1 Message Date
hailin 94d8075970 fix(mining-app): unify color scheme and fix scroll issues
- Update login/register pages to use orange color scheme (#FF6B00)
  matching the navigation pages design
- Fix SafeArea bottom: false on all navigation pages since MainShell
  handles bottom safe area via bottomNavigationBar
- Add AlwaysScrollableScrollPhysics to asset page for consistent scroll
- Increase bottom padding to 100px on all navigation pages to clear
  the navigation bar

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 12:41:41 -08:00
hailin c31d64550b fix(deploy): remove duplicate contribution-records/publish-all call
The full-reset function was calling contribution-records/publish-all API
which caused duplicate records in mining-admin-service because:
- Contribution records are already published to outbox when calculated
- Debezium automatically captures outbox_events and sends to Kafka
- Calling publish-all again creates duplicate events with different IDs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 12:29:16 -08:00
hailin 1b3704b68d fix(contribution-service): fix property mapping in toDto method
The toDto method was accessing non-existent properties on ContributionAccountAggregate:
- teamLevelContribution -> totalLevelPending
- teamBonusContribution -> totalBonusPending
- totalContribution -> effectiveContribution
- isCalculated -> true (always calculated when account exists)
- lastCalculatedAt -> updatedAt

This was causing "Cannot read properties of undefined (reading 'value')" error
on GET /api/v2/contribution/accounts/{accountSequence}

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 12:17:31 -08:00
hailin 5c76c9f62c refactor(mining-app): remove deprecated HomePage and fix navigation
- Delete old green-themed HomePage and its widgets (asset_card, price_card, quick_actions)
- Remove /home route from router configuration
- Fix SplashPage to redirect to /contribution instead of /home after login
- Now all navigation goes through the new orange-themed UI pages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 11:19:41 -08:00
hailin bfafd6d34c refactor(prisma): consolidate migrations into single init files
Merge multiple incremental migrations into single init migration for each service:

- auth-service: 3 migrations → 1 (user auth, SMS, KYC)
- contribution-service: 4 migrations → 1 (contribution accounts, 15-level hierarchy, 3-tier bonus)
- mining-admin-service: 6 migrations → 1 (admin, CDC sync tables, prisma relation mode)
- mining-service: 1 migration (no change needed, renamed for consistency)
- mining-wallet-service: 3 migrations → 1 (wallet system, removed blockchain tables)
- trading-service: 1 migration (no change needed, renamed for consistency)

All migrations renamed from timestamp format (20260111000000_*) to sequential format (0001_init)
for cleaner migration history.

Note: Requires clearing _prisma_migrations table before applying to existing databases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 11:04:24 -08:00
hailin 34e22d3c7f revert: restore original Dockerfiles 2026-01-12 10:12:16 -08:00
hailin d68ee398ab fix: add TEAM_BONUS cleanup to startup scripts
Delete incorrect TEAM_BONUS records (where account_sequence !=
source_account_sequence) on each container startup after migrations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 10:10:51 -08:00
hailin ff3a614804 fix: remove broken data migration files 2026-01-12 10:08:10 -08:00
hailin 22fe23914f fix(contribution): simplify migration to only delete wrong TEAM_BONUS records
Remove the UPDATE statement that referenced non-existent columns.
The contribution_accounts table uses different field structure.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:59:11 -08:00
hailin 95e009966e fix(mining-admin): calculate distribution amounts from actual adoption data
Use treeCount * contributionPerTree from adoption record to calculate
the actual distribution amounts (70%, 12%, 1%, 2%, 15%) instead of
deriving from contribution_records table.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:55:27 -08:00
hailin e71f2aadfc fix: remove incorrect TEAM_BONUS records given to uplines
TEAM_BONUS should only be given to the adopter themselves, not to their
uplines. This migration deletes all TEAM_BONUS records where
account_sequence != source_account_sequence.

Also updates contribution_accounts totals in contribution-service.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:49:44 -08:00
hailin fe332fdb3f fix(mining-app): remove AuthEventBus to fix Riverpod state race condition
The AuthEventBus was causing "Cannot use ref functions after the
dependency of a provider changed" error when 401 responses triggered
logout during provider rebuilds.

Now 401 handling is done through normal exception flow in splash page
and route guards respond to isLoggedInProvider state changes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:44:53 -08:00
hailin add405aa65 feat(mining-app): fix login bugs and connect contribution page to real API
Login fixes:
- Add AuthEventBus for global 401 error handling with auto-logout
- Add route guards with GoRouter redirect to protect authenticated routes
- Remove setMockUser() security vulnerability and legacy login() dead code
- Remove unused AuthInterceptor class

Contribution page:
- Add ContributionRecord entity and model for records API
- Connect contribution details card to GET /accounts/{id}/records endpoint
- Display real team stats (direct referrals, unlocked levels/tiers)
- Calculate expiration countdown from actual record data

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:39:23 -08:00
hailin a89f4c829d feat(mining-admin): add migration for distributionSummary column
Add distributionSummary Text column to synced_adoptions table for storing
distribution details calculated during contribution calculation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:33:58 -08:00
hailin 23dabb0219 feat(contribution): display distribution details with actual amounts
Changes:
1. contribution-service:
   - Add distributionSummary field to SyncedAdoption schema
   - Store distribution summary after contribution calculation

2. mining-admin-service:
   - Add distributionSummary field to SyncedAdoption schema
   - Calculate actual distribution from contribution_records table
   - Return distribution details in planting ledger API

3. mining-admin-web:
   - Display distribution details in planting ledger table
   - Show: 70%(amount) personal, 12%(amount) operation,
     1%(amount) province, 2%(amount) city, 15%(amount) team
   - Show team distribution breakdown (distributed vs unallocated)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:23:02 -08:00
hailin 8d97daa524 fix(contribution): correct TEAM_BONUS distribution to adopter instead of referrer
TEAM_BONUS (7.5% = 2.5% × 3 tiers) should be given to the adopter themselves,
not to their direct referrer. The unlock conditions are:
- T1 (2.5%): Self adoption (always unlocked when adopting)
- T2 (2.5%): 2+ direct referrals adopted
- T3 (2.5%): 4+ direct referrals adopted

Also fixed findAncestorChain to correctly include the first ancestor
in the chain instead of skipping it.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 09:13:13 -08:00
hailin 01ff873264 fix(mining-admin): use Prisma relationMode=prisma for CDC sync tables
Switch to Prisma's "prisma" relation mode to handle CDC event ordering issues.
This mode emulates foreign key relations at the Prisma Client layer instead of
creating database-level FK constraints, which is the recommended approach for
CDC scenarios where event arrival order cannot be guaranteed.

Reference: https://www.prisma.io/docs/orm/prisma-schema/data-model/relations/relation-mode

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 08:33:21 -08:00
hailin ea789f7fec fix(mining-admin): remove CDC sync table foreign key constraints
CDC events arrive asynchronously and order is not guaranteed.
Child records (referrals, accounts) may arrive before parent (users).
This follows CDC best practices: destination tables should not have FK constraints.

Reference: https://estuary.dev/blog/cdc-done-correctly/

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 08:24:10 -08:00
hailin 40fbdec47c fix: add migration_lock.toml for prisma migrations
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 08:09:34 -08:00
hailin e337a1dda4 feat(mining-admin): add migration for contribution records and network progress tables
- Add synced_contribution_records table for tracking contribution ledger
- Add synced_network_progress table for tracking network-wide stats
- Revert Dockerfile to use prisma migrate deploy

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 08:07:16 -08:00
hailin 1c33dd7bf3 fix(mining-admin): auto-sync schema on container startup
- Change Dockerfile to use `prisma db push` instead of `migrate deploy`
- Add publish steps for contribution records and network progress in full-reset
- This ensures new tables are created automatically when schema changes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 08:03:38 -08:00
hailin bf5a16939f fix(mining-admin-service): ignore Debezium heartbeat messages
- Add isHeartbeatMessage to detect heartbeat messages (only have ts_ms field)
- Skip processing for heartbeat messages to avoid unnecessary warnings

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 07:44:27 -08:00
hailin 30e1867eb0 fix(mining-admin-service): properly handle Debezium outbox CDC events
- Add isDebeziumOutboxEvent to detect outbox table CDC messages
- Add handleDebeziumOutboxEvent to extract service event from payload.after
- Fix CDC consumer not recognizing events from contribution-service outbox

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 07:39:27 -08:00
hailin 52c573d507 fix(contribution-service): auto-publish contribution records on calculation
- Change saveMany to return saved records with IDs
- Update saveDistributionResult to use saved records for event publishing
- Contribution records are now automatically synced to mining-admin-service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 07:32:50 -08:00
hailin 04fd7b946a feat(mining-admin-web): update contribution records display to match backend API
- Update ContributionRecord type to match backend response fields (sourceType, baseContribution, distributionRate, etc.)
- Update contribution-records-list component with improved UI showing source type badges, user info, tree count, and expiry status

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 07:30:00 -08:00
hailin dbe9ab223f feat(contribution): fix pending fields update and add network progress tracking
- Fix updateContribution to properly update levelXPending and bonusTierXPending fields
- Add NetworkAdoptionProgress and DailyContributionRate tables for tracking contribution coefficient
- Create ContributionRateService for dynamic rate calculation (base 22617, +0.3% per 100 trees after 1000)
- Add ContributionRecordSynced and NetworkProgressUpdated events for CDC sync
- Add admin endpoints for network progress query and contribution records publishing
- Update mining-admin-service to sync contribution records and network progress

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 07:26:32 -08:00
hailin c0d0088b8e feat(contribution-service): enhance CDC event logging for debugging
Add detailed [CDC] prefixed logs to all CDC handlers:
- cdc-consumer.service.ts: log message parsing, handler dispatch
- user-synced.handler.ts: log user sync operations with field details
- adoption-synced.handler.ts: log adoption sync and contribution calc
- referral-synced.handler.ts: log referral relationship sync

All logs use consistent [CDC] prefix for easy filtering.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:41:24 -08:00
hailin 9642901710 fix(mining-wallet-service): remove remaining blockchain references
- Remove HOT_WALLET and COLD_WALLET from initializeCoreAccounts
- Remove BLOCKCHAIN from counterpartyType union

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:34:46 -08:00
hailin 8e30438433 refactor(mining-wallet-service): remove KAVA blockchain integration
- Remove KavaBlockchainService and blockchain.repository
- Remove BlockchainIntegrationService and BlockchainController
- Update health controller to remove blockchain check
- Clean up Prisma schema (remove blockchain models and enums)
- Add migration to drop blockchain-related tables

This functionality will be re-implemented when needed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:31:30 -08:00
hailin 025cc6871b fix(mining-wallet-service): 修复模块依赖注入问题
将 Kafka consumers 从 InfrastructureModule 移到 ApplicationModule,
因为 consumers 依赖 application 层的服务 (ContributionWalletService, SystemAccountService)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:20:32 -08:00
hailin 7fe954e563 feat(contribution/wallet): 实现贡献值2.0计算与钱包存储架构
主要变更:
- contribution-service: 添加省市字段到认种同步数据
- contribution-service: 实现分配结果发布服务,通过Outbox模式发布到Kafka
- contribution-service: 更新Outbox调度器,支持4小时最大退避重试
- mining-wallet-service: 添加贡献值消费者,处理分配结果入账
- mining-wallet-service: 添加用户注册消费者,自动创建钱包
- mining-wallet-service: 添加贡献值过期调度器
- mining-wallet-service: 系统账户添加contributionBalance字段

Kafka事件流:
- contribution.distribution.completed: 分配结果事件
- auth.user.registered: 用户注册事件

可靠性保证:
- Outbox模式确保事件可靠发布
- 4小时幂等退避策略(30s,1m,2m,5m,10m,30m,1h,2h,4h)
- Redis+DB双重幂等检查

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 06:13:18 -08:00
hailin 1b8791fe5d fix(contribution-service): 添加 unlockedBonusTiers 字段到同步事件
事件和 API 返回中缺少 unlockedBonusTiers 字段,导致
mining-admin-service 无法正确显示团队奖励解锁状态

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 05:09:01 -08:00
hailin 180e5ad057 feat(mining-admin): 重构算力构成展示,添加解锁状态
- 后端添加 unlockedBonusTiers 字段同步
- 前端算力构成卡片展示层级解锁(L1-15)和团队奖励解锁(3档)状态
- 移除无用的系统运营/省级/市级字段

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 04:59:51 -08:00
hailin 4ca4fc9135 fix(mining-admin-web): 适配planting-ledger后端返回数据格式
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 04:12:22 -08:00
hailin bc191791e8 fix(mining-admin-service): getPlantingLedger从synced_adoptions读取真实数据
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 04:02:28 -08:00
hailin 9a34e9d399 feat(mining-admin-web): 引荐关系改为树形可视化布局
- 仿照1.0 admin-web的树形结构
- 显示引荐人链(向上)、总部节点、当前用户
- 递归展开/收起直推下级
- 圆形+-按钮控制展开

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:55:51 -08:00
hailin c141c3f6cd fix: TypeScript null check for originalUserId
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:50:29 -08:00
hailin 9e9a7364b9 fix(mining-admin-service): 实现getReferralTree返回真实推荐关系数据
- 从synced_referrals和synced_adoptions获取数据
- 实现getAncestors获取向上引荐人链
- 实现getDirectReferrals获取直推下级
- 实现getUserAdoptionStats获取认种统计

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:48:59 -08:00
hailin 2025c6ce36 fix(mining-admin): 用户列表API添加认种统计和推荐人信息
- 后端getUsers添加批量查询认种统计和推荐人信息
- 后端formatUserListItem返回adoption和referral字段
- 前端transformUserOverview映射新字段

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:42:54 -08:00
hailin 3074748d15 fix(mining-admin-web): 修复用户详情数据映射 - 正确映射referral/adoption/team字段
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:37:40 -08:00
hailin 5ad71e2e4b fix(mining-admin-service): 用户列表API添加nickname字段
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:29:38 -08:00
hailin 5cff606e87 feat(mining-admin-service): 完善用户详情API返回字段
- getUserDetail 添加以下字段:
  - nickname: 昵称
  - referral: 推荐人信息 (referrerAccountSequence, referrerNickname, depth)
  - adoption: 认种统计 (personalAdoptionCount, directReferralAdoptions, teamAdoptions)
  - team: 团队统计 (directReferralCount, teamMemberCount)

- 从 synced_referrals 表获取推荐关系
- 从 synced_adoptions 表统计认种数量
- 通过 ancestorPath 计算团队成员和团队认种

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:11:19 -08:00
hailin 7b310c554b fix(migrations): 修复数据库迁移脚本语法
- 移除 IF NOT EXISTS,使用标准 Prisma 迁移格式
- 确保 full-reset 能正确执行迁移

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:07:14 -08:00
hailin 4635fea693 chore(migrations): 添加数据库迁移脚本
- auth-service: 20260112110000_add_nickname_to_synced_legacy_users
  - synced_legacy_users 表添加 nickname 字段

- mining-admin-service: 20260112110000_add_referral_adoption_nickname
  - synced_users 表添加 nickname 字段
  - 创建 synced_referrals 表 (推荐关系)
  - 创建 synced_adoptions 表 (认种记录)
  - 相关索引和外键约束

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:02:55 -08:00
hailin 30b04c6376 feat(sync): 完善 CDC 数据同步 - 添加推荐关系、认种记录和昵称字段
- auth-service:
  - SyncedLegacyUser 表添加 nickname 字段
  - LegacyUserMigratedEvent 添加 nickname 参数
  - CDC consumer 同步 nickname 字段
  - SyncedLegacyUserData 接口添加 nickname

- contribution-service:
  - 新增 ReferralSyncedEvent 事件类
  - 新增 AdoptionSyncedEvent 事件类
  - admin.controller 添加 publish-all APIs:
    - POST /admin/referrals/publish-all
    - POST /admin/adoptions/publish-all

- mining-admin-service:
  - SyncedUser 表添加 nickname 字段
  - 新增 SyncedReferral 表 (推荐关系)
  - 新增 SyncedAdoption 表 (认种记录)
  - handleReferralSynced 处理器
  - handleAdoptionSynced 处理器
  - handleLegacyUserMigrated 处理 nickname

- deploy-mining.sh:
  - full_reset 更新为 14 步
  - Step 13: 发布推荐关系
  - Step 14: 发布认种记录

解决 mining-admin-web 缺少昵称、推荐人、认种数据的问题

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:48:15 -08:00
hailin 11eb1f8a04 fix(postgres): 增加数据库最大连接数到 300
- max_connections: 100 -> 300
- max_replication_slots: 10 -> 20
- max_wal_senders: 10 -> 20

支持更多服务和 Debezium connectors 同时连接

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:29:35 -08:00
hailin a4e1859fd2 fix(debezium): 修复 outbox connector 配置中的数据库凭证
使用实际的用户名和密码替代环境变量占位符,
因为 envsubst 不支持带默认值的变量语法

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:13:07 -08:00
hailin 93c9007045 fix(deploy): 修正 Debezium Connect 默认端口为 8084
docker-compose 中 Debezium Connect 映射到 8084 端口

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:11:19 -08:00
hailin cbdb449533 fix(auth): 修复 LegacyUserCdcConsumer 的 OutboxService 依赖注入
- 在 ApplicationModule 中导出 OutboxService
- 在 InfrastructureModule 中使用 forwardRef 导入 ApplicationModule
- 解决循环依赖问题

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:00:21 -08:00
hailin 4cbdf0b503 fix(auth): 修复 CDC consumer 类型错误
使用 ?? 运算符正确处理可选字段:
- update 使用 undefined 保持字段不变
- create 使用 null 明确设置为空值

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:45:10 -08:00