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
- Implement an optimistic mutation queue where each mutation has states: idle → pending → confirmed | failed.
- On submit(data): immediately apply optimistically, call onChainSubmit(data), mark confirmed on success or failed on failure with onRollback(data) to revert.
- Expose rollback(mutationId) that manually reverts a pending mutation.
- Expose retry(mutationId) that re-submits a failed mutation.
- 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
Scope
File:
src/hooks/useEscrow.tsProblem
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
Resolution Strategy
Tags
hooks, optimism, rollback, contract