Skip to content

Design an optimistic UI state reconciler for fractional token swaps with automatic rollback on RPC failure #470

Description

@Damola-Sodiq

Description

Build a sophisticated optimistic mutation layer in React Query that updates token balances instantly upon wallet signature, handling complex rollbacks if the network rejects the transaction.

Architecture & Context

Waiting for blockchain finality destroys the UX of trading fractional assets. The UI must predict the outcome of the trade, update the local cache immediately, and invisibly reconcile the true state once the block closes.

Technical Requirements

  • Intercept tRPC/React Query onMutate hooks to snapshot the previous cache state.
  • Apply the exact fractional math locally to predict the new user balances.
  • Implement onError handlers to cleanly restore the snapshot if the Soroban RPC returns a tx_failed status.

Acceptance Criteria

  • Token balances update to the millisecond the user signs the transaction.
  • Failed transactions gracefully and invisibly revert the UI to the prior true state.
  • Concurrent overlapping optimistic mutations resolve accurately.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions