-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract reducers to common package #17090
Open
peter-sanderson
wants to merge
12
commits into
feat/rust-bluetooth
Choose a base branch
from
bluetooth-common-reducer2
base: feat/rust-bluetooth
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+742
−285
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aa34e30
feat: move reducers into seperate common package, create shared state…
peter-sanderson c0009aa
feat: implement suite-common bluetooth code into Suite
peter-sanderson e1e8026
feat: add tests for bluetoothRedcer and devicesSecondTime
peter-sanderson 2ebe1bc
feat: extract functionality and add test for it
peter-sanderson 6a30f1f
fixup! feat: extract functionality and add test for it
peter-sanderson 20fcc71
fixup! feat: move reducers into seperate common package, create share…
peter-sanderson 1d22b88
fixup! feat: extract functionality and add test for it
peter-sanderson eb34bdb
fixup! feat: implement suite-common bluetooth code into Suite
peter-sanderson c9d03f1
fixup! feat: move reducers into seperate common package, create share…
peter-sanderson 9dcc1e1
fixup! feat: move reducers into seperate common package, create share…
peter-sanderson e0b0c76
fixup! feat: implement suite-common bluetooth code into Suite
peter-sanderson fe0378a
fixup! feat: move reducers into seperate common package, create share…
peter-sanderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/suite/src/actions/bluetooth/__tests__/remapKnownDevicesForLinux.test.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,70 @@ | ||
import { BluetoothDevice } from '@trezor/transport-bluetooth'; | ||
|
||
import { remapKnownDevicesForLinux } from '../remapKnownDevicesForLinux'; | ||
|
||
const nearbyDeviceA: BluetoothDevice = { | ||
id: 'New-Id-A', | ||
data: [], | ||
name: 'Trezor A', | ||
lastUpdatedTimestamp: 1, | ||
address: 'Address-Trezor-A-Staying-Same', | ||
connected: false, | ||
paired: false, | ||
rssi: 0, | ||
}; | ||
|
||
const nearbyDeviceC: BluetoothDevice = { | ||
id: 'C', | ||
data: [], | ||
name: 'Trezor C', | ||
lastUpdatedTimestamp: 1, | ||
address: 'Address-Trezor-C', | ||
connected: false, | ||
paired: false, | ||
rssi: 0, | ||
}; | ||
|
||
const knownDeviceB: BluetoothDevice = { | ||
id: 'B', | ||
data: [], | ||
name: 'Trezor A', | ||
lastUpdatedTimestamp: 1, | ||
address: 'Address-Trezor-B', | ||
connected: false, | ||
paired: false, | ||
rssi: 0, | ||
}; | ||
|
||
const knownDeviceA: BluetoothDevice = { | ||
id: 'Original-Id A', | ||
data: [], | ||
name: 'Trezor B', | ||
lastUpdatedTimestamp: 2, | ||
address: 'Address-Trezor-A-Staying-Same', | ||
connected: false, | ||
paired: false, | ||
rssi: 0, | ||
}; | ||
|
||
describe(remapKnownDevicesForLinux.name, () => { | ||
it('remaps the changed id of the device, while leaving the others intact', () => { | ||
const result = remapKnownDevicesForLinux({ | ||
nearbyDevices: [nearbyDeviceA, nearbyDeviceC], | ||
knownDevices: [knownDeviceA, knownDeviceB], | ||
}); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
address: 'Address-Trezor-A-Staying-Same', | ||
connected: false, | ||
data: [], | ||
id: 'New-Id-A', | ||
lastUpdatedTimestamp: 2, | ||
name: 'Trezor B', | ||
paired: false, | ||
rssi: 0, | ||
}, | ||
knownDeviceB, // Is kept as it is | ||
]); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
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
6 changes: 3 additions & 3 deletions
6
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
6 changes: 3 additions & 3 deletions
6
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
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
27 changes: 27 additions & 0 deletions
27
packages/suite/src/actions/bluetooth/remapKnownDevicesForLinux.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,27 @@ | ||
import { BluetoothDevice } from '@trezor/transport-bluetooth'; | ||
|
||
type RemapKnownDevicesForLinuxParams = { | ||
knownDevices: BluetoothDevice[]; | ||
nearbyDevices: BluetoothDevice[]; | ||
}; | ||
|
||
/** | ||
* On linux, when bluetooth adapter is turned off/on again, the paired | ||
* devices will get different `id`, but `address` will remain the same. | ||
* | ||
* Therefore, we have to remap the knownDevices to change the `id`. | ||
*/ | ||
export const remapKnownDevicesForLinux = ({ | ||
knownDevices, | ||
nearbyDevices, | ||
}: RemapKnownDevicesForLinuxParams): BluetoothDevice[] => | ||
knownDevices.map(knownDevice => { | ||
const nearbyDeviceWithSameAddress = nearbyDevices.find( | ||
nearbyDevice => | ||
nearbyDevice.address === knownDevice.address && nearbyDevice.id !== knownDevice.id, | ||
); | ||
|
||
return nearbyDeviceWithSameAddress | ||
? { ...knownDevice, id: nearbyDeviceWithSameAddress.id } | ||
: knownDevice; | ||
}); |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be done to create generic selector with memoized output. Consulted with @Nodonisko