Feat: Add new balance breakdown apis#87
Conversation
|
|
@codex please trigger manual review |
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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 👍 / 👎.
ed7f1db to
1585e44
Compare
There was a problem hiding this comment.
💡 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'; |
There was a problem hiding this comment.
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 👍 / 👎.
1585e44 to
b3ba699
Compare
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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 👍 / 👎.
|
@codex please do all reviews at once |
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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 👍 / 👎.
b3ba699 to
6ab0e59
Compare
This PR attends to issue #76.
(getBalanceBreakdown, getBalancesBreakdown, getTrustedBalancesBreakdown).Thank you @Egge21M for the well detailed issue description, it helped a lot. Kindly review
Closes #76