Skip to content

feat: add gas estimation display before transaction submission #797

Description

@sanmipaul

Summary

Before users sign any Soroban transaction, the Astera frontend should simulate the transaction and display the estimated gas cost (in XLM). Currently, users have no way to know the cost until the Freighter wallet shows the fee — at which point they've already invested time in filling out forms.

Desired Behavior

On any action form (create invoice, deposit, fund invoice, repay), after the user has filled in all fields:

  1. Frontend calls `sorobanRpc.simulateTransaction()` to get the compute units
  2. Estimated fee shown below the submit button:
    ```
    Estimated network fee: ~0.00123 XLM
    [Sign & Submit]
    ```
  3. If simulation fails (e.g., insufficient collateral), show the error inline before the user signs

Implementation

```ts
// frontend/hooks/useTransactionSimulation.ts
export function useTransactionSimulation(operation: xdr.Operation) {
return useQuery({
queryKey: ['simulate', operation],
queryFn: async () => {
const server = new SorobanRpc.Server(horizonUrl);
const result = await server.simulateTransaction(buildTx(operation));
if (SorobanRpc.Api.isSimulationError(result)) throw new Error(result.error);
return result;
},
enabled: !!operation,
});
}
```

Acceptance Criteria

  • Transaction simulation runs when user fills in all required fields
  • Estimated fee displayed in XLM and USD equivalent
  • Simulation errors shown inline (e.g., "Insufficient collateral")
  • Loading spinner shown during simulation
  • Submit button disabled until simulation completes (or shows warning if skipped)
  • Unit test: simulation error → inline error message shown

References

  • `frontend/components/` — form components
  • Soroban RPC: `simulateTransaction()`

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfrontendNext.js frontend work

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions