Repository navigation
feat(hooks): add useHighValueCargoApproval hook for multi-sig transactions - #910
Merged
johdanike merged 2 commits intoSep 30, 2026
Merged
Conversation
…tions
- Add cargoApprovalService for GET /api/escrow/{id}/approvals and
POST /api/escrow/{id}/approvals/signatures, mapping 403/409/410 to
typed error codes
- Add CargoApproval types with weighted signers and approval window
- Add useHighValueCargoApproval hook: resolves signers and weights,
verifies the weighted threshold, checks the connected wallet is an
authorized signer that has not signed, signs via Freighter and exposes
isThresholdMet for submit enablement
- Block signing once the approval window expires, whether reported by
the backend or reached while the view is open
- Add service and hook unit tests
|
@AdaBliss Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
closes #792
Summary
Adds
useHighValueCargoApproval, a hook that manages the multi-signature approval flow for high-value cargo escrows. It resolves signers and weights, verifies the weighted threshold, checks signer authorization, collects the signature through Freighter, and handles expired approval windows. It follows the Component -> Hook -> Service pattern.Changes
services/cargoApprovalService.ts(new)getApproval(escrowId)callsGET /api/escrow/{escrowId}/approvals.submitSignature(escrowId, { signerPublicKey, signedTransactionXdr })callsPOST /api/escrow/{escrowId}/approvals/signatures.CargoApprovalServiceError, mapping HTTP 403 / 409 / 410 tounauthorized_signer/already_signed/expired.types/cargoApproval.ts(new): the approval shape, with weighted signers, threshold, transaction envelope, window end and status.hooks/useHighValueCargoApproval.ts(new)signers: each signer withweight,approved,signedAtandisCurrentUser.currentWeightis the sum of signed weights, following Stellar threshold semantics.isThresholdMetis true when that weight reaches the threshold or the service reportsthreshold_met/executed. It is intended for submit enablement.isAuthorizedSignerchecks the connected wallet against the signer set. Before signing, the Freighter account is re-checked against the connected wallet.hasSignedblocks a second signature. A 409 from the backend shows an info toast and resyncs.expired, when the deadline is already past, or when the deadline passes while the view is open. The last case uses a single timer, not a ticking interval. A 410 from the backend shows an error toast and resyncs.canSignandsignBlockedReason(wallet_disconnected,unauthorized,already_signed,threshold_met,expired,closed) let the UI explain why signing is disabled.Tests
services/__tests__/cargoApprovalService.test.ts: endpoints, path encoding, envelope handling, status-code mapping.hooks/__tests__/useHighValueCargoApproval.test.tsx: signer list with approved status, weighted threshold accuracy, authorized and unauthorized signers, Freighter account mismatch, signing flow, already-signed state (local and 409), expired windows (reported, past deadline, deadline passing live, 410).Fixtures live under
hooks/__tests__/fixturesand use valid, checksummed Stellar public keys. The hook and service contain no inline mock data.Checks
pnpm type-checkcurrently fails onmainbecause of parse errors inapp/page.tsxandcomponents/escrow/__tests__/CheckoutFlow.keyboard.test.tsx, which this PR does not touch.pnpm test: this PR adds no new failing suites. The suites that fail onmainare unchanged.Note for maintainers
Open PR #901 (for the multi-sig modal issue) also creates
hooks/useHighValueCargoApproval.ts, with a modal-specific contract: risk acknowledgement, countdown and a count-based threshold. The two PRs will conflict on that file. This PR follows the #792 spec: weighted signers from the escrow service, authorized-signer validation,isThresholdMet, and expired-window handling.Screenshots
Unit test run output is included above.