Skip to content

Wallets service balances#662

Merged
portableDD merged 4 commits into
Nexacore-Org:mainfrom
MaryammAli:WalletsService-balances
May 30, 2026
Merged

Wallets service balances#662
portableDD merged 4 commits into
Nexacore-Org:mainfrom
MaryammAli:WalletsService-balances

Conversation

@MaryammAli
Copy link
Copy Markdown
Contributor

Persist Wallet Balances Using TypeORM

Overview

This PR replaces the in-memory wallet balance storage implementation with persistent database-backed storage using TypeORM entities and repositories.

Problem Addressed

The current WalletsService stores balances in a plain in-memory Map, causing all wallet data to be lost whenever the application restarts, crashes, or scales horizontally.

This creates a critical data-loss issue for the wallet system and makes balances unreliable in any real deployment environment.

Changes Made

  • Added a new WalletBalance TypeORM entity with the following fields:

    • id
    • accountId
    • currency
    • balance
    • createdAt
    • updatedAt
  • Refactored WalletsService to use InjectRepository(WalletBalance) for all balance operations.

  • Replaced in-memory balance handling with persistent database reads/writes.

  • Implemented transactional adjustBalance updates with optimistic locking to prevent race conditions and concurrent update inconsistencies.

  • Replaced:

    • getBalance
    • getBalancesForAccount

    with TypeORM-backed queries.

  • Added TypeOrmModule.forFeature([WalletBalance]) to the wallet module.

  • Added a TypeORM migration for wallet balance persistence.

  • Added unit tests covering:

    • balance persistence
    • concurrent updates
    • retrieval queries
    • transactional behavior

Key Files Updated

  • src/wallet/wallets.service.ts
  • src/wallet/wallets.types.ts
  • src/wallet/wallets.module.ts
  • New WalletBalance entity and migration files

Acceptance Criteria

  • Wallet balances persist across application restarts.
  • adjustBalance operations are atomic and concurrency-safe.
  • Existing wallet service methods pass unit tests against a test database.
  • TypeORM migration file is included in the PR.

Notes

WalletsService-balances
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@MaryammAli Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@portableDD
Copy link
Copy Markdown
Contributor

@MaryammAli please resolve conflict

@MaryammAli
Copy link
Copy Markdown
Contributor Author

@portableDD
conflict resolved

@MaryammAli
Copy link
Copy Markdown
Contributor Author

@portableDD
conflict resolved

@portableDD portableDD merged commit 85a9331 into Nexacore-Org:main May 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Wave 200pts] WalletsService: balances are stored in-memory Map — all wallet data lost on every restart

2 participants