@onekeyfe/hd-web-sdk 0.0.3 → 0.0.4

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.
@@ -13946,7 +13946,10 @@ const createErrorMessage = error => ({
13946
13946
 
13947
13947
  const UI_EVENT = 'UI_EVENT';
13948
13948
  const UI_REQUEST$1 = {
13949
- REQUEST_PIN: 'ui-request_pin'
13949
+ REQUEST_PIN: 'ui-request_pin',
13950
+ INVALID_PIN: 'ui-invalid_pin',
13951
+ REQUEST_BUTTON: 'ui-button',
13952
+ CLOSE_UI_WINDOW: 'ui-close_window'
13950
13953
  };
13951
13954
 
13952
13955
  const createUiMessage = (type, payload) => ({
@@ -13987,6 +13990,7 @@ const createUiResponse = (type, payload) => ({
13987
13990
  payload
13988
13991
  });
13989
13992
 
13993
+ const DEVICE_EVENT = 'DEVICE_EVENT';
13990
13994
  const DEVICE = {
13991
13995
  CONNECT: 'device-connect',
13992
13996
  CONNECT_UNACQUIRED: 'device-connect_unacquired',
@@ -14006,6 +14010,12 @@ const DEVICE = {
14006
14010
  WORD: 'word'
14007
14011
  };
14008
14012
 
14013
+ const createDeviceMessage = (type, payload) => ({
14014
+ event: DEVICE_EVENT,
14015
+ type,
14016
+ payload
14017
+ });
14018
+
14009
14019
  const assertType = (res, resType) => {
14010
14020
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
14011
14021
 
@@ -17341,6 +17351,9 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17341
17351
  Log.debug('Call API - setDevice: ', device);
17342
17352
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
17343
17353
  device.on(DEVICE.PIN, onDevicePinHandler);
17354
+ device.on(DEVICE.BUTTON, (d, code) => {
17355
+ onDeviceButtonHandler(d, code);
17356
+ });
17344
17357
 
17345
17358
  try {
17346
17359
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -17383,6 +17396,9 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
17383
17396
  method.dispose();
17384
17397
  }
17385
17398
  }
17399
+
17400
+ closePopup();
17401
+ cleanup();
17386
17402
  }
17387
17403
  });
17388
17404
 
@@ -17446,6 +17462,15 @@ function initDeviceForBle(method) {
17446
17462
  return device;
17447
17463
  }
17448
17464
 
17465
+ const cleanup = () => {
17466
+ _uiPromises = [];
17467
+ Log.debug('Cleanup...');
17468
+ };
17469
+
17470
+ const closePopup = () => {
17471
+ postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
17472
+ };
17473
+
17449
17474
  const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, void 0, void 0, function* () {
17450
17475
  console.log('onDevicePinHandler');
17451
17476
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PIN, device);
@@ -17457,6 +17482,15 @@ const onDevicePinHandler = (...[device, type, callback]) => __awaiter(void 0, vo
17457
17482
  callback(null, uiResp.payload);
17458
17483
  });
17459
17484
 
17485
+ const onDeviceButtonHandler = (...[device, request]) => {
17486
+ postMessage(createDeviceMessage(DEVICE.BUTTON, Object.assign(Object.assign({}, request), {
17487
+ device: device.toMessageObject()
17488
+ })));
17489
+ postMessage(createUiMessage(UI_REQUEST$1.REQUEST_BUTTON, {
17490
+ device: device.toMessageObject()
17491
+ }));
17492
+ };
17493
+
17460
17494
  const postMessage = message => {
17461
17495
  _core.emit(CORE_EVENT, message);
17462
17496
  };
@@ -17564,6 +17598,7 @@ __webpack_unused_export__ = CORE_EVENT;
17564
17598
  __webpack_unused_export__ = Core;
17565
17599
  __webpack_unused_export__ = DEFAULT_PRIORITY;
17566
17600
  __webpack_unused_export__ = DEVICE;
17601
+ __webpack_unused_export__ = DEVICE_EVENT;
17567
17602
  __webpack_unused_export__ = DataManager;
17568
17603
  exports.Sg = errors;
17569
17604
  exports.Bg = IFRAME;
@@ -17573,6 +17608,7 @@ __webpack_unused_export__ = UI_REQUEST$1;
17573
17608
  __webpack_unused_export__ = UI_RESPONSE;
17574
17609
  __webpack_unused_export__ = corsValidator;
17575
17610
  exports.Ue = create;
17611
+ __webpack_unused_export__ = createDeviceMessage;
17576
17612
  exports.xG = createErrorMessage;
17577
17613
  __webpack_unused_export__ = createIFrameMessage;
17578
17614
  __webpack_unused_export__ = createResponseMessage;