Skip to content

Feat: Add new balance breakdown apis#87

Open
igbopharaoh wants to merge 5 commits intocashubtc:masterfrom
igbopharaoh:feat/split-balances
Open

Feat: Add new balance breakdown apis#87
igbopharaoh wants to merge 5 commits intocashubtc:masterfrom
igbopharaoh:feat/split-balances

Conversation

@igbopharaoh
Copy link

@igbopharaoh igbopharaoh commented Feb 5, 2026

This PR attends to issue #76.

  • This PR introduces new balance breakdown methods available in WalletApi (getBalanceBreakdown, getBalancesBreakdown, getTrustedBalancesBreakdown).
  • Refactored Internal consumers -- PaymentRequestService and useTrustedBalance to use new balance breakdown Api.
  • Updated docs reflect new methods .
  • Added tests to cover new balance breakdown methods.

Thank you @Egge21M for the well detailed issue description, it helped a lot. Kindly review

Closes #76

@github-project-automation github-project-automation bot moved this to Backlog in coco Feb 5, 2026
@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

⚠️ No Changeset found

Latest commit: 6ab0e59

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@igbopharaoh igbopharaoh marked this pull request as ready for review February 5, 2026 20:25
@Egge21M
Copy link
Collaborator

Egge21M commented Feb 12, 2026

@codex please trigger manual review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed7f1db2c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

trustedBalances[mintUrl] = amount;
trustedBalances.total += amount;
trustedBalances[mintUrl] = breakdown.ready;
trustedBalances.total += breakdown.total;

Choose a reason for hiding this comment

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

P2 Badge Sum trusted total from ready balances only

The hook stores each mint’s trusted balance as breakdown.ready, but total is accumulated from breakdown.total, which includes reserved proofs. When any trusted mint has reserved proofs, balance.total becomes larger than the sum of the per-mint balances and overstates spendable trusted funds in consumers of this hook.

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1585e44c48

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

import { useEffect, useState, useCallback } from 'react';
import { useManager } from '../contexts/ManagerContext';
import { useMints } from '../contexts/MintContext';
import type { BalancesBreakdownByMint } from '../../../../core';

Choose a reason for hiding this comment

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

P1 Badge Import balance type from coco-cashu-core package

Using the relative specifier ../../../../core here makes the React package compiler resolve to packages/core/index.ts (not the published coco-cashu-core types), so packages/react typecheck/build pulls in core source files and fails under the React tsconfig (for example unresolved @core/* imports and stricter flags). This regression is triggered whenever coco-cashu-react is built or typechecked in the monorepo; import the type from coco-cashu-core (or rely on inference from manager.wallet.getBalancesBreakdown()) to keep React isolated from core internals.

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b3ba69961b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const proofs = await this.getAllReadyProofs();
const balances: { [mintUrl: string]: number } = {};
for (const proof of proofs) {
if (proof.usedByOperationId) continue;

Choose a reason for hiding this comment

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

P2 Badge Propagate reservation changes to spendable balance consumers

By skipping proofs with usedByOperationId here, getBalances() now returns spendable-only amounts, but reservation/unreservation does not trigger the events that current React balance consumers subscribe to. I checked packages/react/src/lib/providers/Balance.tsx and packages/react/src/lib/hooks/useTrustedBalance.ts: both refresh on proofs:saved/proofs:state-changed (and mint updates), while reserveProofs/releaseProofs emit proofs:reserved/proofs:released. During send.prepare (which reserves proofs without changing proof state), UI balances can remain stale and overstate spendable funds until a later unrelated event fires.

Useful? React with 👍 / 👎.

@igbopharaoh
Copy link
Author

@codex please do all reviews at once

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b3ba69961b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const proofs = await this.getAllReadyProofs();
const balances: { [mintUrl: string]: number } = {};
for (const proof of proofs) {
if (proof.usedByOperationId) continue;

Choose a reason for hiding this comment

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

P2 Badge Trigger balance updates when proofs are reserved/released

By skipping usedByOperationId proofs here, getBalances() now changes when reservations are created or cleared, but the existing React balance consumers (useBalance in packages/react/src/lib/providers/Balance.tsx and useTrustedBalance in packages/react/src/lib/hooks/useTrustedBalance.ts) only refresh on proofs:saved/proofs:state-changed and do not listen to proofs:reserved/proofs:released; during any pending send/payment-request flow this leaves UI balances stale and can show spendable amounts that no longer match wallet.getBalances() until another unrelated event fires.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Improvement / Feature: Split balances into reserved and ready

2 participants

Comments