Skip to content

feat: implement optimistic mutation queue with automatic rollback and… - #34

Merged
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
Jess52487:feature/use-escrow-optimism
Jun 20, 2026
Merged

feat: implement optimistic mutation queue with automatic rollback and…#34
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
Jess52487:feature/use-escrow-optimism

Conversation

@Jess52487

Copy link
Copy Markdown
Contributor

closes #21

Description
This pull request implements an optimistic mutation queue for Stellar/Soroban contract interactions to prevent the UI from remaining stuck during block confirmations (which usually take 3–5 seconds) or when transactions are dropped/fail.

Key Changes
Optimistic State Queue: Modified useEscrow hook to support a history stack of mutations in states: idle | pending | confirmed | failed.
History Cap: Configured state history to keep at most 50 entries, rolling off older mutations.
Timestamps: Added submittedAt and confirmedAt Unix timestamps on all mutation objects.
Automatic Rollback: Intercepts onChainSubmit failure to immediately execute the onRollback(data) hook and update status to failed.
Prevent Duplicate Rollbacks: Implemented useRef<Set> tracking of active pending mutation IDs. If a mutation has already been cancelled or handled, duplicate rollbacks are prevented.
Manual Rollback (rollback): Cancels a pending mutation by clearing it from active tracking, invoking onRollback, and setting status to idle.
Retry Mechanism (retry): Allows re-submission of failed mutations, reviving the mutation state back to pending.

@elizabetheonoja-art elizabetheonoja-art left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@elizabetheonoja-art
elizabetheonoja-art merged commit b134e9e into Utility-Protocol:main Jun 20, 2026
3 checks passed
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.

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

2 participants