-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Bluetooth handle connection status for knownDevices
- Loading branch information
1 parent
8d82c24
commit ad15ba6
Showing
5 changed files
with
70 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 32 additions & 16 deletions
48
packages/suite/src/components/suite/bluetooth/BluetoothDeviceItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,41 @@ | ||
import { BluetoothDeviceState, DeviceBluetoothStatusType } from '@suite-common/bluetooth'; | ||
import { Button, Row } from '@trezor/components'; | ||
import { spacings } from '@trezor/theme'; | ||
import { BluetoothDevice as BluetoothDeviceType } from '@trezor/transport-bluetooth'; | ||
import { BluetoothDevice } from '@trezor/transport-bluetooth'; | ||
|
||
import { BluetoothDeviceComponent } from './BluetoothDeviceComponent'; | ||
|
||
const map: Record<DeviceBluetoothStatusType, string> = { | ||
connecting: 'Connecting', | ||
connected: 'Conencted', | ||
error: 'Error', | ||
pairing: 'Pairing', | ||
paired: 'Paired', | ||
}; | ||
|
||
type BluetoothDeviceItemProps = { | ||
device: BluetoothDeviceType; | ||
device: BluetoothDeviceState<BluetoothDevice>; | ||
onClick: () => void; | ||
isDisabled?: boolean; | ||
}; | ||
|
||
export const BluetoothDeviceItem = ({ device, onClick, isDisabled }: BluetoothDeviceItemProps) => ( | ||
<Row onClick={onClick} gap={spacings.md} alignItems="stretch"> | ||
<BluetoothDeviceComponent device={device} flex="1" /> | ||
<Button | ||
variant="primary" | ||
size="small" | ||
margin={{ vertical: spacings.xxs }} | ||
isDisabled={isDisabled} | ||
> | ||
Connect | ||
</Button> | ||
</Row> | ||
); | ||
export const BluetoothDeviceItem = ({ device, onClick }: BluetoothDeviceItemProps) => { | ||
const isDisabled = device.status !== null; | ||
const isLoading = device.status?.type === 'pairing' || device.status?.type === 'connecting'; | ||
|
||
return ( | ||
<Row onClick={isDisabled ? undefined : onClick} gap={spacings.md} alignItems="stretch"> | ||
<BluetoothDeviceComponent device={device.device} flex="1" /> | ||
{device.status && ( | ||
<Button | ||
variant="primary" | ||
size="small" | ||
margin={{ vertical: spacings.xxs }} | ||
isDisabled={isDisabled} | ||
isLoading={isLoading} | ||
> | ||
{map[device.status?.type]} | ||
</Button> | ||
)} | ||
</Row> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters