From cd31be2fc492de546b7f29337c3adf74de477f9e Mon Sep 17 00:00:00 2001 From: Peter Sanderson Date: Mon, 24 Feb 2025 15:41:11 +0100 Subject: [PATCH] fixup! feat: implement suite-common bluetooth code into Suite --- .../suite/bluetooth/BluetoothConnect.tsx | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx b/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx index 48c746ed853..c95c6f85f72 100644 --- a/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx +++ b/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx @@ -7,6 +7,7 @@ import { selectKnownDevices, selectScanStatus, } from '@suite-common/bluetooth'; +import { selectDevices } from '@suite-common/wallet-core'; import { Card, Column, ElevationUp } from '@trezor/components'; import { spacings } from '@trezor/theme'; import { BluetoothDevice } from '@trezor/transport-bluetooth'; @@ -38,9 +39,12 @@ const selectAllDevices = prepareSelectAllDevices(); export const BluetoothConnect = ({ onClose, uiMode }: BluetoothConnectProps) => { const dispatch = useDispatch(); + const [selectedDeviceId, setSelectedDeviceId] = useState(null); const [scannerTimerId, setScannerTimerId] = useState(null); + const trezorDevices = useSelector(selectDevices); + const bluetoothAdapterStatus = useSelector(selectAdapterStatus); const scanStatus = useSelector(selectScanStatus); const allDevices = useSelector(selectAllDevices); @@ -49,12 +53,23 @@ export const BluetoothConnect = ({ onClose, uiMode }: BluetoothConnectProps) => const lasUpdatedBoundaryTimestamp = Date.now() / 1000 - UNPAIRED_DEVICES_LAST_UPDATED_LIMIT_SECONDS; - const devices = allDevices.filter(device => { - if (device.device.lastUpdatedTimestamp >= lasUpdatedBoundaryTimestamp) { - return true; + const devices = allDevices.filter(it => { + const isDeviceAlreadyConnected = + trezorDevices.find(trezorDevice => trezorDevice.bluetoothProps?.id === it.device.id) !== + undefined; + + if (isDeviceAlreadyConnected) { + return false; + } + + const isDeviceUnresponsiveForTooLong = + it.device.lastUpdatedTimestamp < lasUpdatedBoundaryTimestamp; + + if (isDeviceUnresponsiveForTooLong) { + return knownDevices.find(knownDevice => knownDevice.id === it.device.id) !== undefined; } - return knownDevices.find(knownDevice => knownDevice.id === device.device.id) !== undefined; + return true; }); const selectedDevice =