API ReferenceReact provider and hooksFunction
useCancelLOCsAndWithdrawWorkflow()
function useCancelLOCsAndWithdrawWorkflow(): UseCancelLOCsAndWithdrawWorkflowResult;Validates and prepares a sequential cancel-and-withdraw: cancel the listed LOCs, then withdraw the collateral they release.
Omitting withdrawalAmount withdraws the signer’s full execution-time available balance. An
explicit amount is capped at that balance plus the collateral released by already-expired,
signer-owned reservations in the listed LOCs. Domain validation and construction stay owned by
sdk.loc.
Returns
UseCancelLOCsAndWithdrawWorkflowResult
The canonical preparation envelope. validate reports a verdict without building anything;
prepareWorkflow validates and then builds, resolving to prepared, invalid, failed, or
cancelled; workflow, issues, error, and isPreparing mirror the latest request; and reset
discards it. No wallet is prompted until workflow.execute().
Throws
Error when rendered outside <AnvilProvider>, by way of useAnvilSDK. Nothing else
throws: a rejected validation or build is reported as a failed result, not as an exception.
Example
export function ReclaimCollateralButton({ locIDs }: { locIDs: bigint[] }) { const { prepareWorkflow, error, isPreparing } = useCancelLOCsAndWithdrawWorkflow();
async function reclaim() { // Omitting `withdrawalAmount` withdraws the full available balance the // cancellations release, resolved at execution time. const result = await prepareWorkflow({ tokenAddress: USDC, locIDs }); if (result.status === 'prepared') await result.workflow.execute(); }
return ( <> <button onClick={reclaim} disabled={isPreparing}> Cancel and withdraw </button> {error && <p>{error.message}</p>} </> );}