@onekeyfe/hwk-ledger-adapter 1.2.8-alpha.50 → 1.2.8-alpha.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -914,7 +914,7 @@ var _LedgerAdapter = class _LedgerAdapter {
914
914
  type: SDK.OPERATION_ENDED,
915
915
  payload: { operationId: operation.operationId, reason }
916
916
  });
917
- if (reason === "timeout") {
917
+ if (reason === "timeout" && !this._bareCallMayUseConnection(operation)) {
918
918
  void this._releaseOperationConnection(operation);
919
919
  }
920
920
  }
@@ -1458,7 +1458,7 @@ var _LedgerAdapter = class _LedgerAdapter {
1458
1458
  const operation = this._operations.findActive(operationId);
1459
1459
  if (operation) this._cancelOperationWork(operation);
1460
1460
  const endedOperation = this._operations.release(operationId);
1461
- if (!endedOperation) return;
1461
+ if (!endedOperation || this._bareCallMayUseConnection(endedOperation)) return;
1462
1462
  const { connectId } = endedOperation;
1463
1463
  debugLog("[LedgerAdapter][REQ]", {
1464
1464
  method: "releaseOperation",
@@ -1496,6 +1496,15 @@ var _LedgerAdapter = class _LedgerAdapter {
1496
1496
  this._uiRegistry.cancel(void 0, void 0, operationId);
1497
1497
  void this.connector.cancel(this._sessions.get(operation.connectId) ?? operation.connectId);
1498
1498
  }
1499
+ /**
1500
+ * A running call by bare connectId (or still resolving its device by identity) may be on this
1501
+ * connection, e.g. waiting for an unlock; its later stages need it, so it stays cached for that
1502
+ * caller like any bare call's session. A lost connection is torn down regardless.
1503
+ */
1504
+ _bareCallMayUseConnection(operation) {
1505
+ const activeKey = this._jobQueue.getActiveJob()?.deviceId;
1506
+ return activeKey !== void 0 && !isHardwareOperationId(activeKey) && (activeKey === operation.connectId || activeKey === LEDGER_DEFAULT_QUEUE_KEY || operation.connectionKeys.includes(activeKey));
1507
+ }
1499
1508
  async _releaseOperationConnection(operation) {
1500
1509
  const sessionIds = /* @__PURE__ */ new Set();
1501
1510
  for (const [connectId, sessionId] of this._sessions) {
@@ -2017,11 +2026,19 @@ var _LedgerAdapter = class _LedgerAdapter {
2017
2026
  } else {
2018
2027
  for (const sid of this._sessions.values()) void this.connector.cancel(sid);
2019
2028
  }
2020
- if (this._connectingPromise) {
2029
+ const connectingConnectId = this._connectingConnectId;
2030
+ const targetKeys = new Set(
2031
+ [
2032
+ connectId,
2033
+ resolvedConnectId,
2034
+ ...pendingOperationId ? this._operations.find(pendingOperationId)?.connectionKeys ?? [] : []
2035
+ ].filter(Boolean)
2036
+ );
2037
+ const ownsPendingConnect = !connectId || activeJobId !== void 0 && queueKeys.has(activeJobId) || connectingConnectId !== void 0 && targetKeys.has(connectingConnectId);
2038
+ if (this._connectingPromise && ownsPendingConnect) {
2021
2039
  this._doConnectAbortController?.abort(userAbortReason);
2022
2040
  }
2023
- const connectingConnectId = this._connectingConnectId;
2024
- if (connectingConnectId) void this.connector.cancel(connectingConnectId);
2041
+ if (connectingConnectId && ownsPendingConnect) void this.connector.cancel(connectingConnectId);
2025
2042
  }
2026
2043
  // ---------------------------------------------------------------------------
2027
2044
  // Chain fingerprint