-
-
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: implement Bluetooth Onboarding UI feat: different 'Not the Trezor you are looking for' UI feat: implement Bluetooth Onboarding UI 2 feat: implement Bluetooth Onboarding UI feat: different 'Not the Trezor you are looking for' UI feat: implement Bluetooth Onboarding UI 2 feat: use CollapsibleBox component in Bluetooth UI fix: after rebase enable BT onboarding WIP: transport name breaking change aftr rebase
- Loading branch information
1 parent
66a1a81
commit 232e121
Showing
32 changed files
with
1,104 additions
and
23 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createAction } from '@reduxjs/toolkit'; | ||
|
||
import { BluetoothDevice } from '@trezor/transport-bluetooth'; | ||
|
||
import { | ||
BluetoothScanStatus, | ||
DeviceBluetoothStatus, | ||
} from '../../reducers/bluetooth/bluetoothReducer'; | ||
|
||
export const BLUETOOTH_PREFIX = '@suite/bluetooth'; | ||
|
||
export const bluetoothAdapterEventAction = createAction( | ||
`${BLUETOOTH_PREFIX}/adapter-event`, | ||
({ isPowered }: { isPowered: boolean }) => ({ payload: { isPowered } }), | ||
); | ||
|
||
export const bluetoothDeviceListUpdate = createAction( | ||
`${BLUETOOTH_PREFIX}/device-list-update`, | ||
({ devices }: { devices: BluetoothDevice[] }) => ({ payload: { devices } }), | ||
); | ||
|
||
export const bluetoothConnectDeviceEventAction = createAction( | ||
`${BLUETOOTH_PREFIX}/device-connection-status`, | ||
({ connectionStatus, id }: { id: string; connectionStatus: DeviceBluetoothStatus }) => ({ | ||
payload: { id, connectionStatus }, | ||
}), | ||
); | ||
|
||
export const bluetoothScanStatusAction = createAction( | ||
`${BLUETOOTH_PREFIX}/scan-status`, | ||
({ status }: { status: BluetoothScanStatus }) => ({ payload: { status } }), | ||
); | ||
|
||
export const allBluetoothActions = { | ||
bluetoothAdapterEventAction, | ||
bluetoothDeviceListUpdate, | ||
bluetoothConnectDeviceEventAction, | ||
bluetoothScanStatusAction, | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/suite/src/actions/bluetooth/bluetoothConnectDeviceThunk.ts
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createThunk } from '@suite-common/redux-utils'; | ||
import { bluetoothIpc } from '@trezor/transport-bluetooth'; | ||
|
||
import { BLUETOOTH_PREFIX } from './bluetoothActions'; | ||
|
||
type ThunkResponse = ReturnType<typeof bluetoothIpc.connectDevice>; | ||
|
||
export const bluetoothConnectDeviceThunk = createThunk<ThunkResponse, { id: string }, void>( | ||
`${BLUETOOTH_PREFIX}/bluetoothConnectDeviceThunk`, | ||
async ({ id }, { fulfillWithValue }) => { | ||
const result = await bluetoothIpc.connectDevice(id); | ||
|
||
return fulfillWithValue(result); | ||
}, | ||
); |
13 changes: 13 additions & 0 deletions
13
packages/suite/src/actions/bluetooth/bluetoothStartScanningThunk.ts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createThunk } from '@suite-common/redux-utils'; | ||
import { bluetoothIpc } from '@trezor/transport-bluetooth'; | ||
|
||
import { BLUETOOTH_PREFIX } from './bluetoothActions'; | ||
|
||
export const bluetoothStartScanningThunk = createThunk<void, void, void>( | ||
`${BLUETOOTH_PREFIX}/bluetoothStartScanningThunk`, | ||
_ => { | ||
// This can fail, but if there is an error we already got it from `adapter-event` | ||
// and user is informed about it (bluetooth turned-off, ...) | ||
bluetoothIpc.startScan(); | ||
}, | ||
); |
12 changes: 12 additions & 0 deletions
12
packages/suite/src/actions/bluetooth/bluetoothStopScanningThunk.ts
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createThunk } from '@suite-common/redux-utils'; | ||
import { bluetoothIpc } from '@trezor/transport-bluetooth'; | ||
|
||
import { BLUETOOTH_PREFIX } from './bluetoothActions'; | ||
|
||
export const bluetoothStopScanningThunk = createThunk<void, void, void>( | ||
`${BLUETOOTH_PREFIX}/bluetoothStopScanningThunk`, | ||
_ => { | ||
// This can fail, but there is nothing we can do about it | ||
bluetoothIpc.stopScan(); | ||
}, | ||
); |
55 changes: 55 additions & 0 deletions
55
packages/suite/src/actions/bluetooth/initBluetoothThunk.ts
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { createThunk } from '@suite-common/redux-utils/'; | ||
import { DeviceConnectionStatus, bluetoothIpc } from '@trezor/transport-bluetooth'; | ||
import { Without } from '@trezor/type-utils'; | ||
|
||
import { | ||
BLUETOOTH_PREFIX, | ||
bluetoothAdapterEventAction, | ||
bluetoothConnectDeviceEventAction, | ||
bluetoothDeviceListUpdate, | ||
} from './bluetoothActions'; | ||
import { selectSuiteFlags } from '../../reducers/suite/suiteReducer'; | ||
|
||
type DeviceConnectionStatusWithOptionalId = Without<DeviceConnectionStatus, 'id'> & { | ||
id?: string; | ||
}; | ||
|
||
export const initBluetoothThunk = createThunk<void, void, void>( | ||
`${BLUETOOTH_PREFIX}/initBluetoothThunk`, | ||
async (_, { dispatch, getState }) => { | ||
const { isBluetoothEnabled } = selectSuiteFlags(getState()); | ||
|
||
if (!isBluetoothEnabled) { | ||
return; | ||
} | ||
|
||
bluetoothIpc.on('adapter-event', isPowered => { | ||
console.warn('adapter-event', isPowered); | ||
dispatch(bluetoothAdapterEventAction({ isPowered })); | ||
}); | ||
|
||
bluetoothIpc.on('device-list-update', devices => { | ||
console.warn('device-list-update', devices); | ||
dispatch(bluetoothDeviceListUpdate({ devices })); | ||
}); | ||
|
||
bluetoothIpc.on('device-connection-status', connectionStatus => { | ||
console.warn('device-connection-status', connectionStatus); | ||
const copyConnectionStatus: DeviceConnectionStatusWithOptionalId = { | ||
...connectionStatus, | ||
}; | ||
delete copyConnectionStatus.id; // So we dont pollute redux store | ||
|
||
dispatch( | ||
bluetoothConnectDeviceEventAction({ | ||
id: connectionStatus.id, | ||
connectionStatus: copyConnectionStatus, | ||
}), | ||
); | ||
}); | ||
|
||
// TODO: this should be called after trezor/connect init? | ||
const knownDevices = getState().bluetooth.pairedDevices; | ||
await bluetoothIpc.init({ knownDevices }); | ||
}, | ||
); |
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
Oops, something went wrong.