From aa41b751a652eaa7c8f38f47e281898aa0d70805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Thu, 6 Jun 2024 12:58:08 +0200 Subject: [PATCH] chore: allow for skiping HW device selection in the HW onboarding flows --- .github/shared/build/action.yml | 5 +++++ .github/workflows/e2e-tests-linux-split.yml | 1 + apps/browser-extension-wallet/.env.defaults | 3 +++ .../multi-wallet/hardware-wallet/steps/Connect.tsx | 14 ++++++++++++-- packages/cardano/src/wallet/lib/hardware-wallet.ts | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/shared/build/action.yml b/.github/shared/build/action.yml index 1653fd624..fa1b280ac 100644 --- a/.github/shared/build/action.yml +++ b/.github/shared/build/action.yml @@ -96,6 +96,10 @@ inputs: description: 'Browser target to build for. Options are [firefox | chromium]' required: false default: 'chromium' + E2E_FORCE_TREZOR_PICKED: + description: 'Force Trezor emulation' + required: false + default: 'false' runs: using: 'composite' steps: @@ -167,4 +171,5 @@ runs: SENTRY_ENVIRONMENT: ${{ inputs.SENTRY_ENVIRONMENT }} WALLET_POLLING_INTERVAL_IN_SEC: ${{ inputs.WALLET_POLLING_INTERVAL_IN_SEC }} BROWSER: ${{ inputs.BROWSER_TARGET }} + E2E_FORCE_TREZOR_PICKED: ${{ inputs.E2E_FORCE_TREZOR_PICKED }} run: yarn browser build diff --git a/.github/workflows/e2e-tests-linux-split.yml b/.github/workflows/e2e-tests-linux-split.yml index 330ca50f6..6826f5818 100644 --- a/.github/workflows/e2e-tests-linux-split.yml +++ b/.github/workflows/e2e-tests-linux-split.yml @@ -191,6 +191,7 @@ jobs: SENTRY_ENVIRONMENT: 'e2e-tests' WALLET_POLLING_INTERVAL_IN_SEC: 5 BROWSER_TARGET: ${{ env.BROWSER }} + E2E_FORCE_TREZOR_PICKED: true - name: Upload build artifact if: needs.setup.outputs.build_exists == 'false' diff --git a/apps/browser-extension-wallet/.env.defaults b/apps/browser-extension-wallet/.env.defaults index ce051e119..043b3e3c3 100644 --- a/apps/browser-extension-wallet/.env.defaults +++ b/apps/browser-extension-wallet/.env.defaults @@ -135,3 +135,6 @@ MIN_NUMBER_OF_COSIGNERS=2 # POLLING PAUSE AFTER INACTIVITY SESSION_TIMEOUT=120000 + +# e2e +E2E_FORCE_TREZOR_PICKED=false diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx index 4cceea886..3b85e12d7 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx @@ -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 { useWalletOnboarding } from '../../walletOnboardingContext'; @@ -41,6 +42,14 @@ 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(); @@ -48,6 +57,7 @@ export const Connect: VFC = () => { const [discoveryState, setDiscoveryState] = useState(DiscoveryState.Requested); const [connectionError, setConnectionError] = useState(null); const analytics = useAnalyticsContext(); + const forcedTrezorUsbDevice = useE2eForceTrezorPicked(); const translations = makeTranslations({ connectionError, t }); @@ -64,7 +74,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); @@ -75,7 +85,7 @@ export const Connect: VFC = () => { setConnectionError(parseConnectionError(error)); } })(); - }, [connect, discoveryState, analytics, next, postHogActions.hardware]); + }, [connect, discoveryState, analytics, next, postHogActions.hardware, forcedTrezorUsbDevice]); return ( productId === trezorModelTProductId); +export const trezorDescriptors = TREZOR_USB_DESCRIPTORS.filter(({ productId }) => productId === trezorModelTProductId); export const supportedHwUsbDescriptors = [...ledgerDescriptors, ...trezorDescriptors]; export const connectDeviceRevamped = async (usbDevice: USBDevice): Promise => {