@onekeyfe/hd-transport-react-native 1.2.0-alpha.6 → 1.2.0-alpha.61

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.
@@ -7,35 +7,10 @@ export type BleWriteCapability = {
7
7
  isWritableWithoutResponse?: boolean | null;
8
8
  };
9
9
 
10
- export type BleWriteMode = 'withResponse' | 'withoutResponse';
11
-
12
10
  export function hasWritableCapability(characteristic: BleWriteCapability) {
13
11
  return !!(characteristic.isWritableWithResponse || characteristic.isWritableWithoutResponse);
14
12
  }
15
13
 
16
- export function resolveBleWriteMode(
17
- characteristic: BleWriteCapability,
18
- preferredMode: BleWriteMode = 'withoutResponse'
19
- ): BleWriteMode {
20
- if (preferredMode === 'withoutResponse' && characteristic.isWritableWithoutResponse) {
21
- return 'withoutResponse';
22
- }
23
-
24
- if (preferredMode === 'withResponse' && characteristic.isWritableWithResponse) {
25
- return 'withResponse';
26
- }
27
-
28
- if (characteristic.isWritableWithoutResponse) {
29
- return 'withoutResponse';
30
- }
31
-
32
- if (characteristic.isWritableWithResponse) {
33
- return 'withResponse';
34
- }
35
-
36
- return preferredMode;
37
- }
38
-
39
14
  export function resolveProtocolV2PacketCapacity({
40
15
  platform,
41
16
  iosPacketLength = IOS_PACKET_LENGTH,
package/src/constants.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { createKnownBleUuidAliases, matchesKnownBleUuid } from '@onekeyfe/hd-shared';
2
+
1
3
  export const IOS_PACKET_LENGTH = 128;
2
4
  export const ANDROID_PACKET_LENGTH = 192;
3
5
  export const ANDROID_DEFAULT_MTU = 23;
@@ -40,7 +42,9 @@ export const getInfosForServiceUuid = (serviceUuid: string, deviceType: 'classic
40
42
  const service =
41
43
  services[serviceUuid] ??
42
44
  Object.values(services).find(
43
- item => normalizeBleUuid(item.serviceUuid) === normalizedServiceUuid
45
+ item =>
46
+ normalizeBleUuid(item.serviceUuid) === normalizedServiceUuid ||
47
+ matchesKnownBleUuid(serviceUuid, createKnownBleUuidAliases(item.serviceUuid))
44
48
  );
45
49
  if (!service) {
46
50
  return null;
@@ -51,17 +55,7 @@ export const getInfosForServiceUuid = (serviceUuid: string, deviceType: 'classic
51
55
  export const normalizeBleUuid = (uuid?: string | null) =>
52
56
  (uuid ?? '').replace(/-/g, '').toLowerCase();
53
57
 
54
- export const getBleUuidKey = (uuid?: string | null) => {
55
- const normalized = normalizeBleUuid(uuid);
56
- return normalized.length >= 8 ? normalized.substring(4, 8) : normalized;
57
- };
58
-
59
58
  export const isSameBleUuid = (left?: string | null, right?: string | null) => {
60
- const normalizedLeft = normalizeBleUuid(left);
61
- const normalizedRight = normalizeBleUuid(right);
62
-
63
- return (
64
- normalizedLeft === normalizedRight ||
65
- (getBleUuidKey(left) !== '' && getBleUuidKey(left) === getBleUuidKey(right))
66
- );
59
+ if (!left || !right) return false;
60
+ return matchesKnownBleUuid(left, createKnownBleUuidAliases(right));
67
61
  };