Skip to content

Commit

Permalink
chore(suite): interrupt discovery on connect popup
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Nov 22, 2024
1 parent 4fa2a3e commit d0ee74b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 1 addition & 2 deletions packages/connect-web/src/impl/core-in-suite-desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectSettingsWeb> {
public eventEmitter = new EventEmitter();
Expand Down
22 changes: 16 additions & 6 deletions packages/suite/src/middlewares/wallet/discoveryMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) ||
Expand Down
2 changes: 0 additions & 2 deletions suite-common/connect-init/src/connectInitThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit d0ee74b

Please sign in to comment.