Skip to content

Commit e6c2322

Browse files
committed
chore(bluetooth): use stable empty array for nearby BLE devices selectors
1 parent 7466e7d commit e6c2322

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

suite-native/bluetooth/src/selectors.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
selectKnownDevices,
55
selectNearbyDevices,
66
} from '@suite-common/bluetooth';
7-
import { createWeakMapSelector } from '@suite-common/redux-utils';
7+
import { createWeakMapSelector, returnStableArrayIfEmpty } from '@suite-common/redux-utils';
88

99
import { NativeBluetoothRootState } from './bluetoothSlice';
1010

@@ -38,22 +38,26 @@ export const selectNearbyBluetoothDevices = createMemoizedSelector(
3838
export const selectNearbyPairableBluetoothDevices = createMemoizedSelector(
3939
[selectNearbyBluetoothDevices, selectKnownBluetoothDevices],
4040
(nearbyBluetoothDevices, knownBluetoothDevices) =>
41-
nearbyBluetoothDevices.filter(
42-
({ id, manufacturerData }) =>
43-
knownBluetoothDevices.every(knownDevice => knownDevice.id !== id) &&
44-
manufacturerData.filterPolicy?.pairing === true,
41+
returnStableArrayIfEmpty(
42+
nearbyBluetoothDevices.filter(
43+
({ id, manufacturerData }) =>
44+
knownBluetoothDevices.every(knownDevice => knownDevice.id !== id) &&
45+
manufacturerData.filterPolicy?.pairing === true,
46+
),
4547
),
4648
);
4749

4850
export const selectKnownConnectableBluetoothDevices = createMemoizedSelector(
4951
[selectNearbyBluetoothDevices, selectKnownBluetoothDevices, selectBluetoothAutoConnectPolicy],
5052
(nearbyBluetoothDevices, knownBluetoothDevices, autoConnectPolicy) =>
51-
nearbyBluetoothDevices.filter(
52-
({ id, manufacturerData, connectionStatus }) =>
53-
knownBluetoothDevices.some(knownDevice => knownDevice.id === id) &&
54-
autoConnectPolicy[id]?.type !== 'autoconnect-disabled' &&
55-
manufacturerData.filterPolicy?.pairing !== true &&
56-
manufacturerData.filterPolicy?.user_disconnected !== true &&
57-
connectionStatus.type === 'disconnected',
53+
returnStableArrayIfEmpty(
54+
nearbyBluetoothDevices.filter(
55+
({ id, manufacturerData, connectionStatus }) =>
56+
knownBluetoothDevices.some(knownDevice => knownDevice.id === id) &&
57+
autoConnectPolicy[id]?.type !== 'autoconnect-disabled' &&
58+
manufacturerData.filterPolicy?.pairing !== true &&
59+
manufacturerData.filterPolicy?.user_disconnected !== true &&
60+
connectionStatus.type === 'disconnected',
61+
),
5862
),
5963
);

0 commit comments

Comments
 (0)