Skip to content

Open the wallet prompt without waiting for simulation - #333

Open
luchobonatti wants to merge 2 commits into
mainfrom
feat/318-presimulate
Open

luchobonatti wants to merge 2 commits into
mainfrom
feat/318-presimulate

Conversation

@luchobonatti

Copy link
Copy Markdown
Member

Summary

Closes #318

After a click, Freighter waited for getAccount and simulateTransaction (0.5 to over 1 s on testnet). Ready actions are now simulated in the background, and the click signs the simulated transaction when it is still fresh.

Changes

  • The transaction hook keeps one simulated transaction per request (owner, argument, grant), reused within 30 s; a submission, a changed read or expiry drops it and re-simulates while the action stays open
  • The rail reports its expanded action once it is Ready (400 ms after it settles) and releases it when collapsed, blocked or unmounted; hidden tabs and hidden pages prepare nothing
  • The investor page prepares once a valid amount settles
  • A reused transaction is signed and sent through submitSigned; a consumed sequence shows "The transaction went stale" with Try again, and the next click simulates fresh
  • Reused transactions confirm with the on-chain result and show their hash while in flight

Acceptance criteria

  • The console simulates an action when its rail turns Ready; the investor page simulates once the amount is valid
  • A click reuses the simulation when the argument, signer and grant match and it is under 30 s old; otherwise it simulates as today
  • A refetch of the panel's reads drops cached simulations
  • A reused transaction refused for a consumed sequence number drops the cache and says to try again; the next click simulates fresh
  • A background simulation that fails shows nothing; the click reports the failure as today

Test plan

Automated tests

npx vitest run: 1746 tests pass.

Manual verification

On the local network with a local signer, Close epoch, Attest price and Subscribe each reached sendTransaction 46 to 95 ms after the click with no simulateTransaction in between; before, the simulation ran after the click.

Breaking changes

None.

Checklist

  • Self-reviewed my own diff
  • Tests added or updated
  • Docs updated (if applicable)
  • No unrelated changes bundled in

Screenshots

None.

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
strata-vault-kit-app Ready Ready Preview Oct 22, 2026 6:36pm UTC

Request Review

Copilot AI 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.

🔵 Needs a closer look

It reworks the wallet-signing and submission path for every investor and admin action with concurrency-sensitive caching (refs, generation counters, timers, query-cache subscriptions), so despite strong test coverage and no concrete defect found, the risk warrants final human review.

No open issues 🎉

What changed in this PR

This PR removes the perceptible delay between clicking an action and the Freighter wallet prompt. Previously the click triggered getAccount + simulateTransaction (0.5–1 s+ on testnet) before the wallet opened. Now ready actions are simulated in the background, and a click signs the already-simulated transaction (AssembledTransaction.sign() makes no network call) when it is still fresh, falling back to the previous simulate-on-click flow otherwise.

Changes:

  • useContractTransaction gains a usePrepared helper exposing prepare(arg, grant) => Release and take(key): it caches one background-simulated transaction per request (keyed by owner/arg/authority/standing), reuses it for 30 s, and drops it on submit, on a changed matching read, or on expiry; submit consumes the cached tx and signs/sends it via submitSigned.
  • A new { kind: "stale" } failure is surfaced when a reused transaction is refused for a consumed sequence number ("The transaction went stale", with Try again), and the in-flight hash is now shown for reused submissions.
  • The admin rails report their open-and-ready action (400 ms after it settles) through a shared onReady/Send (submitTo/prepareFor) indirection, gated by active; the investor page prepares once a valid amount settles.
File Description
app/​src/​hooks/​useContractTransaction.ts Core change: usePrepared background simulation, prepare/take, reuse on submit, stale failure, early hash.
app/​src/​hooks/​usePendingTransaction.ts Adds prepare passthrough and the Send/Sendable/submitTo/prepareFor dispatch helpers.
app/​src/​hooks/​use*{RequestDeposit,RequestRedeem,Fund,FulfillEpoch,FinalizeWindDownRound,DeployToCustodian,CloseEpoch,ClaimRedeem,ClaimDeposit,CancelRedeem,CancelDeposit,Attest,ActivateWindDown}.ts Add prepare: (...) => Release to each hook's public interface.
app/​src/​pages/​VaultPreview.tsx Prepares the subscribe/redeem hook 400 ms after a valid, in-balance amount settles.
app/​src/​components/​admin/​CycleActionRail.tsx Reports the open ready action via onReady after a 400 ms settle; releases on collapse/block/unmount.
app/​src/​components/​admin/​{Cycle,Emergency,Configuration,Governance,Compliance}Section.tsx Refactor run into dispatch(action, send) and wire onReady (prepare) gated by active.
app/​src/​components/​vault/​TransactionModal.tsx Adds stale failure copy, step state, and Try-again handling.
app/​src/​**/​*.test.{ts,tsx} Extensive new coverage for preparation, reuse, expiry, stale, release, and hidden-tab gating.

Review effort: Balanced

This branch was successfully deployed

1 active deployment
Preview — 4a39e83c Deployed Oct 22, 2026 by vercel[bot]
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.

Open the wallet prompt without waiting for simulation

2 participants