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 18, 2024
1 parent 26115a9 commit 9be558b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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 @@ -20,6 +20,7 @@ import { SUITE, ROUTER, MODAL } from 'src/actions/suite/constants';
import * as walletSettingsActions from 'src/actions/settings/walletSettingsActions';
import { getApp } from 'src/utils/suite/router';
import { selectIsDeviceLocked } from 'src/reducers/suite/suiteReducer';

Check warning on line 22 in packages/suite/src/middlewares/wallet/discoveryMiddleware.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

There should be at least one empty line between import groups
import { connectPopupCallThunk } from '@suite-common/connect-init';

Check warning on line 23 in packages/suite/src/middlewares/wallet/discoveryMiddleware.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

`@suite-common/connect-init` import should occur before import of `src/actions/suite/constants`

export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps(
async (action, { dispatch, next, getState }) => {
Expand All @@ -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 9be558b

Please sign in to comment.