@onekeyfe/hd-ble-sdk 0.0.5 → 0.0.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAoB,EAWlB,QAAQ,EAKT,MAAM,mBAAmB,CAAC;AAU3B,eAAO,MAAM,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAO,CAAC;AAuFpE,QAAA,MAAM,cAAc,qCAOlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
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;AAwGpE,QAAA,MAAM,cAAc,qCAOlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -573,11 +573,21 @@ const init = (settings) => __awaiter(void 0, void 0, void 0, function* () {
573
573
  }
574
574
  });
575
575
  const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
576
+ var _a, _b;
576
577
  Log.debug('call: ', params);
577
578
  try {
578
579
  const response = yield postMessage({ event: HardwareSdk.IFRAME.CALL, type: HardwareSdk.IFRAME.CALL, payload: params });
579
580
  if (response) {
580
581
  Log.debug('response: ', response);
582
+ if (!response.success) {
583
+ if ((typeof response.payload === 'string' && response.payload.includes(ReactNativeTransport.PERMISSION_ERROR)) ||
584
+ ((_a = response.payload.error) === null || _a === void 0 ? void 0 : _a.includes(ReactNativeTransport.PERMISSION_ERROR))) {
585
+ postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
586
+ }
587
+ if ((_b = response.payload.error) === null || _b === void 0 ? void 0 : _b.includes(ReactNativeTransport.LOCATION_ERROR)) {
588
+ postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.LOCATION_PERMISSION), false);
589
+ }
590
+ }
581
591
  return response;
582
592
  }
583
593
  return HardwareSdk.createErrorMessage(HardwareSdk.ERRORS.TypedError('Call_NotResponse'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-ble-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.8",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "ISC",
@@ -20,8 +20,8 @@
20
20
  "lint:fix": "eslint . --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@onekeyfe/hd-core": "^0.0.5",
24
- "@onekeyfe/hd-transport-react-native": "^0.0.5"
23
+ "@onekeyfe/hd-core": "^0.0.8",
24
+ "@onekeyfe/hd-transport-react-native": "^0.0.8"
25
25
  },
26
- "gitHead": "24d2a28fd3f2e7fda4c21742e968bce764985615"
26
+ "gitHead": "edfa30382fdf36182bc389c8ff1dd1a689096592"
27
27
  }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import HardwareSdk, {
7
7
  initCore,
8
8
  Core,
9
9
  createErrorMessage,
10
+ createUiMessage,
10
11
  CORE_EVENT,
11
12
  CoreMessage,
12
13
  ERRORS,
@@ -15,8 +16,12 @@ import HardwareSdk, {
15
16
  IFRAME,
16
17
  UI_EVENT,
17
18
  UiResponseEvent,
19
+ UI_REQUEST,
18
20
  } from '@onekeyfe/hd-core';
19
- import ReactNativeTransport from '@onekeyfe/hd-transport-react-native';
21
+ import ReactNativeTransport, {
22
+ PERMISSION_ERROR,
23
+ LOCATION_ERROR,
24
+ } from '@onekeyfe/hd-transport-react-native';
20
25
 
21
26
  const eventEmitter = new EventEmitter();
22
27
  const Log = initLog('@onekey/hd-ble-sdk');
@@ -102,6 +107,23 @@ const call = async (params: any) => {
102
107
  const response = await postMessage({ event: IFRAME.CALL, type: IFRAME.CALL, payload: params });
103
108
  if (response) {
104
109
  Log.debug('response: ', response);
110
+
111
+ if (!response.success) {
112
+ if (
113
+ (typeof response.payload === 'string' && response.payload.includes(PERMISSION_ERROR)) ||
114
+ response.payload.error?.includes(PERMISSION_ERROR)
115
+ ) {
116
+ /**
117
+ * Send message notification when there is no Bluetooth access permission
118
+ */
119
+ postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_PERMISSION), false);
120
+ }
121
+
122
+ if (response.payload.error?.includes(LOCATION_ERROR)) {
123
+ postMessage(createUiMessage(UI_REQUEST.LOCATION_PERMISSION), false);
124
+ }
125
+ }
126
+
105
127
  return response;
106
128
  }
107
129