Skip to content

Commit

Permalink
chore(suite): add tutorial step to onboarding for TS5
Browse files Browse the repository at this point in the history
(cherry picked from commit 74f5dad)
  • Loading branch information
komret authored and MiroslavProchazka committed Jul 8, 2024
1 parent 391fa3f commit 3e49396
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/suite/src/config/onboarding/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const steps: Step[] = [
{
id: STEP.ID_TUTORIAL_STEP,
stepGroup: 0,
supportedModels: [DeviceModelInternal.T2B1],
supportedModels: [
DeviceModelInternal.T2B1,
{ model: DeviceModelInternal.T3T1, minFwVersion: '2.8.0' },
],
prerequisites: [...commonPrerequisites, 'device-recovery-mode', 'device-different'],
},
{
Expand Down
11 changes: 8 additions & 3 deletions packages/suite/src/types/onboarding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { DeviceModelInternal } from '@trezor/connect';
import * as STEP from 'src/constants/onboarding/steps';
import { PrerequisiteType } from 'src/utils/suite/prerequisites';

export interface Step {
type ModelWithFirmwareVersion = {
model: DeviceModelInternal;
minFwVersion: `${number}.${number}.${number}`;
};

export type Step = {
id: AnyStepId;
stepGroup: number | undefined;
prerequisites?: (PrerequisiteType | 'device-different')[];
path?: AnyPath[];
supportedModels?: DeviceModelInternal[];
}
supportedModels?: (DeviceModelInternal | ModelWithFirmwareVersion)[];
};

// todo: remove, improve typing
export type AnyStepId =
Expand Down
40 changes: 38 additions & 2 deletions packages/suite/src/utils/onboarding/__tests__/steps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const backupStep: Step = {
id: STEP.ID_BACKUP_STEP,
path: [],
stepGroup: 1,
supportedModels: [DeviceModelInternal.T2B1],
supportedModels: [
DeviceModelInternal.T2B1,
{ model: DeviceModelInternal.T3T1, minFwVersion: '2.8.0' },
],
};

const stateMock = {
Expand All @@ -37,7 +40,7 @@ describe('steps', () => {
expect(findNextStep(firmwareStep.id, stepsMock)).toEqual(backupStep);
});

it('should throw on improrper use (no more step exists)', () => {
it('should throw on improper use (no more step exists)', () => {
expect(() => findNextStep(backupStep.id, stepsMock)).toThrow('no next step exists');
});
});
Expand Down Expand Up @@ -95,5 +98,38 @@ describe('steps', () => {
})),
).toEqual(false);
});

it('should exclude steps not supported by firmware', () => {
expect(
isStepUsed(backupStep, () => ({
...stateMock,
device: {
selectedDevice: {
features: {
internal_model: DeviceModelInternal.T3T1,
major_version: 2,
minor_version: 8,
patch_version: 0,
},
},
},
})),
).toEqual(true);
expect(
isStepUsed(backupStep, () => ({
...stateMock,
device: {
selectedDevice: {
features: {
internal_model: DeviceModelInternal.T3T1,
major_version: 2,
minor_version: 7,
patch_version: 2,
},
},
},
})),
).toEqual(false);
});
});
});
12 changes: 11 additions & 1 deletion packages/suite/src/utils/onboarding/steps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { selectDevice } from '@suite-common/wallet-core';
import { getFirmwareVersion } from '@trezor/device-utils';
import { versionUtils } from '@trezor/utils';

import { AnyStepId, AnyPath, Step } from 'src/types/onboarding';
import { GetState } from 'src/types/suite';
Expand All @@ -15,7 +17,15 @@ export const isStepUsed = (step: Step, getState: GetState): boolean => {
if (
deviceModelInternal &&
Array.isArray(step.supportedModels) &&
!step.supportedModels.includes(deviceModelInternal)
!(
step.supportedModels.includes(deviceModelInternal) ||
step.supportedModels.some(
it =>
typeof it === 'object' &&
it.model === deviceModelInternal &&
versionUtils.isNewerOrEqual(getFirmwareVersion(device), it.minFwVersion),
)
)
) {
return false;
}
Expand Down

0 comments on commit 3e49396

Please sign in to comment.