Skip to content

feat(frontend): add transaction simulation and preview#463

Open
devEunicee wants to merge 1 commit into
PrincessnJoy:mainfrom
devEunicee:feature/288-transaction-simulation-preview
Open

feat(frontend): add transaction simulation and preview#463
devEunicee wants to merge 1 commit into
PrincessnJoy:mainfrom
devEunicee:feature/288-transaction-simulation-preview

Conversation

@devEunicee

Copy link
Copy Markdown
Contributor

Summary

Closes #288

Users and developers can now preview a vote transaction — including the estimated fee — before submitting it on-chain. Simulation errors (e.g. already voted, proposal inactive) are shown with distinct styling so users understand whether a failure is a contract-level rejection or a network problem.

Changes

frontend/src/api.ts

  • SimulationError class — extends Error with the raw RPC response; thrown specifically for contract-level simulation rejections, distinct from network/connection failures
  • simulateWriteCall(sender, contractId, method, args) — generic helper that builds a transaction, runs it through server.simulateTransaction(), and returns a SimulationPreview (fee in stroops, decoded return value) or throws SimulationError
  • simulateCastVote(voter, proposalId, vote) — convenience wrapper for cast_vote
  • simulateCreateProposal(...) — convenience wrapper for create_proposal

frontend/src/components/VoteSimulationPreview.tsx (new)

  • Radio buttons to select Yes / No / Abstain
  • Simulate button that calls simulateCastVote with the connected wallet
  • Success panel: shows estimated fee in XLM (converted from stroops)
  • Contract-rejection panel (yellow): distinct message explaining the transaction would fail on-chain
  • Network-error panel (red): generic RPC/connection failure message
  • Accessible: role="status" / role="alert" with aria-live

frontend/src/components/ProposalDetail.tsx

  • Imports and renders VoteSimulationPreview when wallet is connected, proposal is Active, and user has not yet voted

Error handling

Error type Source Display
SimulationError Contract rejected the simulated call Yellow warning panel
Error Network / RPC failure Red error panel
Success Simulation returned a result Green success panel with fee

)

- Add SimulationError class to api.ts — distinct from real tx failures
- Add simulateWriteCall() helper: builds and simulates a state-changing
  transaction against the RPC node, returns SimulationPreview with
  estimated fee in stroops; throws SimulationError on contract rejection
  vs plain Error on network/RPC failure
- Add simulateCastVote() and simulateCreateProposal() convenience wrappers
- Add VoteSimulationPreview component: radio group for Yes/No/Abstain,
  Simulate button, success panel (estimated fee), contract-rejection
  panel (yellow, distinct styling), network-error panel (red)
- Integrate VoteSimulationPreview into ProposalDetail — shown when
  wallet is connected, proposal is Active, and user has not yet voted

Closes PrincessnJoy#288
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.

Add support for local transaction simulation and preview

1 participant