Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: allow for skipping HW device selection in the HW onboarding flows #1210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e-tests-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ env:
DISPLAY: ':99.0'
NODE_OPTIONS: --max-old-space-size=16384
BRANCH: ${{ github.ref_name }}
E2E_FORCE_TREZOR_PICKED: true

jobs:
tests:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e-tests-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ env:
NETWORK: ${{ github.event.inputs.network || 'preprod' }}
RUN: ${{ github.run_number }}
BRANCH: ${{ github.ref_name }}
E2E_FORCE_TREZOR_PICKED: true

jobs:
build-extension-linux:
Expand Down
5 changes: 4 additions & 1 deletion apps/browser-extension-wallet/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@ LACE_EXTENSION_KEY=gafhhkghbfjjkeiendhlofajokpaflmk
# Extension uninstall redirect
LACE_EXTENSION_UNINSTALL_REDIRECT_URL=https://forms.gle/XNcPfWafY8XgxkYw7

# Midnight
# Midnight
MIDNIGHT_EVENT_BANNER_REMINDER_TIME=129600000

# e2e
E2E_FORCE_TREZOR_PICKED=false
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TranslationKey } from '@lace/translation';
import { TFunction } from 'i18next';
import React, { useCallback, useEffect, useState, VFC } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { useAnalyticsContext } from '@providers';
import { useHardwareWallet } from '../context';
import { isTimeoutError } from '../useWrapWithTimeout';
Expand Down Expand Up @@ -62,13 +63,22 @@ enum DiscoveryState {
Running = 'Running'
}

const useE2eForceTrezorPicked = (): USBDevice | null => {
const { search } = useLocation();
if (process.env.E2E_FORCE_TREZOR_PICKED !== 'true') return null;

const forceTrezorPicked = new URLSearchParams(search).has('force-trezor-picked');
return forceTrezorPicked ? (Wallet.trezorDescriptors[0] as USBDevice) : null;
};

export const Connect: VFC = () => {
const { t } = useTranslation();
const { postHogActions } = useWalletOnboarding();
const { back, connect, next } = useHardwareWallet();
const [discoveryState, setDiscoveryState] = useState<DiscoveryState>(DiscoveryState.Requested);
const [connectionError, setConnectionError] = useState<ConnectionError | null>(null);
const analytics = useAnalyticsContext();
const forcedTrezorUsbDevice = useE2eForceTrezorPicked();

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

Expand All @@ -85,7 +95,7 @@ export const Connect: VFC = () => {
setDiscoveryState(DiscoveryState.Running);
try {
void analytics.sendEventToPostHog(postHogActions.hardware.CONNECT_HW_VIEW);
const usbDevice = await requestHardwareWalletConnection();
const usbDevice = forcedTrezorUsbDevice || (await requestHardwareWalletConnection());
void analytics.sendEventToPostHog(postHogActions.hardware.HW_POPUP_CONNECT_CLICK);
await connect(usbDevice);
setDiscoveryState(DiscoveryState.Idle);
Expand All @@ -96,7 +106,7 @@ export const Connect: VFC = () => {
setConnectionError(parseConnectionError(error));
}
})();
}, [connect, discoveryState, analytics, next, postHogActions.hardware]);
}, [connect, discoveryState, analytics, next, postHogActions.hardware, forcedTrezorUsbDevice]);

return (
<WalletSetupConnectHardwareWalletStepRevamp
Expand Down
2 changes: 1 addition & 1 deletion packages/cardano/src/wallet/lib/hardware-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ledgerDescriptors = [

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

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