Skip to content

Fix castVote in api.ts — vote transactions are simulated but never signed or submitted #502

Description

@PrincessnJoy

Description

The castVote function in frontend/src/api.ts simulates the transaction against Soroban RPC but never signs or submits it. As a result, every vote action in the UI silently appears to succeed (no error is thrown) but no transaction is ever broadcast to the network — votes are never recorded on-chain.

Additionally, the function uses a dummy account sequence number instead of fetching the real sequence number from the network, which would cause submission to fail even if signing were added.

// Current (broken) behaviour in api.ts
const simResult = await server.simulateTransaction(tx);
return simResult;  // ← returns simulation, never submits

The correct flow is:

  1. Build the transaction with the wallet's real public key and sequence number
  2. Simulate to get the footprint and fee
  3. Assemble the transaction with simulation results
  4. Send to the wallet for signing (Freighter / xBull)
  5. Submit the signed transaction via server.sendTransaction
  6. Poll server.getTransaction until the status is SUCCESS or FAILED

Acceptance Criteria

  • castVote fetches the real account sequence number from Soroban RPC before building the transaction
  • After simulation, the assembled transaction is sent to the connected wallet (Freighter / xBull) for signing using WalletContext
  • The signed transaction is submitted via server.sendTransaction
  • The function polls server.getTransaction until a terminal state (SUCCESS or FAILED) and returns the result
  • Errors from the wallet (user rejection) and from the network (contract revert) are surfaced to the UI as distinct error types
  • The vote confirmation toast/modal reflects the on-chain result, not the simulation result
  • Unit tests cover the happy path and at minimum: wallet rejection, contract revert, network timeout
  • The same fix is applied to any other write operations in api.ts (e.g., createProposal) that share the same pattern

Related

Priority

Critical — votes cannot be cast. Core feature is completely broken.

Estimated Effort

Medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions