@onekeyfe/hwk-ledger-adapter 1.2.8-alpha.122 → 1.2.8-alpha.123

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.d.mts CHANGED
@@ -541,8 +541,8 @@ declare class LedgerConnectorBase implements IConnector {
541
541
  protected _emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
542
542
  /**
543
543
  * Return a per-call ctx with the chain's Ledger app name pre-bound to
544
- * wrapError, so chain handlers don't need to repeat `{ defaultAppName: 'X' }`
545
- * at every catch site. Falls through unchanged for unknown methods.
544
+ * UI prompts and wrapError, so chain handlers don't need to repeat the name.
545
+ * Falls through unchanged for unknown methods.
546
546
  */
547
547
  private _ctxForMethod;
548
548
  private _wrapError;
package/dist/index.d.ts CHANGED
@@ -541,8 +541,8 @@ declare class LedgerConnectorBase implements IConnector {
541
541
  protected _emit<K extends ConnectorEventType>(event: K, data: ConnectorEventMap[K]): void;
542
542
  /**
543
543
  * Return a per-call ctx with the chain's Ledger app name pre-bound to
544
- * wrapError, so chain handlers don't need to repeat `{ defaultAppName: 'X' }`
545
- * at every catch site. Falls through unchanged for unknown methods.
544
+ * UI prompts and wrapError, so chain handlers don't need to repeat the name.
545
+ * Falls through unchanged for unknown methods.
546
546
  */
547
547
  private _ctxForMethod;
548
548
  private _wrapError;
package/dist/index.js CHANGED
@@ -1043,6 +1043,7 @@ var _LedgerAdapter = class _LedgerAdapter {
1043
1043
  // need to subscribe in one place. The AppInstallProgress variant re-keys
1044
1044
  // sessionId to connectId via `_sessions`, and drops if no mapping exists.
1045
1045
  this.uiEventForwarder = (event) => {
1046
+ const operationId = this._activeOperationId();
1046
1047
  if (event.type === import_hwk_adapter_core4.EConnectorInteraction.AppInstallProgress) {
1047
1048
  let connectId;
1048
1049
  for (const [cid, sid] of this._sessions) {
@@ -1071,6 +1072,7 @@ var _LedgerAdapter = class _LedgerAdapter {
1071
1072
  this._installProgressLastEmittedValue = progress;
1072
1073
  this.emitter.emit("ui-event", {
1073
1074
  type: import_hwk_adapter_core4.EConnectorInteraction.AppInstallProgress,
1075
+ ...operationId ? { operationId } : {},
1074
1076
  payload: {
1075
1077
  connectId,
1076
1078
  appName,
@@ -1079,7 +1081,7 @@ var _LedgerAdapter = class _LedgerAdapter {
1079
1081
  });
1080
1082
  return;
1081
1083
  }
1082
- this.emitter.emit("ui-event", event);
1084
+ this.emitter.emit("ui-event", operationId ? { ...event, operationId } : event);
1083
1085
  };
1084
1086
  this.connector = connector;
1085
1087
  this._defaultAutoInstallApp = options?.autoInstallApp ?? false;
@@ -2069,12 +2071,6 @@ var _LedgerAdapter = class _LedgerAdapter {
2069
2071
  } else {
2070
2072
  this._jobQueue.cancelActiveAndPending(void 0, userAbortReason);
2071
2073
  }
2072
- if (resolvedConnectId) {
2073
- const sessionId = this._sessions.get(resolvedConnectId) ?? resolvedConnectId;
2074
- void this.connector.cancel(sessionId);
2075
- } else {
2076
- for (const sid of this._sessions.values()) void this.connector.cancel(sid);
2077
- }
2078
2074
  const connectingConnectId = this._connectingConnectId;
2079
2075
  const targetKeys = new Set(
2080
2076
  [
@@ -2084,6 +2080,14 @@ var _LedgerAdapter = class _LedgerAdapter {
2084
2080
  ].filter(Boolean)
2085
2081
  );
2086
2082
  const ownsPendingConnect = !connectId || activeJobId !== void 0 && queueKeys.has(activeJobId) || connectingConnectId !== void 0 && targetKeys.has(connectingConnectId);
2083
+ if (activeJobId === void 0 || ownsPendingConnect) {
2084
+ if (resolvedConnectId) {
2085
+ const sessionId = this._sessions.get(resolvedConnectId) ?? resolvedConnectId;
2086
+ void this.connector.cancel(sessionId);
2087
+ } else {
2088
+ for (const sid of this._sessions.values()) void this.connector.cancel(sid);
2089
+ }
2090
+ }
2087
2091
  if (this._connectingPromise && ownsPendingConnect) {
2088
2092
  this._doConnectAbortController?.abort(userAbortReason);
2089
2093
  }
@@ -2266,7 +2270,7 @@ var _LedgerAdapter = class _LedgerAdapter {
2266
2270
  } catch (err) {
2267
2271
  this.emitter.emit(import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW, {
2268
2272
  type: import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW,
2269
- payload: {}
2273
+ payload: { operationId }
2270
2274
  });
2271
2275
  throw Object.assign(new Error("User cancelled Ledger connection"), {
2272
2276
  _tag: ERROR_TAG.UserAborted,
@@ -2330,7 +2334,7 @@ var _LedgerAdapter = class _LedgerAdapter {
2330
2334
  } catch (err) {
2331
2335
  this.emitter.emit(import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW, {
2332
2336
  type: import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW,
2333
- payload: {}
2337
+ payload: { operationId }
2334
2338
  });
2335
2339
  return false;
2336
2340
  }
@@ -2368,7 +2372,7 @@ var _LedgerAdapter = class _LedgerAdapter {
2368
2372
  } catch (err) {
2369
2373
  this.emitter.emit(import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW, {
2370
2374
  type: import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW,
2371
- payload: {}
2375
+ payload: { operationId }
2372
2376
  });
2373
2377
  return false;
2374
2378
  }
@@ -3164,7 +3168,7 @@ var _LedgerAdapter = class _LedgerAdapter {
3164
3168
  }
3165
3169
  this.emitter.emit(import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW, {
3166
3170
  type: import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW,
3167
- payload: {}
3171
+ payload: { operationId }
3168
3172
  });
3169
3173
  return await this._runConnectorCall(
3170
3174
  resolvedConnectId,
@@ -3231,7 +3235,7 @@ var _LedgerAdapter = class _LedgerAdapter {
3231
3235
  if (err?._tag === import_hwk_adapter_core4.UI_REQUEST_PREEMPTED_TAG) {
3232
3236
  this.emitter.emit(import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW, {
3233
3237
  type: import_hwk_adapter_core4.UI_REQUEST.CLOSE_UI_WINDOW,
3234
- payload: {}
3238
+ payload: { operationId }
3235
3239
  });
3236
3240
  throw Object.assign(new Error("Device permission request superseded"), {
3237
3241
  _tag: ERROR_TAG.UserAborted,
@@ -4968,6 +4972,14 @@ var METHOD_PREFIX_TO_APP_NAME = {
4968
4972
  tron: "Tron",
4969
4973
  zcash: "Zcash"
4970
4974
  };
4975
+ function withOpenAppName(event, data, appName) {
4976
+ if (event !== "ui-event") return data;
4977
+ const uiEvent = data;
4978
+ if (uiEvent.type !== import_hwk_adapter_core13.EConnectorInteraction.ConfirmOpenApp || uiEvent.payload.appName) {
4979
+ return data;
4980
+ }
4981
+ return { ...uiEvent, payload: { ...uiEvent.payload, appName } };
4982
+ }
4971
4983
  var HARDWARE_ERROR_CODE_VALUES = new Set(
4972
4984
  Object.values(import_hwk_adapter_core13.HardwareErrorCode).filter((value) => typeof value === "number")
4973
4985
  );
@@ -5776,8 +5788,8 @@ var LedgerConnectorBase = class {
5776
5788
  // ---------------------------------------------------------------------------
5777
5789
  /**
5778
5790
  * Return a per-call ctx with the chain's Ledger app name pre-bound to
5779
- * wrapError, so chain handlers don't need to repeat `{ defaultAppName: 'X' }`
5780
- * at every catch site. Falls through unchanged for unknown methods.
5791
+ * UI prompts and wrapError, so chain handlers don't need to repeat the name.
5792
+ * Falls through unchanged for unknown methods.
5781
5793
  */
5782
5794
  _ctxForMethod(method) {
5783
5795
  const prefix = /^(evm|btc|sol|tron|zcash)/.exec(method)?.[1];
@@ -5785,7 +5797,8 @@ var LedgerConnectorBase = class {
5785
5797
  if (!defaultAppName) return this._ctx;
5786
5798
  return {
5787
5799
  ...this._ctx,
5788
- wrapError: (err, opts) => this._wrapError(err, { defaultAppName, ...opts })
5800
+ wrapError: (err, opts) => this._wrapError(err, { defaultAppName, ...opts }),
5801
+ emit: (event, data) => this._ctx.emit(event, withOpenAppName(event, data, defaultAppName))
5789
5802
  };
5790
5803
  }
5791
5804
  _wrapError(err, opts) {