Skip to content

Commit

Permalink
fixup! feat: implement suite-common bluetooth code into Suite
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed Feb 24, 2025
1 parent 1a79397 commit cd31be2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -38,9 +39,12 @@ const selectAllDevices = prepareSelectAllDevices<BluetoothDevice>();

export const BluetoothConnect = ({ onClose, uiMode }: BluetoothConnectProps) => {
const dispatch = useDispatch();

const [selectedDeviceId, setSelectedDeviceId] = useState<string | null>(null);
const [scannerTimerId, setScannerTimerId] = useState<TimerId | null>(null);

const trezorDevices = useSelector(selectDevices);

const bluetoothAdapterStatus = useSelector(selectAdapterStatus);
const scanStatus = useSelector(selectScanStatus);
const allDevices = useSelector(selectAllDevices);
Expand All @@ -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 =
Expand Down

0 comments on commit cd31be2

Please sign in to comment.