Skip to content

Commit 870d6e8

Browse files
chore: allow for skipping HW device selection in the HW onboarding flows (#1210)
1 parent 58c38ad commit 870d6e8

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

.github/shared/build/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ inputs:
102102
description: 'Browser target to build for. Options are [firefox | chromium]'
103103
required: false
104104
default: 'chromium'
105+
E2E_FORCE_TREZOR_PICKED:
106+
description: 'Force Trezor emulation'
107+
required: false
108+
default: 'false'
105109
runs:
106110
using: 'composite'
107111
steps:
@@ -175,4 +179,5 @@ runs:
175179
SENTRY_ENVIRONMENT: ${{ inputs.SENTRY_ENVIRONMENT }}
176180
WALLET_POLLING_INTERVAL_IN_SEC: ${{ inputs.WALLET_POLLING_INTERVAL_IN_SEC }}
177181
BROWSER: ${{ inputs.BROWSER_TARGET }}
182+
E2E_FORCE_TREZOR_PICKED: ${{ inputs.E2E_FORCE_TREZOR_PICKED }}
178183
run: yarn browser build

.github/workflows/e2e-tests-linux-split.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ jobs:
193193
SENTRY_ENVIRONMENT: 'e2e-tests'
194194
WALLET_POLLING_INTERVAL_IN_SEC: 5
195195
BROWSER_TARGET: ${{ env.BROWSER }}
196+
E2E_FORCE_TREZOR_PICKED: true
196197

197198
- name: Upload build artifact
198199
if: needs.setup.outputs.build_exists == 'false'

apps/browser-extension-wallet/.env.defaults

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,6 @@ MIN_NUMBER_OF_COSIGNERS=2
135135

136136
# POLLING PAUSE AFTER INACTIVITY
137137
SESSION_TIMEOUT=120000
138+
139+
# e2e
140+
E2E_FORCE_TREZOR_PICKED=false

apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TranslationKey } from '@lace/translation';
55
import { TFunction } from 'i18next';
66
import React, { useCallback, useEffect, useState, VFC } from 'react';
77
import { useTranslation } from 'react-i18next';
8+
import { useLocation } from 'react-router-dom';
89
import { useAnalyticsContext } from '@providers';
910
import { useHardwareWallet } from '../context';
1011
import { useWalletOnboarding } from '../../walletOnboardingContext';
@@ -41,13 +42,22 @@ enum DiscoveryState {
4142
Running = 'Running'
4243
}
4344

45+
const useE2eForceTrezorPicked = (): USBDevice | null => {
46+
const { search } = useLocation();
47+
if (process.env.E2E_FORCE_TREZOR_PICKED !== 'true') return null;
48+
49+
const forceTrezorPicked = new URLSearchParams(search).has('force-trezor-picked');
50+
return forceTrezorPicked ? (Wallet.trezorDescriptors[0] as USBDevice) : null;
51+
};
52+
4453
export const Connect: VFC = () => {
4554
const { t } = useTranslation();
4655
const { postHogActions } = useWalletOnboarding();
4756
const { back, connect, next } = useHardwareWallet();
4857
const [discoveryState, setDiscoveryState] = useState<DiscoveryState>(DiscoveryState.Requested);
4958
const [connectionError, setConnectionError] = useState<ConnectionError | null>(null);
5059
const analytics = useAnalyticsContext();
60+
const forcedTrezorUsbDevice = useE2eForceTrezorPicked();
5161

5262
const translations = makeTranslations({ connectionError, t });
5363

@@ -64,7 +74,7 @@ export const Connect: VFC = () => {
6474
setDiscoveryState(DiscoveryState.Running);
6575
try {
6676
void analytics.sendEventToPostHog(postHogActions.hardware.CONNECT_HW_VIEW);
67-
const usbDevice = await requestHardwareWalletConnection();
77+
const usbDevice = forcedTrezorUsbDevice || (await requestHardwareWalletConnection());
6878
void analytics.sendEventToPostHog(postHogActions.hardware.HW_POPUP_CONNECT_CLICK);
6979
await connect(usbDevice);
7080
setDiscoveryState(DiscoveryState.Idle);
@@ -75,7 +85,7 @@ export const Connect: VFC = () => {
7585
setConnectionError(parseConnectionError(error));
7686
}
7787
})();
78-
}, [connect, discoveryState, analytics, next, postHogActions.hardware]);
88+
}, [connect, discoveryState, analytics, next, postHogActions.hardware, forcedTrezorUsbDevice]);
7989

8090
return (
8191
<WalletSetupConnectHardwareWalletStepRevamp

packages/cardano/src/wallet/lib/hardware-wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const ledgerDescriptors = [{ vendorId: ledgerUSBVendorId }];
5050

5151
// eslint-disable-next-line unicorn/number-literal-case
5252
const trezorModelTProductId = 0x53_c1;
53-
const trezorDescriptors = TREZOR_USB_DESCRIPTORS.filter(({ productId }) => productId === trezorModelTProductId);
53+
export const trezorDescriptors = TREZOR_USB_DESCRIPTORS.filter(({ productId }) => productId === trezorModelTProductId);
5454
export const supportedHwUsbDescriptors = [...ledgerDescriptors, ...trezorDescriptors];
5555

5656
export const connectDeviceRevamped = async (usbDevice: USBDevice): Promise<HardwareWalletConnection> => {

0 commit comments

Comments
 (0)