Skip to content

Commit

Permalink
feat(suite): handle firmwareUpdate and version change event
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz committed Jan 20, 2025
1 parent 63f955d commit c6bf766
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const bootloaderDeviceNoIntermediaryT1 = {
),
};
const firmwareUpdateResponsePayload = {
hash: 'abc',
challenge: 'def',
check: 'valid',
versionCheck: true,
};

export const actions = [
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/middlewares/suite/eventsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const eventsMiddleware =
}
}

if (action.type === DEVICE.FIRMWARE_VERSION_CHANGED) {
// TODO: show warning? move this to different middleware?
}

if (deviceActions.selectDevice.match(action)) {
// Find and mark all notification associated (new connected!, update required etc)
if (!action.payload) return action;
Expand Down
4 changes: 3 additions & 1 deletion suite-common/firmware/src/firmwareThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const firmwareUpdate = createThunk<
connectResponse: firmwareUpdateResponse,
});
} else {
const { check } = firmwareUpdateResponse.payload;
const { check, versionCheck } = firmwareUpdateResponse.payload;
if (check === 'mismatch') {
// hash check was performed, and it does not match, so consider firmware counterfeit
dispatch(handleFwHashMismatch(device));
Expand All @@ -165,6 +165,8 @@ export const firmwareUpdate = createThunk<
errorMessage: firmwareUpdateResponse.payload.checkError,
}),
);
} else if (!binary && !versionCheck) {
// TODO: log to sentry
} else {
dispatch(handleFwHashValid(device));
}
Expand Down
15 changes: 13 additions & 2 deletions suite-common/wallet-core/src/device/deviceActions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createAction } from '@reduxjs/toolkit';

import { Device, DEVICE } from '@trezor/connect';
import { Device, DEVICE, DeviceVersionChanged } from '@trezor/connect';
import { ButtonRequest, TrezorDevice } from '@suite-common/suite-types';
import { WalletType } from '@suite-common/wallet-types';

Expand All @@ -18,7 +18,7 @@ const connectDevice = createAction(DEVICE.CONNECT, (payload: DeviceConnectAction

const connectUnacquiredDevice = createAction(
DEVICE.CONNECT_UNACQUIRED,
(payload: { device: Device; settings: ConnectDeviceSettings }) => ({ payload }),
(payload: DeviceConnectActionPayload) => ({ payload }),
);

const deviceChanged = createAction(DEVICE.CHANGED, (payload: Device | TrezorDevice) => ({
Expand All @@ -29,6 +29,16 @@ const deviceDisconnect = createAction(DEVICE.DISCONNECT, (payload: TrezorDevice)
payload,
}));

// this action is not used but is required because of the typings
// changed here: https://github.com/trezor/trezor-suite/commit/c02412bccf80da7c827f624b7a7c85cdedf278c5#diff-2e9d057f0bfe2cc92fe50d4ce28838622d9e79fcca010ab8847a0fa288da13fd
// in fact action is dispatched from connectInitThunk same as the rest of events
const deviceFirmwareVersionChanged = createAction(
DEVICE.FIRMWARE_VERSION_CHANGED,
(payload: DeviceVersionChanged['payload']) => ({
payload,
}),
);

const updatePassphraseMode = createAction(
`${DEVICE_MODULE_PREFIX}/updatePassphraseMode`,
(payload: { device: TrezorDevice; hidden: boolean; alwaysOnDevice?: boolean }) => ({ payload }),
Expand Down Expand Up @@ -102,4 +112,5 @@ export const deviceActions = {
selectDevice,
updateSelectedDevice,
removeButtonRequests,
deviceFirmwareVersionChanged,
};

0 comments on commit c6bf766

Please sign in to comment.