Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

LIVE-1469 Handle onboarded devices in device actions #1738

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const LowerThanMinimumRelayFee = createCustomErrorClass(
export const TransactionRefusedOnDevice = createCustomErrorClass(
"TransactionRefusedOnDevice"
);
export const DeviceNotOnboarded = createCustomErrorClass("DeviceNotOnboarded");
export const InvalidAddressBecauseAlreadyDelegated = createCustomErrorClass(
"InvalidAddressBecauseAlreadyDelegated"
);
Expand Down
6 changes: 6 additions & 0 deletions src/hw/connectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import getDeviceInfo from "./getDeviceInfo";
import getAppAndVersion from "./getAppAndVersion";
import appSupportsQuitApp from "../appSupportsQuitApp";
import { isDashboardName } from "./isDashboardName";
import { DeviceNotOnboarded } from "../errors";
import type { AppAndVersion } from "./connectApp";
import quitApp from "./quitApp";
export type Input = {
Expand Down Expand Up @@ -77,6 +78,11 @@ const cmd = ({
concatMap((deviceInfo) => {
timeoutSub.unsubscribe();

// FIXME Until we have proper flagging of the onboarded status.
if (!deviceInfo.onboarded) {
throw new DeviceNotOnboarded();
}

if (deviceInfo.isBootloader) {
return of({
type: "bootloader",
Expand Down
19 changes: 18 additions & 1 deletion src/hw/getDeviceInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import getAppAndVersion from "./getAppAndVersion";
import type { DeviceInfo } from "../types/manager";
import { PROVIDERS } from "../manager/provider";
import { isDashboardName } from "./isDashboardName";
import { DeviceNotOnboarded } from "../errors";
const ManagerAllowedFlag = 0x08;
const PinValidatedFlag = 0x80;
export default async function getDeviceInfo(
Expand Down Expand Up @@ -37,7 +38,16 @@ export default async function getDeviceInfo(
throw new DeviceOnDashboardExpected();
}

const res = await getVersion(transport);
const res = await getVersion(transport).catch((e) => {
if (e instanceof TransportStatusError) {
// @ts-expect-error typescript not checking agains the instanceof
if (e.statusCode === 0x6d06) {
throw new DeviceNotOnboarded();
}
}
throw e;
});

const {
isBootloader,
rawVersion,
Expand All @@ -57,6 +67,12 @@ export default async function getDeviceInfo(
const flag = flags.length > 0 ? flags[0] : 0;
const managerAllowed = !!(flag & ManagerAllowedFlag);
const pinValidated = !!(flag & PinValidatedFlag);

// FIXME Until we have proper flagging of the onboarded status.
let onboarded = true;
if (flags.length === 4) {
onboarded = !!(flags[0] & 0x04);
}
log(
"hw",
"deviceInfo: se@" +
Expand All @@ -79,5 +95,6 @@ export default async function getDeviceInfo(
isBootloader,
managerAllowed,
pinValidated,
onboarded,
};
}
1 change: 1 addition & 0 deletions src/types/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type DeviceInfo = {
mcuBlVersion?: string;
mcuTargetId?: number;
seTargetId?: number;
onboarded?: boolean;
};
export type DeviceModelInfo = {
modelId: DeviceModelId;
Expand Down