Skip to content

Issue 5: Optimistic State Mutators and Rollback Controllers for Contract Adjustments #21

Description

@elizabetheonoja-art

Scope

File: src/hooks/useEscrow.ts

Problem

When users submit tariff updates or fund deposits to Soroban contracts, the 3-5 second block confirmation window leaves the UI in a loading state. If the transaction fails or is dropped, there is no automatic rollback mechanism, leaving the UI in a permanently incorrect state.

Requirements

  1. Implement an optimistic mutation queue where each mutation has states: idle → pending → confirmed | failed.
  2. On submit(data): immediately apply optimistically, call onChainSubmit(data), mark confirmed on success or failed on failure with onRollback(data) to revert.
  3. Expose rollback(mutationId) that manually reverts a pending mutation.
  4. Expose retry(mutationId) that re-submits a failed mutation.
  5. Track pendingCount for UI badge display.

Resolution Strategy

  • useRef<Set> to track active mutations and prevent duplicate rollbacks.
  • Store mutation history in state with max 50 entries.
  • Each mutation carries submittedAt and confirmedAt timestamps.

Tags

hooks, optimism, rollback, contract

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions