From d0ee74bafb47061e3f140734649f7e1d1c2f1763 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Mon, 18 Nov 2024 13:12:17 +0100 Subject: [PATCH] chore(suite): interrupt discovery on connect popup --- .../src/impl/core-in-suite-desktop.ts | 3 +-- .../middlewares/wallet/discoveryMiddleware.ts | 22 ++++++++++++++----- .../connect-init/src/connectInitThunks.ts | 2 -- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/connect-web/src/impl/core-in-suite-desktop.ts b/packages/connect-web/src/impl/core-in-suite-desktop.ts index c677eacf9e34..8592c862bfd7 100644 --- a/packages/connect-web/src/impl/core-in-suite-desktop.ts +++ b/packages/connect-web/src/impl/core-in-suite-desktop.ts @@ -23,8 +23,7 @@ import { createDeferred, createDeferredManager, DeferredManager } from '@trezor/ import { parseConnectSettings } from '../connectSettings'; /** - * Base class for CoreInPopup methods for TrezorConnect factory. - * This implementation is directly used here in connect-web, but it is also extended in connect-webextension. + * CoreInSuiteDesktop implementation for TrezorConnect factory. */ export class CoreInSuiteDesktop implements ConnectFactoryDependencies { public eventEmitter = new EventEmitter(); diff --git a/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts b/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts index 5058b730fa03..0d27ec73480a 100644 --- a/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts +++ b/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts @@ -15,6 +15,7 @@ import { UI } from '@trezor/connect'; import { isDeviceAcquired } from '@suite-common/suite-utils'; import { DiscoveryStatus } from '@suite-common/wallet-constants'; import { createMiddlewareWithExtraDeps } from '@suite-common/redux-utils'; +import { connectPopupCallThunk } from '@suite-common/connect-init'; import { SUITE, ROUTER, MODAL } from 'src/actions/suite/constants'; import * as walletSettingsActions from 'src/actions/settings/walletSettingsActions'; @@ -46,12 +47,20 @@ export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps( } // consider if discovery should be interrupted - let interruptionIntent = action.type === deviceActions.selectDevice.type; - if (action.type === ROUTER.LOCATION_CHANGE) { - interruptionIntent = - getApp(action.payload.url) !== 'wallet' && - getApp(action.payload.url) !== 'dashboard' && - getApp(action.payload.url) !== 'settings'; + let interruptionIntent = false; + if (action.type === deviceActions.selectDevice.type) { + interruptionIntent = true; + } + if ( + action.type === ROUTER.LOCATION_CHANGE && + getApp(action.payload.url) !== 'wallet' && + getApp(action.payload.url) !== 'dashboard' && + getApp(action.payload.url) !== 'settings' + ) { + interruptionIntent = true; + } + if (action.type === MODAL.OPEN_USER_CONTEXT && action.payload.type === 'connect-popup') { + interruptionIntent = true; } // discovery interruption ends after DISCOVERY.STOP action @@ -144,6 +153,7 @@ export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps( if ( becomesConnected || action.type === SUITE.APP_CHANGED || + connectPopupCallThunk.fulfilled.match(action) || deviceActions.selectDevice.match(action) || authorizeDeviceThunk.fulfilled.match(action) || walletSettingsActions.changeNetworks.match(action) || diff --git a/suite-common/connect-init/src/connectInitThunks.ts b/suite-common/connect-init/src/connectInitThunks.ts index d0c9ec40c36d..b5af94e1c4a0 100644 --- a/suite-common/connect-init/src/connectInitThunks.ts +++ b/suite-common/connect-init/src/connectInitThunks.ts @@ -193,8 +193,6 @@ export const connectPopupCallThunk = createThunk( if (!device) { console.error('Device not found'); - // Need to select device first - dispatch(extra.thunks.openSwitchDeviceDialog()); // TODO: wait for device selection and continue throw ERRORS.TypedError('Device_NotFound');