On this page
Cancel Request
Overview
cancel(connectId) cancels queued and active SDK requests associated with that connection and closes pending SDK UI. Omitting connectId cancels all pending requests. Use it when the user cancels a PIN/passphrase prompt, leaves the flow, or reaches an application timeout.
Method
HardwareSDK.cancel(connectId);
// Cancel all pending requests:
HardwareSDK.cancel();Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
connectId | string | No | Target connection; omit to cancel all pending requests. |
Return Value
cancel() returns void. Await the original method’s Promise to observe its result. The public SDK normally resolves a cancelled request with success: false; queue cancellation uses HardwareErrorCode.CallQueueActionCancelled (822). A device-side rejection or an error that wins a race with cancellation can return a different code. Do not match error-message text or assume every cancellation has the same code.
Examples
Basic cancellation
import type { EVMSignTransactionParams } from '@onekeyfe/hd-core';
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
// Use a fully prepared transaction from your application's transaction builder.
declare const params: EVMSignTransactionParams;
const signPromise = HardwareSDK.evmSignTransaction(connectId, deviceId, params);
// Invoke from the user's Cancel action.
HardwareSDK.cancel(connectId);
const result = await signPromise;
if (!result.success) {
if (result.payload.code === HardwareErrorCode.CallQueueActionCancelled) {
// Close the cancelled operation's UI.
} else {
throw new Error(result.payload.error);
}
}Cancel with timeout
This timer cancels all pending requests on the selected connection, so serialize operations per device.
import type { EVMSignTransactionParams } from '@onekeyfe/hd-core';
async function signWithTimeout(
connectId: string,
deviceId: string,
params: EVMSignTransactionParams,
timeoutMs = 60_000,
) {
const timer = setTimeout(() => HardwareSDK.cancel(connectId), timeoutMs);
try {
return await HardwareSDK.evmSignTransaction(connectId, deviceId, params);
} finally {
clearTimeout(timer);
}
}Cancel vs. transport teardown
Cancellation interrupts the operation and may trigger device/link cleanup. It does not guarantee that the connection remains usable or that a new call can start immediately. Await the original result; if the link was lost, rediscover the device and refresh getDeviceState before a new user action. Do not automatically replay signing or firmware updates.
Use HardwareSDK.dispose() when tearing down the SDK or switching transports, then init() before further use. A physical disconnect is reported through DEVICE.DISCONNECT; pending public method calls return failure results.
See Disconnects and reconnection and Error Codes.