-
-
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.
- Loading branch information
1 parent
5c99d12
commit 6de6a8e
Showing
11 changed files
with
165 additions
and
136 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
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 { bluetoothManager } from '@trezor/transport-bluetooth'; | ||
|
||
import { BLUETOOTH_PREFIX } from './bluetoothActions'; | ||
|
||
type ThunkResponse = ReturnType<typeof bluetoothManager.connectDevice>; | ||
|
||
export const bluetoothConnectDeviceThunk = createThunk<ThunkResponse, { uuid: string }, void>( | ||
`${BLUETOOTH_PREFIX}/bluetoothConnectDeviceThunk`, | ||
async ({ uuid }, { fulfillWithValue }) => { | ||
const result = await bluetoothManager.connectDevice(uuid); | ||
|
||
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 { bluetoothManager } 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, ...) | ||
bluetoothManager.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 { bluetoothManager } 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 | ||
bluetoothManager.stopScan(); | ||
}, | ||
); |
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
import { createThunk } from '@suite-common/redux-utils/'; | ||
import { bluetoothManager, DeviceConnectionStatus } from '@trezor/transport-bluetooth'; | ||
import { Without } from '@trezor/type-utils'; | ||
|
||
import { | ||
BLUETOOTH_PREFIX, | ||
bluetoothAdapterEventAction, | ||
bluetoothConnectDeviceEventAction, | ||
bluetoothDeviceListUpdate, | ||
} from './bluetoothActions'; | ||
|
||
type DeviceConnectionStatusWithOptionalUuid = Without<DeviceConnectionStatus, 'uuid'> & { | ||
uuid?: string; | ||
}; | ||
|
||
export const initBluetoothThunk = createThunk<void, void, void>( | ||
`${BLUETOOTH_PREFIX}/initBluetoothThunk`, | ||
(_, { dispatch }) => { | ||
bluetoothManager.on('adapter-event', isPowered => { | ||
console.warn('adapter-event', isPowered); | ||
dispatch(bluetoothAdapterEventAction({ isPowered })); | ||
}); | ||
|
||
bluetoothManager.on('device-list-update', devices => { | ||
console.warn('device-list-update', devices); | ||
dispatch(bluetoothDeviceListUpdate({ devices })); | ||
}); | ||
|
||
bluetoothManager.on('device-connection-status', connectionStatus => { | ||
console.warn('device-connection-status', connectionStatus); | ||
const copyConnectionStatus: DeviceConnectionStatusWithOptionalUuid = { | ||
...connectionStatus, | ||
}; | ||
delete copyConnectionStatus.uuid; // So we dont pollute redux store | ||
|
||
dispatch( | ||
bluetoothConnectDeviceEventAction({ | ||
uuid: connectionStatus.uuid, | ||
connectionStatus: copyConnectionStatus, | ||
}), | ||
); | ||
}); | ||
}, | ||
); |
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
Oops, something went wrong.