Skip to content

Bump @toon-protocol/client to 0.26.0 and switch Money tab reads to the real getClaimState() - #113

Merged
ALLiDoizCode merged 1 commit into
mainfrom
sandcastle/issue-108
Aug 4, 2026
Merged

Bump @toon-protocol/client to 0.26.0 and switch Money tab reads to the real getClaimState()#113
ALLiDoizCode merged 1 commit into
mainfrom
sandcastle/issue-108

Conversation

@toon-backlog-bot

Copy link
Copy Markdown

Bumps @toon-protocol/client to 0.26.0 and switches the Money tab's claim-state reads from the mock/stub to the real getClaimState().

Part of #108

This PR was produced by the sandcastle agent:implement runner and is awaiting human review.

🤖 Generated with Claude Code

Task: buzz#108. The version bump half was already done by buzz#74's PR
#107 (main carries @toon-protocol/client@^0.26.0 and the pnpm
minimumReleaseAgeExclude entry) — per the issue's own re-scope comments,
this lands only the remaining read-path work.

Key decisions:
- Deleted ToonPaidWriter's hand-rolled `ClaimStateReadResult` stand-in and
  imported the real `ClaimStateResult` type from `@toon-protocol/client`
  (type-only import — no runtime cost, matches this module's "lazy heavy
  import" discipline). `tryClaimState`'s narrowing logic (`result.ok` /
  `result.depositTotal`) was already structurally correct against the
  hand-rolled type and needed no behavior change against the real one.
- `RawNetworkFlowStatus` gains `creditedBaseUnits`, fed by
  `tryClaimState`. Per `@toon-protocol/client`'s own "Earning" docs,
  earnings net off-chain onto the SAME channel's claim watermark — there
  is no separate earned ledger — so `cumulativeClaimed` can read below
  zero once an identity is credited more than it has spent.
  `tryClaimState` splits that signed watermark into the two non-negative
  buckets `agentNetworkFlow.ts`'s `spendable = deposit − owed + credited`
  (toon-meta#262 decision 9) already expects, rather than making every
  caller re-interpret a signed "owed". The local-fallback path always
  reports `creditedBaseUnits: 0n` — this client's own tracked watermark
  only knows what it spent, never a connector-applied credit.
- `networkSpendState.ts` now passes `input.raw.creditedBaseUnits` through
  instead of hardcoding `0n`; updated its stale comment (previously said
  "no income source is wired") and `agentNetworkFlow.ts`'s module doc
  (previously said the claim-state read "is not yet vendored" against
  the 0.25.1 pin) — both now correctly describe income RATE
  (`incomeRateBaseUnitsPerSec`/`incomeSampleCount`) as the remaining
  unwired gap, not the credited balance itself.

Files changed: desktop/src/shared/api/toonPaidWriter.ts (+test),
desktop/src/features/profile/lib/{networkSpendState.ts (+test),
agentNetworkFlow.ts (doc only)}.

Verified: fmt-check, desktop-tauri-fmt-check, clippy (workspace,
-D warnings), test-unit (864 tests), desktop-check, desktop-test (4331
passed), desktop-build, web-check, web-build — all green.

Blockers/notes for next iteration: income RATE tracking
(incomeRateBaseUnitsPerSec/incomeSampleCount in agentNetworkFlow.ts's
NetworkFlowRead) is still unwired — no live event feed exists for inbound
payments, only networkSpendLiveStore.ts's outbound onPaidWrite — so
runway still degrades to burn-only until a caller measures income over
time. This is a separate, real gap from this ticket's balance-side
creditedBaseUnits wiring, not something this ticket's AC asked for.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Claude Sonnet 5 <noreply@anthropic.com>
@ALLiDoizCode
ALLiDoizCode merged commit 9fed5d4 into main Aug 4, 2026
42 of 44 checks passed
ALLiDoizCode pushed a commit that referenced this pull request Aug 4, 2026
* RALPH: earning badge on AgentIdentityCard, close out net-flow Money tab (buzz#86)

Task: #86, part of the agent-fleet-money epic
(toon-meta#262 decision 9). Per the issue's own re-dispatch comment,
AC1/AC2 (income beside spend, income-aware runway) landed in PR #97
(agentNetworkFlow.ts) and were wired to real data in #108/#106 (PR #113,
#106). AC4 (suppress the low-funds alert for a self-funding agent) was
already implemented and tested by buzz#76/PR #111 —
`deriveAgentFleetRunwayBadge` returns no badge once `deriveNetworkRunway`
concludes an agent is self-funding, which flows straight through
`countLowFundsAgents`/`shouldShowSidebarLowFundsCard` — confirmed via the
existing "self-funding agents show no badge" test, no code change needed.
This lands the one true remaining gap: AC3, an earning indicator on
`AgentIdentityCard` in the Agents grid.

Key decisions:
- New `isAgentFleetEarning(state: NetworkSpendState): boolean`
  (agentFleetRunway.ts) wraps `agentNetworkFlow.ts`'s `isEarning` behind
  the same `state.kind !== "quoted"` gate `deriveAgentFleetRunwayBadge`
  already uses, so the earning badge and the low-funds suppression share
  one trusted-income bar and can never disagree about whether an agent
  is self-funding.
- New `useAgentFleetEarningBadges` hook mirrors
  `useAgentFleetRunwayBadges`'s `isSelf`-only gate exactly (same
  documented buzz#79 ADR 0006 gap — no per-agent channel read exists for
  any identity but the one this desktop process itself pays as). Kept as
  its own hook rather than folding into the existing runway hook: the
  runway hook's `Map<pubkey, AgentFleetRunwayBadge>` return type is
  consumed as-is by two call sites (`UnifiedAgentsSection.tsx`,
  `SidebarLowFundsCard.tsx`), and `SidebarLowFundsCard.tsx` has no need
  for earning state, so widening its shape would be churn for one
  consumer's benefit.
- `AgentStatusBadge` (the card's single-warning slot, `UnifiedAgentsSection.tsx`)
  gets a third, lowest-priority branch: operational issues, then a
  low-funds runway warning, then "Earning" (success-variant badge,
  `TrendingUp` icon) — same slot, no layout change. The three are
  mutually exclusive in practice (self-funding agents never carry a
  runway badge), but priority order is defensive.

Files changed: desktop/src/features/agents/lib/{agentFleetRunway.ts (+3
tests),useAgentFleetEarningBadges.ts (new)},
desktop/src/features/agents/ui/UnifiedAgentsSection.tsx.

Verified: fmt-check, desktop-tauri-fmt-check, clippy (workspace,
-D warnings), test-unit (864 tests), desktop-check, desktop-test (4334
passed), desktop-build, web-check, web-build — all green.

Blockers/notes for next iteration: the earning badge is wired but inert
against real data today — `networkSpendState.ts`'s `deriveNetworkSpendState`
hardcodes `incomeRateBaseUnitsPerSec: 0`/`incomeSampleCount: 0` (no live
inbound-payment event feed exists yet, only `networkSpendLiveStore.ts`'s
outbound `onPaidWrite` — documented in agentNetworkFlow.ts's module doc
since PR #113), so `isEarning`/`isAgentFleetEarning` cannot return true
from a real read until that income-rate feed lands. This is the same
documented, pre-existing gap AC1/AC2's runway already ships ahead of, not
new scope this ticket introduces.

Signed-off-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: toon-backlog-bot[bot] <294337193+toon-backlog-bot[bot]@users.noreply.github.com>

* Dedupe fleet-status hooks: one useNetworkSpend read for badges + earning

UnifiedAgentsSection called useAgentFleetRunwayBadges and the new
useAgentFleetEarningBadges together, each independently calling
useNetworkSpend(true)/useIdentityQuery and duplicating the same
isSelf-matching loop — doubling the connector fetch on every mount.
Fold both into useAgentFleetStatus, which computes runway badges and
the earning set from a single self-spend read; useAgentFleetRunwayBadges
becomes a thin wrapper so SidebarLowFundsCard is unaffected.

Signed-off-by: toon-backlog-bot[bot] <294337193+toon-backlog-bot[bot]@users.noreply.github.com>

---------

Signed-off-by: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: toon-backlog-bot[bot] <294337193+toon-backlog-bot[bot]@users.noreply.github.com>
Co-authored-by: toon-backlog-bot[bot] <294337193+toon-backlog-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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