diff --git a/packages/connect/src/api/binance/api/binanceAbstractMethods.ts b/packages/connect/src/api/binance/api/binanceAbstractMethods.ts new file mode 100644 index 00000000000..37b4ce1bc13 --- /dev/null +++ b/packages/connect/src/api/binance/api/binanceAbstractMethods.ts @@ -0,0 +1,21 @@ +import { Capability } from '@trezor/protobuf/src/messages-schema'; +import { AbstractMethod, Payload } from '../../../core/AbstractMethod'; +import { CallMethodPayload } from '../../../events'; +import { getFirmwareRange } from '../../common/paramsValidator'; +import { getMiscNetwork } from '../../../data/coinInfo'; + +export abstract class BinanceAbstractMethod< + Name extends CallMethodPayload['method'], + Params = undefined, +> extends AbstractMethod { + requiredDeviceCapabilities = [Capability.Binance]; + + constructor(message: { id?: number; payload: Payload }) { + super(message); + this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); + } + + // firmwareRangeRequirements could be defined here instead of config.ts + // loading coin-specific protobuf could be done here + // anything else? +} diff --git a/packages/connect/src/api/binance/api/binanceGetAddress.ts b/packages/connect/src/api/binance/api/binanceGetAddress.ts index 7ae967f1ea4..03b35395895 100644 --- a/packages/connect/src/api/binance/api/binanceGetAddress.ts +++ b/packages/connect/src/api/binance/api/binanceGetAddress.ts @@ -2,28 +2,28 @@ import { Assert } from '@trezor/schema-utils'; -import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; -import { getMiscNetwork } from '../../../data/coinInfo'; +import { MethodReturnType } from '../../../core/AbstractMethod'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { PROTO, ERRORS } from '../../../constants'; import { UI, createUiMessage } from '../../../events'; import { Bundle } from '../../../types'; import { GetAddress as GetAddressSchema } from '../../../types/api/getAddress'; +import { BinanceAbstractMethod } from './binanceAbstractMethods'; type Params = PROTO.BinanceGetAddress & { address?: string; }; -export default class BinanceGetAddress extends AbstractMethod<'binanceGetAddress', Params[]> { +export default class BinanceGetAddress extends BinanceAbstractMethod< + 'binanceGetAddress', + Params[] +> { hasBundle?: boolean; progress = 0; init() { this.noBackupConfirmationMode = 'always'; this.requiredPermissions = ['read']; - this.requiredDeviceCapabilities = ['Capability_Binance']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/binance/api/binanceGetPublicKey.ts b/packages/connect/src/api/binance/api/binanceGetPublicKey.ts index c9f15a1eb0b..eca51946843 100644 --- a/packages/connect/src/api/binance/api/binanceGetPublicKey.ts +++ b/packages/connect/src/api/binance/api/binanceGetPublicKey.ts @@ -2,15 +2,14 @@ import { Assert } from '@trezor/schema-utils'; -import { AbstractMethod, MethodReturnType } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; -import { getMiscNetwork } from '../../../data/coinInfo'; +import { MethodReturnType } from '../../../core/AbstractMethod'; import { validatePath, fromHardened, getSerializedPath } from '../../../utils/pathUtils'; import { UI, createUiMessage } from '../../../events'; import type { PROTO } from '../../../constants'; import { Bundle, GetPublicKey as GetPublicKeySchema } from '../../../types'; +import { BinanceAbstractMethod } from './binanceAbstractMethods'; -export default class BinanceGetPublicKey extends AbstractMethod< +export default class BinanceGetPublicKey extends BinanceAbstractMethod< 'binanceGetPublicKey', PROTO.BinanceGetPublicKey[] > { @@ -18,8 +17,6 @@ export default class BinanceGetPublicKey extends AbstractMethod< init() { this.requiredPermissions = ['read']; - this.requiredDeviceCapabilities = ['Capability_Binance']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); // create a bundle with only one batch if bundle doesn't exists this.hasBundle = !!this.payload.bundle; diff --git a/packages/connect/src/api/binance/api/binanceSignTransaction.ts b/packages/connect/src/api/binance/api/binanceSignTransaction.ts index 9b82cb0f509..3a6ac744170 100644 --- a/packages/connect/src/api/binance/api/binanceSignTransaction.ts +++ b/packages/connect/src/api/binance/api/binanceSignTransaction.ts @@ -2,13 +2,11 @@ import { AssertWeak } from '@trezor/schema-utils'; -import { AbstractMethod } from '../../../core/AbstractMethod'; -import { getFirmwareRange } from '../../common/paramsValidator'; -import { getMiscNetwork } from '../../../data/coinInfo'; import { validatePath } from '../../../utils/pathUtils'; import * as helper from '../binanceSignTx'; import { BinanceSignTransaction as BinanceSignTransactionSchema } from '../../../types/api/binance'; import type { BinancePreparedTransaction } from '../../../types/api/binance'; +import { BinanceAbstractMethod } from './binanceAbstractMethods'; type Params = { path: number[]; @@ -16,14 +14,12 @@ type Params = { chunkify?: boolean; }; -export default class BinanceSignTransaction extends AbstractMethod< +export default class BinanceSignTransaction extends BinanceAbstractMethod< 'binanceSignTransaction', Params > { init() { this.requiredPermissions = ['read', 'write']; - this.requiredDeviceCapabilities = ['Capability_Binance']; - this.firmwareRange = getFirmwareRange(this.name, getMiscNetwork('BNB'), this.firmwareRange); const { payload } = this; // validate incoming parameters