Skip to content

feat(frontend): add Soroban contract invocation hook#181

Merged
Wilfred007 merged 1 commit intoGildado:mainfrom
CMI-James-OD:codex/issue-144-soroban-contract-hook
Feb 26, 2026
Merged

feat(frontend): add Soroban contract invocation hook#181
Wilfred007 merged 1 commit intoGildado:mainfrom
CMI-James-OD:codex/issue-144-soroban-contract-hook

Conversation

@CMI-James
Copy link
Contributor

Description

Add a reusable Soroban contract invocation hook for frontend contract calls.

Closes #144

Changes proposed

What were you told to do?

I was tasked with creating a useSorobanContract(contractId) React hook that abstracts direct Soroban smart-contract invocations for deployed contracts (bulk_payment, vesting_escrow, revenue_split).

Requirements included:

  • Return invoke, loading, error, and result state
  • Run simulateTransaction before every live submission
  • Delegate wallet signing to useWalletSigning
  • Decode on-chain results and return typed data
  • Surface failures via useNotification toast errors

What did I do?

Added a dedicated Soroban invocation hook

Updated frontend/src/hooks/useSorobanContract.ts with:

  • useSorobanContract(contractId) returning invoke, loading, error, and result
  • Generic typed result support via a parseResult callback
  • Contract-method invocation API that accepts method name + args

Integrated pre-flight simulation into invoke flow

Implemented invocation pipeline to:

  • Build contract-call transaction XDR with Contract + TransactionBuilder
  • Simulate the XDR using existing simulateTransaction(...)
  • Block submission and raise error when simulation fails

Wired wallet signing through existing wallet hook

Integrated useWalletSigning by:

  • Preparing transaction with Soroban RPC
  • Signing prepared XDR through sign(...)
  • Rebuilding signed transaction and submitting to Soroban RPC

Added on-chain result decoding and typed return

After submission and confirmation polling:

  • Read return value from successful transaction
  • Decode ScVal via scValToNative
  • Return parsed typed value and tx hash in hook result state

Added robust error surfacing

Hook now:

  • Tracks and exposes error state
  • Emits user-facing toast failures through notifyError(...)
  • Validates disconnected-wallet state before invocation

Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.
  • My commit messages styles matches our requested structure.
  • My code additions will fail neither code linting checks nor unit test.
  • I am only making changes to files I was requested to.

Screenshots / Testing Evidence

  • Ran pnpm lint in frontend/ and no blocking lint errors were reported for this hook (only existing unrelated warning-level checks elsewhere)
  • Ran pnpm build in frontend/ successfully
  • Hook implementation was validated by code inspection against acceptance requirements

@CMI-James CMI-James force-pushed the codex/issue-144-soroban-contract-hook branch from c38461a to bbfb8d2 Compare February 26, 2026 12:01
@Wilfred007 Wilfred007 merged commit 3e2fe91 into Gildado:main Feb 26, 2026
1 check passed
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.

#071: Soroban Contract Invocation Hook

2 participants