From b1630f7dfba7a66977e205e605b1c41372282c97 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 --- .../middlewares/wallet/discoveryMiddleware.ts | 22 ++++++++++++++----- .../connect-init/src/connectInitThunks.ts | 2 -- 2 files changed, 16 insertions(+), 8 deletions(-) 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');