Skip to content

Commit

Permalink
fix(protobuf): clean up type of backup_type in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Apr 8, 2024
1 parent 7803da2 commit 19b7bb2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
5 changes: 2 additions & 3 deletions packages/connect/src/api/resetDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import { AbstractMethod } from '../core/AbstractMethod';
import { UI, createUiMessage } from '../events';
import { getFirmwareRange } from './common/paramsValidator';
import type { PROTO } from '../constants';
import { PROTO } from '../constants';
import { Assert } from '@trezor/schema-utils';
import { ResetDevice as ResetDeviceSchema } from '../types/api/resetDevice';

export default class ResetDevice extends AbstractMethod<'resetDevice', PROTO.ResetDevice> {
confirmed?: boolean;
Expand All @@ -18,7 +17,7 @@ export default class ResetDevice extends AbstractMethod<'resetDevice', PROTO.Res

const { payload } = this;
// validate bundle type
Assert(ResetDeviceSchema, payload);
Assert(PROTO.ResetDevice, payload);

this.params = {
display_random: payload.display_random,
Expand Down
11 changes: 1 addition & 10 deletions packages/connect/src/types/api/resetDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
* Performs device setup and generates a new seed.
*/

import { Static, Type } from '@trezor/schema-utils';
import { PROTO } from '../../constants';
import type { Params, Response } from '../params';

export type ResetDevice = Static<typeof ResetDevice>;
export const ResetDevice = Type.Composite([
PROTO.ResetDevice,
Type.Object({
backup_type: Type.Optional(Type.Union([Type.Literal(0), Type.Literal(1)])),
}),
]);

export declare function resetDevice(params: Params<ResetDevice>): Response<PROTO.Success>;
export declare function resetDevice(params: Params<PROTO.ResetDevice>): Response<PROTO.Success>;
2 changes: 1 addition & 1 deletion packages/protobuf/scripts/protobuf-patches/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const TYPE_PATCH = {
'EosActionUnlinkAuth.type': 'string',
'EosActionNewAccount.creator': 'string',
'EosActionNewAccount.name': 'string',
'ResetDevice.backup_type': 'string | number', // BackupType is a enum. in Features displayed as string, in resetDevice method param accepted as number
'ResetDevice.backup_type': 'Enum_BackupType',
'StellarAsset.type': '0 | 1 | 2 | "NATIVE" | "ALPHANUM4" | "ALPHANUM12"', // StellarAssetType is a enum, accepted as both number and string
'StellarSignTx.sequence_number': UINT_TYPE,
'StellarSignTx.memo_id': UINT_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/messages-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ export const ResetDevice = Type.Object(
u2f_counter: Type.Optional(Type.Number()),
skip_backup: Type.Optional(Type.Boolean()),
no_backup: Type.Optional(Type.Boolean()),
backup_type: Type.Optional(Type.Union([Type.String(), Type.Number()])),
backup_type: Type.Optional(EnumEnum_BackupType),
},
{ $id: 'ResetDevice' },
);
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ export type ResetDevice = {
u2f_counter?: number;
skip_backup?: boolean;
no_backup?: boolean;
backup_type?: string | number;
backup_type?: Enum_BackupType;
};

// BackupDevice
Expand Down

0 comments on commit 19b7bb2

Please sign in to comment.