feat(frontend): add transaction simulation and preview#463
Open
devEunicee wants to merge 1 commit into
Open
Conversation
) - 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsSimulationErrorclass — extendsErrorwith the raw RPC response; thrown specifically for contract-level simulation rejections, distinct from network/connection failuressimulateWriteCall(sender, contractId, method, args)— generic helper that builds a transaction, runs it throughserver.simulateTransaction(), and returns aSimulationPreview(fee in stroops, decoded return value) or throwsSimulationErrorsimulateCastVote(voter, proposalId, vote)— convenience wrapper for cast_votesimulateCreateProposal(...)— convenience wrapper for create_proposalfrontend/src/components/VoteSimulationPreview.tsx(new)simulateCastVotewith the connected walletrole="status"/role="alert"witharia-livefrontend/src/components/ProposalDetail.tsxVoteSimulationPreviewwhen wallet is connected, proposal is Active, and user has not yet votedError handling
SimulationErrorError