@ledgerhq/react-native-hw-transport-ble 6.28.3 → 6.28.4-next.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +17 -0
- package/lib/BleTransport.d.ts +67 -37
- package/lib/BleTransport.d.ts.map +1 -1
- package/lib/BleTransport.js +257 -198
- package/lib/BleTransport.js.map +1 -1
- package/lib/BleTransport.test.d.ts +2 -0
- package/lib/BleTransport.test.d.ts.map +1 -0
- package/lib/BleTransport.test.js +370 -0
- package/lib/BleTransport.test.js.map +1 -0
- package/lib/remapErrors.d.ts +4 -0
- package/lib/remapErrors.d.ts.map +1 -1
- package/lib/remapErrors.js +20 -1
- package/lib/remapErrors.js.map +1 -1
- package/lib/types.d.ts +4 -0
- package/lib/types.d.ts.map +1 -1
- package/lib-es/BleTransport.d.ts +67 -37
- package/lib-es/BleTransport.d.ts.map +1 -1
- package/lib-es/BleTransport.js +257 -198
- package/lib-es/BleTransport.js.map +1 -1
- package/lib-es/BleTransport.test.d.ts +2 -0
- package/lib-es/BleTransport.test.d.ts.map +1 -0
- package/lib-es/BleTransport.test.js +365 -0
- package/lib-es/BleTransport.test.js.map +1 -0
- package/lib-es/remapErrors.d.ts +4 -0
- package/lib-es/remapErrors.d.ts.map +1 -1
- package/lib-es/remapErrors.js +19 -1
- package/lib-es/remapErrors.js.map +1 -1
- package/lib-es/types.d.ts +4 -0
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/BleTransport.test.ts +275 -0
- package/src/BleTransport.ts +250 -172
- package/src/remapErrors.ts +33 -2
- package/src/types.ts +5 -0
package/src/remapErrors.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DisconnectedDevice,
|
|
3
|
+
HwTransportError,
|
|
4
|
+
HwTransportErrorType,
|
|
5
|
+
} from "@ledgerhq/errors";
|
|
6
|
+
import { BleError, BleErrorCode } from "react-native-ble-plx";
|
|
7
|
+
|
|
2
8
|
export const remapError = (error: Error | null | undefined) => {
|
|
3
9
|
if (!error || !error.message) return error;
|
|
4
10
|
|
|
@@ -11,8 +17,33 @@ export const remapError = (error: Error | null | undefined) => {
|
|
|
11
17
|
|
|
12
18
|
return error;
|
|
13
19
|
};
|
|
14
|
-
|
|
20
|
+
|
|
21
|
+
export const rethrowError = (e: Error | null | undefined): never => {
|
|
15
22
|
throw remapError(e);
|
|
16
23
|
};
|
|
24
|
+
|
|
17
25
|
export const decoratePromiseErrors = <A>(promise: Promise<A>): Promise<A> =>
|
|
18
26
|
promise.catch(rethrowError);
|
|
27
|
+
|
|
28
|
+
export const bleErrorToHwTransportError = new Map([
|
|
29
|
+
[BleErrorCode.ScanStartFailed, HwTransportErrorType.BleScanStartFailed],
|
|
30
|
+
[
|
|
31
|
+
BleErrorCode.LocationServicesDisabled,
|
|
32
|
+
HwTransportErrorType.BleLocationServicesDisabled,
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
BleErrorCode.BluetoothUnauthorized,
|
|
36
|
+
HwTransportErrorType.BleBluetoothUnauthorized,
|
|
37
|
+
],
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
export const mapBleErrorToHwTransportError = (
|
|
41
|
+
bleError: BleError
|
|
42
|
+
): HwTransportError => {
|
|
43
|
+
const message = `${bleError.message}. Origin: ${bleError.errorCode}`;
|
|
44
|
+
|
|
45
|
+
const inferedType = bleErrorToHwTransportError.get(bleError.errorCode);
|
|
46
|
+
const type = !inferedType ? HwTransportErrorType.Unknown : inferedType;
|
|
47
|
+
|
|
48
|
+
return new HwTransportError(type, message);
|
|
49
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export type { BleManager } from "react-native-ble-plx";
|
|
2
2
|
export type Device = any; // FIXME: should be taken from Transport Device type, which should be at least a union of all Device types
|
|
3
3
|
export type Characteristic = any;
|
|
4
|
+
|
|
5
|
+
export type ReconnectionConfig = {
|
|
6
|
+
pairingThreshold: number;
|
|
7
|
+
delayAfterFirstPairing: number;
|
|
8
|
+
};
|