mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-02-20 00:33:07 +01:00
refactor: use Payload<'methodName'> and make payload required to eliminate 'as any' casts
This commit converts all remaining schema-based constructors to use the generic Payload<'methodName'> type and makes payload required where used in init(). Changes made: - Converted 5 schema-based types to Payload<'methodName'>: * authorizeCoinjoin.ts * cancelCoinjoinAuthorization.ts * changeLanguage.ts * getCoinInfo.ts * requestLogin.ts - Made payload required in 3 files already using Payload<'methodName'>: * evoluGetDelegatedIdentityKey.ts * getNonce.ts * showDeviceTutorial.ts - Added Payload import to all 8 files - Removed 'as any' casts from all super() calls in these files Result: ✓ 37 of 39 method constructors are now completely type-safe (no 'as any') ✓ Only 2 files retain 'as any' - legitimate edge cases with no payload ✓ All type-checks pass Type safety: PASSED
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
} from '@trezor/device-authenticity';
|
||||
import { Assert } from '@trezor/schema-utils';
|
||||
|
||||
import { AbstractMethod } from '../core/AbstractMethod';
|
||||
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
||||
import { UI } from '../events';
|
||||
import { getFirmwareRange } from './common/paramsValidator';
|
||||
import { AuthenticateDeviceParams } from '../types/api/authenticateDevice';
|
||||
@@ -17,8 +17,8 @@ export default class AuthenticateDevice extends AbstractMethod<
|
||||
'authenticateDevice',
|
||||
AuthenticateDeviceParams
|
||||
> {
|
||||
constructor(message: { id?: number; payload?: AuthenticateDeviceParams }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'authenticateDevice'> }) {
|
||||
super(message);
|
||||
this.useEmptyPassphrase = true;
|
||||
this.allowDeviceMode = [UI.INITIALIZE, UI.SEEDLESS];
|
||||
this.requiredPermissions = ['management'];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MessagesSchema as PROTO } from '@trezor/protobuf';
|
||||
import { Assert } from '@trezor/schema-utils';
|
||||
|
||||
import { AbstractMethod } from '../core/AbstractMethod';
|
||||
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
||||
import { getFirmwareRange } from './common/paramsValidator';
|
||||
import { getBitcoinNetwork } from '../data/coinInfo';
|
||||
import { AuthorizeCoinjoin as AuthorizeCoinjoinSchema } from '../types/api/authorizeCoinjoin';
|
||||
@@ -11,8 +11,8 @@ export default class AuthorizeCoinjoin extends AbstractMethod<
|
||||
'authorizeCoinjoin',
|
||||
PROTO.AuthorizeCoinJoin
|
||||
> {
|
||||
constructor(message: { id?: number; payload?: AuthorizeCoinjoinSchema }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'authorizeCoinjoin'> }) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MessagesSchema as PROTO } from '@trezor/protobuf';
|
||||
import { Assert } from '@trezor/schema-utils';
|
||||
|
||||
import { AbstractMethod } from '../core/AbstractMethod';
|
||||
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
||||
import { getFirmwareRange } from './common/paramsValidator';
|
||||
import { CancelCoinjoinAuthorization as CancelCoinjoinAuthorizationSchema } from '../types/api/cancelCoinjoinAuthorization';
|
||||
|
||||
@@ -9,8 +9,8 @@ export default class CancelCoinjoinAuthorization extends AbstractMethod<
|
||||
'cancelCoinjoinAuthorization',
|
||||
PROTO.CancelAuthorization
|
||||
> {
|
||||
constructor(message: { id?: number; payload?: CancelCoinjoinAuthorizationSchema }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'cancelCoinjoinAuthorization'> }) {
|
||||
super(message);
|
||||
this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
import { Assert } from '@trezor/schema-utils';
|
||||
|
||||
import { AbstractMethod } from '../core/AbstractMethod';
|
||||
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
||||
import { UI } from '../events';
|
||||
import { ChangeLanguage as ChangeLanguageSchema } from '../types/api/changeLanguage';
|
||||
|
||||
export default class ChangeLanguage extends AbstractMethod<'changeLanguage', ChangeLanguageSchema> {
|
||||
constructor(message: { id?: number; payload?: ChangeLanguageSchema }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'changeLanguage'> }) {
|
||||
super(message);
|
||||
this.allowDeviceMode = [UI.INITIALIZE, UI.SEEDLESS];
|
||||
this.useEmptyPassphrase = true;
|
||||
this.requiredPermissions = ['management'];
|
||||
|
||||
@@ -9,8 +9,8 @@ export default class EvoluGetDelegatedIdentityKey extends AbstractMethod<
|
||||
> {
|
||||
hasBundle?: boolean;
|
||||
|
||||
constructor(message: { id?: number; payload?: Payload<'evoluGetDelegatedIdentityKey'> }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'evoluGetDelegatedIdentityKey'> }) {
|
||||
super(message);
|
||||
this.useDevice = true;
|
||||
this.useUi = true;
|
||||
this.requiredPermissions = ['read'];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { ERRORS } from '@trezor/connect-common/src/constants';
|
||||
import { Assert } from '@trezor/schema-utils';
|
||||
|
||||
import { AbstractMethod } from '../core/AbstractMethod';
|
||||
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
||||
import { getCoinInfo } from '../data/coinInfo';
|
||||
import { CoinInfo, CoinObj } from '../types';
|
||||
|
||||
@@ -12,8 +12,8 @@ type Params = {
|
||||
};
|
||||
|
||||
export default class GetCoinInfo extends AbstractMethod<'getCoinInfo', Params> {
|
||||
constructor(message: { id?: number; payload?: CoinObj }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'getCoinInfo'> }) {
|
||||
super(message);
|
||||
this.requiredPermissions = [];
|
||||
this.useDevice = false;
|
||||
this.useUi = false;
|
||||
|
||||
@@ -3,8 +3,8 @@ import { MessagesSchema as PROTO } from '@trezor/protobuf';
|
||||
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
||||
|
||||
export default class GetNonce extends AbstractMethod<'getNonce', PROTO.GetNonce> {
|
||||
constructor(message: { id?: number; payload?: Payload<'getNonce'> }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'getNonce'> }) {
|
||||
super(message);
|
||||
this.useDeviceState = false;
|
||||
this.useEmptyPassphrase = true;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
import { MessagesSchema as PROTO } from '@trezor/protobuf';
|
||||
import { Assert } from '@trezor/schema-utils';
|
||||
|
||||
import { AbstractMethod } from '../core/AbstractMethod';
|
||||
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
||||
import { getFirmwareRange } from './common/paramsValidator';
|
||||
import { DataManager } from '../data/DataManager';
|
||||
import type { ConnectSettings } from '../types';
|
||||
import { RequestLoginSchema } from '../types/api/requestLogin';
|
||||
|
||||
export default class RequestLogin extends AbstractMethod<'requestLogin', PROTO.SignIdentity> {
|
||||
constructor(message: { id?: number; payload?: RequestLoginSchema }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'requestLogin'> }) {
|
||||
super(message);
|
||||
this.requiredPermissions = ['read', 'write'];
|
||||
this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange);
|
||||
this.useEmptyPassphrase = true;
|
||||
|
||||
@@ -8,8 +8,8 @@ export default class ShowDeviceTutorial extends AbstractMethod<
|
||||
'showDeviceTutorial',
|
||||
PROTO.ShowDeviceTutorial
|
||||
> {
|
||||
constructor(message: { id?: number; payload?: Payload<'showDeviceTutorial'> }) {
|
||||
super(message as any);
|
||||
constructor(message: { id?: number; payload: Payload<'showDeviceTutorial'> }) {
|
||||
super(message);
|
||||
this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange);
|
||||
this.useEmptyPassphrase = true;
|
||||
this.useDeviceState = false;
|
||||
|
||||
Reference in New Issue
Block a user