@onekeyfe/hd-ble-sdk 0.1.5 → 0.1.6

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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _onekeyfe_hd_core from '@onekeyfe/hd-core';
2
- import { Deferred } from '@onekeyfe/hd-core';
2
+ import { Deferred } from '@onekeyfe/hd-shared';
3
3
 
4
4
  declare const messagePromises: {
5
5
  [key: number]: Deferred<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAoB,EAYlB,QAAQ,EAMT,MAAM,mBAAmB,CAAC;AAa3B,eAAO,MAAM,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAO,CAAC;AA2GpE,QAAA,MAAM,cAAc,qCAOlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAA0B,QAAQ,EAAqB,MAAM,qBAAqB,CAAC;AAU1F,eAAO,MAAM,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAO,CAAC;AAwGpE,QAAA,MAAM,cAAc,qCAOlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var HardwareSdk = require('@onekeyfe/hd-core');
6
+ var hdShared = require('@onekeyfe/hd-shared');
6
7
  var ReactNativeTransport = require('@onekeyfe/hd-transport-react-native');
7
8
 
8
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -523,7 +524,7 @@ const dispose = () => {
523
524
  };
524
525
  const uiResponse = (response) => {
525
526
  if (!_core) {
526
- throw HardwareSdk.ERRORS.TypedError('Init_NotInitialized');
527
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NotInitialized);
527
528
  }
528
529
  const { type, payload } = response;
529
530
  _core.handleMessage({ event: HardwareSdk.UI_EVENT, type, payload });
@@ -551,11 +552,11 @@ function handleMessage(message) {
551
552
  function postMessage(message, usePromise = true) {
552
553
  return __awaiter(this, void 0, void 0, function* () {
553
554
  if (!_core) {
554
- throw HardwareSdk.ERRORS.TypedError('Runtime', 'postMessage: _core not found');
555
+ throw hdShared.ERRORS.TypedError('postMessage: _core not found');
555
556
  }
556
557
  if (usePromise) {
557
558
  _messageID++;
558
- messagePromises[_messageID] = HardwareSdk.create();
559
+ messagePromises[_messageID] = hdShared.createDeferred();
559
560
  const response = yield _core.handleMessage(Object.assign(Object.assign({}, message), { id: `${_messageID}` }));
560
561
  return response;
561
562
  }
@@ -584,17 +585,16 @@ const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
584
585
  if (response) {
585
586
  Log.debug('response: ', response);
586
587
  if (!response.success) {
587
- if ((typeof response.payload === 'string' && response.payload.includes(ReactNativeTransport.PERMISSION_ERROR)) ||
588
- ((_a = response.payload.error) === null || _a === void 0 ? void 0 : _a.includes(ReactNativeTransport.PERMISSION_ERROR))) {
588
+ if (((_a = response.payload) === null || _a === void 0 ? void 0 : _a.code) === hdShared.HardwareErrorCode.BlePermissionError) {
589
589
  postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
590
590
  }
591
- if ((_b = response.payload.error) === null || _b === void 0 ? void 0 : _b.includes(ReactNativeTransport.LOCATION_ERROR)) {
591
+ if (((_b = response.payload) === null || _b === void 0 ? void 0 : _b.code) === hdShared.HardwareErrorCode.BleLocationError) {
592
592
  postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.LOCATION_PERMISSION), false);
593
593
  }
594
594
  }
595
595
  return response;
596
596
  }
597
- return HardwareSdk.createErrorMessage(HardwareSdk.ERRORS.TypedError('Call_NotResponse'));
597
+ return HardwareSdk.createErrorMessage(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNotResponse));
598
598
  }
599
599
  catch (error) {
600
600
  Log.error('__call error: ', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-ble-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "ISC",
@@ -20,8 +20,9 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-core": "^0.1.5",
24
- "@onekeyfe/hd-transport-react-native": "^0.1.5"
23
+ "@onekeyfe/hd-core": "^0.1.6",
24
+ "@onekeyfe/hd-shared": "^0.1.6",
25
+ "@onekeyfe/hd-transport-react-native": "^0.1.6"
25
26
  },
26
- "gitHead": "26a2b960d5e1917d3f2217cef449269200a1a376"
27
+ "gitHead": "ebe2789fa24cbfb798c9be445678e71e67e33d71"
27
28
  }
package/src/index.ts CHANGED
@@ -10,18 +10,13 @@ import HardwareSdk, {
10
10
  createUiMessage,
11
11
  CORE_EVENT,
12
12
  CoreMessage,
13
- ERRORS,
14
- Deferred,
15
- create as createDeferred,
16
13
  IFRAME,
17
14
  UI_EVENT,
18
15
  UiResponseEvent,
19
16
  UI_REQUEST,
20
17
  } from '@onekeyfe/hd-core';
21
- import ReactNativeTransport, {
22
- PERMISSION_ERROR,
23
- LOCATION_ERROR,
24
- } from '@onekeyfe/hd-transport-react-native';
18
+ import { ERRORS, createDeferred, Deferred, HardwareErrorCode } from '@onekeyfe/hd-shared';
19
+ import ReactNativeTransport from '@onekeyfe/hd-transport-react-native';
25
20
 
26
21
  const eventEmitter = new EventEmitter();
27
22
  const Log = initLog('@onekey/hd-ble-sdk');
@@ -39,7 +34,7 @@ const dispose = () => {
39
34
 
40
35
  const uiResponse = (response: UiResponseEvent) => {
41
36
  if (!_core) {
42
- throw ERRORS.TypedError('Init_NotInitialized');
37
+ throw ERRORS.TypedError(HardwareErrorCode.NotInitialized);
43
38
  }
44
39
  const { type, payload } = response;
45
40
  _core.handleMessage({ event: UI_EVENT, type, payload });
@@ -70,7 +65,7 @@ function handleMessage(message: CoreMessage) {
70
65
 
71
66
  async function postMessage(message: CoreMessage, usePromise = true) {
72
67
  if (!_core) {
73
- throw ERRORS.TypedError('Runtime', 'postMessage: _core not found');
68
+ throw ERRORS.TypedError('postMessage: _core not found');
74
69
  }
75
70
 
76
71
  if (usePromise) {
@@ -112,17 +107,14 @@ const call = async (params: any) => {
112
107
  Log.debug('response: ', response);
113
108
 
114
109
  if (!response.success) {
115
- if (
116
- (typeof response.payload === 'string' && response.payload.includes(PERMISSION_ERROR)) ||
117
- response.payload.error?.includes(PERMISSION_ERROR)
118
- ) {
110
+ if (response.payload?.code === HardwareErrorCode.BlePermissionError) {
119
111
  /**
120
112
  * Send message notification when there is no Bluetooth access permission
121
113
  */
122
114
  postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_PERMISSION), false);
123
115
  }
124
116
 
125
- if (response.payload.error?.includes(LOCATION_ERROR)) {
117
+ if (response.payload?.code === HardwareErrorCode.BleLocationError) {
126
118
  postMessage(createUiMessage(UI_REQUEST.LOCATION_PERMISSION), false);
127
119
  }
128
120
  }
@@ -130,7 +122,7 @@ const call = async (params: any) => {
130
122
  return response;
131
123
  }
132
124
 
133
- return createErrorMessage(ERRORS.TypedError('Call_NotResponse'));
125
+ return createErrorMessage(ERRORS.TypedError(HardwareErrorCode.CallMethodNotResponse));
134
126
  } catch (error) {
135
127
  Log.error('__call error: ', error);
136
128
  return createErrorMessage(error);