Skip to content

fix: balance display#3155

Merged
brianp merged 7 commits intotari-project:build-feat/walletfrom
shanimal08:fix/balance
Mar 6, 2026
Merged

fix: balance display#3155
brianp merged 7 commits intotari-project:build-feat/walletfrom
shanimal08:fix/balance

Conversation

@shanimal08
Copy link
Collaborator

@shanimal08 shanimal08 commented Feb 23, 2026

Description

  • remove BalanceCalculator and the calculations from balance changes
  • use the account balance directly from db
  • add small temporary value for total directly after an outgoing transaction

Motivation and Context

How Has This Been Tested?

  • locally

Breaking Changes

  • None
  • Requires data directory on base node to be deleted
  • Requires hard fork
  • Other - Please specify

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @shanimal08, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the wallet's balance management system. The primary goal is to streamline how balances are calculated and displayed by moving away from an internal calculation mechanism to directly leveraging the database's AccountBalance state. This change aims to improve accuracy and reduce complexity in balance reporting, with corresponding updates made to the user interface to reflect these new data sources.

Highlights

  • Balance Management Refactor: The custom BalanceCalculator and its associated error handling have been removed, simplifying the balance tracking logic. The system now directly uses the account balance retrieved from the database.
  • Direct Database Balance Usage: Wallet balance updates now directly fetch and utilize the AccountBalance from the database, eliminating intermediate calculations within the application logic.
  • Temporary Total Balance Adjustment: A small temporary adjustment is applied to the total balance immediately after an outgoing transaction, providing quicker feedback to the user before full block processing.
  • Frontend Balance Display Updates: Frontend components responsible for displaying wallet balances have been updated to align with the new account_balance structure, ensuring consistency across the application.
  • Dependency Update: The syn dependency in Cargo.lock has been updated from version 2.0.115 to 2.0.116.
Changelog
  • Cargo.lock
    • Updated 'syn' dependency to version 2.0.116.
  • src-tauri/src/commands.rs
    • Reordered import statement for 'BalanceTracker'.
  • src-tauri/src/events.rs
    • Removed 'AccountBalance' and 'MicroMinotari' imports.
    • Removed the 'WalletBalanceUpdatePayload' struct definition.
  • src-tauri/src/events_emitter.rs
    • Removed 'WalletBalanceUpdatePayload' from imports.
    • Added 'AccountBalance' import.
    • Modified 'emit_wallet_balance_update' function to directly accept 'AccountBalance' as payload.
  • src-tauri/src/wallet/minotari_wallet/balance_tracker/balance_calculator.rs
    • Removed the 'BalanceCalculator' file.
  • src-tauri/src/wallet/minotari_wallet/balance_tracker/errors.rs
    • Removed the 'errors.rs' file.
  • src-tauri/src/wallet/minotari_wallet/balance_tracker/mod.rs
    • Removed module imports for 'balance_calculator' and 'errors'.
    • Removed 'DisplayedTransaction' and 'WalletBalanceUpdatePayload' imports.
    • Changed 'EMPTY_BALANCE' to be a public static variable.
    • Removed the 'current_balance' field from the 'BalanceTracker' struct.
    • Simplified the 'init_balance' method to directly use 'AccountBalance' and emit it.
    • Removed the 'get_balance' method.
    • Refactored 'update_from_transactions' to remove transaction-based calculations and directly update from an optional 'AccountBalance'.
    • Updated 'emit_balance' to directly accept 'AccountBalance'.
  • src-tauri/src/wallet/minotari_wallet/mod.rs
    • Added import for 'EMPTY_BALANCE' from 'balance_tracker'.
    • Added import for 'MicroMinotari'.
    • Updated 'send_transaction' to calculate a temporary total balance after an outgoing transaction and use the new balance update mechanism.
    • Modified transaction scanning logic to use the simplified 'update_from_transactions' method.
  • src/components/transactions/send/SendForm.tsx
    • Updated balance retrieval to use 'accountBalance' from the wallet store instead of 'balance'.
  • src/components/wallet/components/balance/WalletBalance.tsx
    • Updated balance display logic to use 'accountBalance' from the wallet store.
  • src/hooks/app/useTauriEventsListener.ts
    • Added a debug log for 'WalletBalanceUpdate' events.
  • src/store/actions/miningStoreActions.ts
    • Removed the 'restartMining' asynchronous function.
  • src/store/actions/walletStoreActions.ts
    • Removed 'WalletBalanceExtended' import.
    • Added 'AccountBalance' import.
    • Added 'deepEqual' utility import.
    • Updated 'setWalletBalance' to accept 'AccountBalance' directly and use 'deepEqual' for comparison.
  • src/store/useWalletStore.test.ts
    • Updated balance state tests to reflect the change from 'balance' and 'calculated_balance' to 'account_balance'.
  • src/store/useWalletStore.ts
    • Removed 'WalletBalanceExtended' interface.
    • Replaced 'balance' and 'calculated_balance' fields with a single 'account_balance' field in 'WalletStoreState'.
  • src/types/app-status.ts
    • Removed the 'WalletBalance' interface.
  • src/types/backend-state.ts
    • Added 'AccountBalance' import.
    • Removed 'WalletBalanceExtended' import.
    • Updated the payload type for 'WalletBalanceUpdate' events to 'AccountBalance'.
  • src/types/tapplets/TappletSigner.ts
    • Replaced 'WalletBalance' import with 'AccountBalance' import.
    • Updated the 'getTariBalance' method to return 'AccountBalance' and map its fields accordingly.
Activity
  • The pull request is currently marked as 'Work In Progress' (WIP).
  • The author has indicated that logs are still present and need to be addressed.
  • Further work is planned to add another call to retrieve the balance from the database after new blocks are processed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot 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

This pull request refactors the balance tracking logic to rely on the database as the source of truth, removing the client-side BalanceCalculator. This is a great simplification that improves robustness. The changes on the frontend to adapt to the new account_balance state are also well-executed. I've left a few comments on areas that could be further simplified or made more robust, particularly around the temporary balance update after a transaction and handling of optional balance updates. There's also a leftover debug log on the frontend that should be removed before merging.

@shanimal08 shanimal08 changed the title fix: balance [wip] fix: balance display Mar 6, 2026
@shanimal08 shanimal08 marked this pull request as ready for review March 6, 2026 08:22
@brianp brianp merged commit 56a20ac into tari-project:build-feat/wallet Mar 6, 2026
14 checks passed
@shanimal08 shanimal08 deleted the fix/balance branch March 6, 2026 10:59
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.

2 participants