Skip to content

feat(hooks): add splits hooks and optimistic withdraw/cancel updates - #293

Open
gbemi-aro wants to merge 1 commit into
SorobanForge:mainfrom
gbemi-aro:feat/hooks-splits-optimistic
Open

gbemi-aro wants to merge 1 commit into
SorobanForge:mainfrom
gbemi-aro:feat/hooks-splits-optimistic

Conversation

@gbemi-aro

Copy link
Copy Markdown

Summary

Adds the splits data layer that the upcoming /splits page needs, and makes withdraw/cancel feel immediate instead of showing a stale balance until the next refetch.

Closes #201
Closes #202

#201 — splits hooks

  • useSplit / useSplits return the same { data, error, loading, refetch } shape as the stream hooks.
  • useCreateSplit / useDistributeSplit expose pending / success / error state through the shared useContractMutation machine and refetch splits when a transaction confirms.
  • Typed against a structural SplitsClientLike, so the hooks work now and accept a future SplitsClient without changes. Listing degrades to an empty list when listSplits is not available, mirroring useStreams.

#202 — optimistic withdraw/cancel

  • New optimistic.ts overlay: pending ops are kept separately from the last loaded stream and applied on read.
  • Withdraw optimistically increases withdrawn; cancel marks the stream cancelled.
  • Failed transactions remove only their own op, so concurrent mutations on the same stream do not clobber each other.
  • On confirmation, all mounted useStream readers refetch (bypassing the read cache) before the settled op is dropped, so the UI never flickers back to the pre-transaction value.

Tests

  • packages/hooks/src/optimistic.test.ts — success, rollback, cancel, concurrent-mutation independence, withdraw without an amount.
  • packages/hooks/src/splits.test.ts — load, error, listing + creator filter, unsupported client, create/distribute pending/success/error, null client.

Verification

  • pnpm --filter @stellar-starter-kit/hooks test — 34/34 pass
  • pnpm --filter @stellar-starter-kit/hooks typecheck and lint — clean
  • pnpm typecheck (repo-wide turbo) — 18/18 tasks pass
  • Branch merges cleanly into main (no conflicts)

The splits dashboard had no data layer, and a withdraw or cancel left the
displayed stream stale until the next read, which read as a failed write.

Add useSplit/useSplits and create/distribute mutation hooks against a
structural SplitsClientLike, plus an optimistic overlay shared with
useStream so withdraw and cancel update immediately, reconcile on
confirmation, and roll back independently on failure.

Closes SorobanForge#201
Closes SorobanForge#202

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@vercel

vercel Bot commented Oct 29, 2026

Copy link
Copy Markdown

@gbemi-aro is attempting to deploy a commit to the techalhaji's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

feat(hooks): add optimistic updates for withdraw and cancel feat(hooks): add a useSplits hook for the splits dashboard

1 participant