Skip to content

Commit 96eaa7e

Browse files
committed
[DDW-722] Code cleanup
1 parent fdb52b9 commit 96eaa7e

File tree

11 files changed

+82
-86
lines changed

11 files changed

+82
-86
lines changed

hardware-wallet-tests/cardano-app-already-launched.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const run = () => {
3636
deviceModel: expect.any(String),
3737
deviceName: expect.any(String),
3838
path: expect.any(String),
39+
product: expect.any(String),
3940
});
4041

4142
const cardanoAppChannelReply = await cardanoAppChannel.request(

hardware-wallet-tests/cardano-app-not-started.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const run = () => {
3636
deviceModel: expect.any(String),
3737
deviceName: expect.any(String),
3838
path: expect.any(String),
39+
product: expect.any(String),
3940
});
4041

4142
try {
@@ -49,28 +50,28 @@ export const run = () => {
4950
patch: expect.any(Number),
5051
deviceId: expect.any(String),
5152
});
52-
53-
const extendedPublicKey = await publicKeyChannel.request(
54-
{
55-
path: "1852'/1815'/0'",
56-
// Shelley 1852 ADA 1815 indicator for account '0'
57-
isTrezor: false,
58-
devicePath: params.path,
59-
},
60-
ipcRenderer,
61-
ipcRenderer
62-
);
63-
64-
expect(extendedPublicKey).toEqual({
65-
chainCodeHex: expect.any(String),
66-
publicKeyHex: expect.any(String),
67-
deviceId: expect.any(String),
68-
});
69-
70-
resolve();
7153
} catch (err) {
7254
return null;
7355
}
56+
57+
const extendedPublicKey = await publicKeyChannel.request(
58+
{
59+
path: "1852'/1815'/0'",
60+
// Shelley 1852 ADA 1815 indicator for account '0'
61+
isTrezor: false,
62+
devicePath: params.path,
63+
},
64+
ipcRenderer,
65+
ipcRenderer
66+
);
67+
68+
expect(extendedPublicKey).toEqual({
69+
chainCodeHex: expect.any(String),
70+
publicKeyHex: expect.any(String),
71+
deviceId: expect.any(String),
72+
});
73+
74+
resolve();
7475
}
7576
);
7677

hardware-wallet-tests/multiple-hardware-wallets.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ export const run = () => {
1515

1616
const hardwareWalletConnectionChannel = createHardwareWalletConnectionChannel();
1717

18-
const promptMessages = createTestInstructions([
18+
createTestInstructions([
1919
'Start test runner',
2020
'Plug Ledger Nano S to your computer',
2121
'Plug Ledger Nano X to your computer',
2222
]);
2323

24-
promptMessages();
25-
26-
const expectedSequence = createSequentialResult([
24+
const getNextExpectedSequence = createSequentialResult([
2725
{
2826
disconnected: false,
2927
deviceModel: 'nanoS',
@@ -37,7 +35,7 @@ export const run = () => {
3735
return new Promise((resolve) => {
3836
hardwareWalletConnectionChannel.onReceive(
3937
async (message: { path: string; deviceModel: string }) => {
40-
const [expectedValue, isOver] = expectedSequence();
38+
const [expectedValue, isOver] = getNextExpectedSequence();
4139
expect(message).toEqual(expectedValue);
4240

4341
if (isOver) {

hardware-wallet-tests/remove-multiple-hardware-wallets.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
createTestInstructions,
99
} from './utils';
1010

11-
const expectedSequence = createSequentialResult([
11+
const getNextExpectedSequence = createSequentialResult([
1212
{
1313
disconnected: false,
1414
deviceModel: 'nanoS',
@@ -34,27 +34,23 @@ export const run = () => {
3434

3535
const hardwareWalletConnectionChannel = createHardwareWalletConnectionChannel();
3636

37-
const promptMessages = createTestInstructions([
37+
createTestInstructions([
3838
'Connect Nano S',
3939
'Connect Nano X',
4040
'Disconnect Nano S',
4141
'Disconnect Nano X',
4242
]);
4343

44-
promptMessages();
45-
4644
return new Promise((resolve) => {
4745
hardwareWalletConnectionChannel.onReceive(
4846
async (params: { path: string; deviceModel: string }) => {
49-
const [expectedValue, isOver] = expectedSequence();
47+
const [expectedValue, isOver] = getNextExpectedSequence();
5048

5149
expect(params).toEqual(expectedValue);
5250

5351
if (isOver) {
5452
return resolve(null);
5553
}
56-
57-
promptMessages();
5854
}
5955
);
6056

hardware-wallet-tests/remove-single-hardware-wallet.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
export const run = () => {
1212
expect.assertions(3);
1313

14-
const promptMessages = createTestInstructions([
14+
createTestInstructions([
1515
'Plug Ledger Nano S to your computer',
1616
'Disconnect Nano S',
1717
]);
@@ -20,7 +20,7 @@ export const run = () => {
2020

2121
const hardwareWalletConnectionChannel = createHardwareWalletConnectionChannel();
2222

23-
const expectedSequence = createSequentialResult([
23+
const getNextExpectedSequence = createSequentialResult([
2424
{
2525
disconnected: false,
2626
},
@@ -29,16 +29,13 @@ export const run = () => {
2929
},
3030
]);
3131

32-
promptMessages();
33-
3432
return new Promise((resolve) => {
3533
hardwareWalletConnectionChannel.onReceive(
3634
async (params: { path: string }) => {
37-
const [expectedValue, isOver] = expectedSequence();
35+
const [expectedValue, isOver] = getNextExpectedSequence();
3836
expect(params).toEqual(expectedValue);
3937

4038
if (isOver) return resolve(null);
41-
promptMessages();
4239
}
4340
);
4441

hardware-wallet-tests/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const createSequentialResult = (sequence: Array<Partial<Result>>) => {
115115
deviceModel: expect.any(String),
116116
deviceName: expect.any(String),
117117
path: expect.any(String),
118+
product: expect.any(String),
118119
};
119120

120121
const result = sequence.map((s) => ({ ...common, ...s }));
@@ -127,6 +128,4 @@ export const log = (message: string) =>
127128

128129
export const createTestInstructions = (messages: string[]) => {
129130
messages.forEach((m, i) => log(`${i + 1} - ${m}`));
130-
131-
return () => log(messages.shift());
132131
};

source/common/ipc/api.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BridgeInfo, Device as TrezorDevice, UdevInfo } from 'trezor-connect';
21
import type {
32
BugReportRequestHttpOptions,
43
BugReportRequestPayload,
@@ -62,6 +61,9 @@ import type {
6261
TrezorSignTransactionRequest,
6362
TrezorSignTransactionResponse,
6463
HardwareWalletConnectionRequest,
64+
LedgerDevicePayload,
65+
TrezorDevicePayload,
66+
TrezorDeviceErrorPayload,
6567
} from '../types/hardware-wallets.types';
6668

6769
/**
@@ -465,37 +467,6 @@ export type GetBlockSyncProgressMainResponse = {
465467
* Channels for connecting / interacting with Hardware Wallet devices
466468
*/
467469

468-
export type LedgerDevicePayload = {
469-
disconnected: boolean;
470-
deviceType: 'ledger';
471-
deviceId: string | null;
472-
deviceModel: string;
473-
deviceName: string;
474-
path: string;
475-
product: string;
476-
};
477-
478-
export type TrezorDevicePayload = {
479-
disconnected: boolean;
480-
deviceId: string;
481-
deviceType: 'trezor';
482-
deviceModel: TrezorDevice;
483-
// e.g. "1" or "T"
484-
deviceName: string;
485-
path: string;
486-
eventType: string;
487-
};
488-
489-
export type TrezorDeviceErrorPayload = {
490-
error?: {
491-
payload: {
492-
error: string;
493-
bridge?: BridgeInfo;
494-
udev?: UdevInfo;
495-
};
496-
};
497-
};
498-
499470
export const GET_HARDWARE_WALLET_TRANSPORT_CHANNEL =
500471
'GET_HARDWARE_WALLET_TRANSPORT_CHANNEL';
501472
export type getHardwareWalletTransportRendererRequest = HardwareWalletTransportDeviceRequest;

source/common/types/hardware-wallets.types.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { BridgeInfo, Device as TrezorDevice, UdevInfo } from 'trezor-connect';
2+
13
export type BIP32Path = Array<number>;
24
export type LedgerModel = 'nanoS' | 'nanoX';
35
export type TrezorModel = '1' | 'T';
@@ -31,13 +33,10 @@ export const DeviceModels: {
3133
TREZOR_ONE: '1',
3234
TREZOR_T: 'T',
3335
};
34-
export const DeviceTypes: {
35-
LEDGER: DeviceType;
36-
TREZOR: DeviceType;
37-
} = {
38-
LEDGER: 'ledger',
39-
TREZOR: 'trezor',
40-
};
36+
export enum DeviceTypes {
37+
LEDGER = 'ledger',
38+
TREZOR = 'trezor',
39+
}
4140
export const DeviceEvents: {
4241
CONNECT: DeviceEvent;
4342
CONNECT_UNACQUIRED: DeviceEvent;
@@ -296,6 +295,42 @@ export type TrezorSignTransactionResponse = {
296295
success: boolean;
297296
payload: TrezorSerializedTxPayload | TrezorRawTxPayload;
298297
};
298+
299+
export type LedgerDevicePayload = {
300+
disconnected: boolean;
301+
deviceType: 'ledger';
302+
deviceId: string | null;
303+
deviceModel: string;
304+
deviceName: string;
305+
path: string;
306+
product: string;
307+
};
308+
309+
export type TrezorDevicePayload = {
310+
disconnected: boolean;
311+
deviceId: string;
312+
deviceType: 'trezor';
313+
deviceModel: TrezorDevice;
314+
// e.g. "1" or "T"
315+
deviceName: string;
316+
path: string;
317+
eventType: string;
318+
};
319+
320+
export type TrezorDeviceErrorPayload = {
321+
deviceType: 'trezor';
322+
error?: {
323+
payload: {
324+
error: string;
325+
bridge?: BridgeInfo;
326+
udev?: UdevInfo;
327+
code?: string;
328+
};
329+
};
330+
};
331+
332+
// FIXME: This should be LedgerDevicePayload | TrezorDevicePayload | TrezorDeviceErrorPayload
333+
// Changing so will result in a huge refactoring on HardwareWalletsStore._changeHardwareWalletConnectionStatus
299334
export type HardwareWalletConnectionRequest = {
300335
disconnected: boolean;
301336
deviceType: DeviceType;

source/main/ipc/getHardwareWalletChannel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export const handleHardwareWalletRequests = async (
188188
// Send Transport error to Renderer
189189
getHardwareWalletConnectionChannel.send(
190190
{
191+
deviceType: 'trezor',
191192
error: {
192193
payload: event.payload,
193194
},
@@ -381,7 +382,6 @@ export const handleHardwareWalletRequests = async (
381382
deviceName: productName,
382383
// e.g. Ledger Nano S
383384
path: lastConnectedPath || devicePath,
384-
firmwareVersion: null,
385385
};
386386

387387
logger.info(

source/main/utils/logging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const logToLevel = (level: string) => (
3434
});
3535

3636
export const logger: Logger = {
37-
debug: logToLevel('info'),
37+
debug: logToLevel('debug'),
3838
info: logToLevel('info'),
3939
error: logToLevel('error'),
4040
warn: logToLevel('warn'),

0 commit comments

Comments
 (0)