Skip to content

Commit

Permalink
fix: make typings for storageLoad a bit more 'nice'
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed Feb 14, 2025
1 parent 5dbe6c7 commit 44f7c48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions suite-common/bluetooth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@reduxjs/toolkit": "1.9.5",
"@suite-common/redux-utils": "workspace:*",
"@suite-common/wallet-core": "workspace:*"
}
}
16 changes: 9 additions & 7 deletions suite-common/bluetooth/src/bluetoothReducerCreator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Draft, createReducer } from '@reduxjs/toolkit';
import { AnyAction, Draft } from '@reduxjs/toolkit';

import { createReducerWithExtraDeps } from '@suite-common/redux-utils';
import { deviceActions } from '@suite-common/wallet-core';

import {
Expand Down Expand Up @@ -51,13 +52,8 @@ export const bluetoothReducerCreator = <T extends BluetoothDevice>() => {
devices: [] as T[],
};

return createReducer<BluetoothState<T>>(initialState, builder =>
return createReducerWithExtraDeps<BluetoothState<T>>(initialState, (builder, extra) =>
builder
.addCase('@storage/load', (state, rest) => {
// Todo: figure out hot to type it
// @ts-expect-error typed action
state.knownDevices = rest.payload.knownDevices?.bluetooth || [];
})
.addCase(bluetoothAdapterEventAction, (state, { payload: { isPowered } }) => {
state.isAdapterEnabled = isPowered;
if (!isPowered) {
Expand Down Expand Up @@ -125,6 +121,12 @@ export const bluetoothReducerCreator = <T extends BluetoothDevice>() => {
}
}
},
)
.addMatcher(
action => action.type === extra.actionTypes.storageLoad,
(state, action: AnyAction) => {
state.knownDevices = action.payload.knownDevices?.bluetooth;
},
),
);
};
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10270,6 +10270,7 @@ __metadata:
resolution: "@suite-common/bluetooth@workspace:suite-common/bluetooth"
dependencies:
"@reduxjs/toolkit": "npm:1.9.5"
"@suite-common/redux-utils": "workspace:*"
"@suite-common/wallet-core": "workspace:*"
languageName: unknown
linkType: soft
Expand Down

0 comments on commit 44f7c48

Please sign in to comment.