mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-02-20 00:33:07 +01:00
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
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { MessagesSchema as PROTO } from '@trezor/protobuf';
|
|
import { Assert } from '@trezor/schema-utils';
|
|
|
|
import { AbstractMethod, Payload } from '../core/AbstractMethod';
|
|
import { getFirmwareRange } from './common/paramsValidator';
|
|
import { CancelCoinjoinAuthorization as CancelCoinjoinAuthorizationSchema } from '../types/api/cancelCoinjoinAuthorization';
|
|
|
|
export default class CancelCoinjoinAuthorization extends AbstractMethod<
|
|
'cancelCoinjoinAuthorization',
|
|
PROTO.CancelAuthorization
|
|
> {
|
|
constructor(message: { id?: number; payload: Payload<'cancelCoinjoinAuthorization'> }) {
|
|
super(message);
|
|
this.firmwareRange = getFirmwareRange(this.name, null, this.firmwareRange);
|
|
}
|
|
|
|
init() {
|
|
const { payload } = this;
|
|
|
|
Assert(CancelCoinjoinAuthorizationSchema, payload);
|
|
this.preauthorized =
|
|
typeof payload.preauthorized === 'boolean' ? payload.preauthorized : true;
|
|
}
|
|
|
|
get info() {
|
|
return 'Cancel Coinjoin Authorization';
|
|
}
|
|
|
|
async run() {
|
|
const cmd = this.device.getCommands();
|
|
|
|
if (!this.preauthorized) {
|
|
if (!(await cmd.preauthorize(false))) {
|
|
// device is not preauthorised
|
|
return { message: 'Not authorized' };
|
|
}
|
|
}
|
|
|
|
const response = await cmd.typedCall('CancelAuthorization', 'Success');
|
|
|
|
return response.message;
|
|
}
|
|
}
|