Skip to content

Conversation

@pedroanastacio
Copy link
Member

@pedroanastacio pedroanastacio commented Jan 15, 2026

Description

  • The balance and transaction cache was only updating after a few minutes, which meant that the UI had incorrect data until the cache was updated.

Summary

  • Adds endpoint (/user/check-balances/) to check balances of all predicates related to user and emit socket event if the cached balances are different from the blockchain balance
  • Adds endpoint (/predicate/check-balances/:predicateId) to check balances of the given predicate and emit socket event if the cached balances are different from the blockchain balance
  • Adds socket events to notify the UI when the balance and transaction caches are updated
    • BALANCE_OUTDATED_USER
    • BALANCE_OUTDATED_PREDICATE
  • Adds util function (compareBalances) to compare cached balances with blockchain balances

Checklist

  • I reviewed my PR code before submitting
  • I ensured that the implementation is working correctly and did not impact other parts of the app
  • I mentioned the PR link in the task

Copy link
Member

@guimroque guimroque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review - Summary

What was done

  • Added two new endpoints to check balance differences between cache and blockchain:
    • /user/check-balances/ - checks all predicates for a user
    • /predicate/check-balances/:predicateId - checks specific predicate
  • Added socket events BALANCE_OUTDATED_USER and BALANCE_OUTDATED_PREDICATE to notify UI when cache is updated
  • Added compareBalances utility function to detect balance changes
  • Added getBalancesFromBlockchain method to ProviderWithCache for direct blockchain queries
  • Implemented cache invalidation and update logic when balance changes are detected

Positive Points

  • Good separation of concerns with dedicated service methods
  • Proper error handling with try/catch blocks
  • Uses existing authentication and permission middlewares
  • Implements proper TypeScript interfaces
  • Good use of Promise.all for concurrent balance checks
  • Includes safety limit (MAX_PREDICATES_TO_CHECK_BALANCE = 50)
  • Proper cache invalidation strategy

Issues Found

  • Missing input validation for predicateId parameter
  • Potential performance issues with concurrent database queries
  • Console.log statements should be removed
  • Missing error context in some catch blocks
  • Socket event naming inconsistency

Total comments: 5 (1 critical, 3 important, 1 suggestion)

@pedroanastacio pedroanastacio requested review from guimroque and removed request for guimroque January 15, 2026 19:02
@guimroque guimroque requested review from guimroque and removed request for guimroque January 15, 2026 20:15
Copy link
Member

@guimroque guimroque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

Previous issues have been fixed. Code approved.

@pedroanastacio pedroanastacio merged commit 3344f3a into staging Jan 15, 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.

3 participants