Skip to content

Commit

Permalink
chore(connect): coinAbstractMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Nov 7, 2024
1 parent e701922 commit 55450ea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
21 changes: 21 additions & 0 deletions packages/connect/src/api/binance/api/binanceAbstractMethods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Capability } from '@trezor/protobuf/src/messages-schema';

Check warning on line 1 in packages/connect/src/api/binance/api/binanceAbstractMethods.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

There should be at least one empty line between import groups
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<Name, Params> {
requiredDeviceCapabilities = [Capability.Binance];

constructor(message: { id?: number; payload: Payload<Name> }) {
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?
}
12 changes: 6 additions & 6 deletions packages/connect/src/api/binance/api/binanceGetAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions packages/connect/src/api/binance/api/binanceGetPublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

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[]
> {
hasBundle?: boolean;

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@

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[];
transaction: BinancePreparedTransaction;
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
Expand Down

0 comments on commit 55450ea

Please sign in to comment.