Skip to content

Commit 1954b91

Browse files
committed
fix(suite-sync): tweak middlewares
1 parent c989c58 commit 1954b91

File tree

7 files changed

+26
-54
lines changed

7 files changed

+26
-54
lines changed

packages/suite/src/middlewares/suite/suiteMiddleware.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
selectIsDeviceAutoEjectEnabled,
1212
startOrRestartDiscoveryThunk,
1313
} from '@suite-common/wallet-core';
14+
import { isTrezorDeviceWithState } from '@suite-common/wallet-utils';
1415
import { DEVICE } from '@trezor/connect';
1516

1617
import { METADATA, ROUTER, SUITE } from 'src/actions/suite/constants';
@@ -44,7 +45,7 @@ const isActionDeviceRelated = (action: AnyAction): boolean => {
4445
};
4546

4647
export const prepareSuiteMiddleware = createMiddlewareWithExtraDeps(
47-
(action, { dispatch, next, getState }) => {
48+
(action, { dispatch, next, getState, extra }) => {
4849
const prevApp = getState().router.app;
4950
if (action.type === ROUTER.LOCATION_CHANGE && action.payload.app !== prevApp) {
5051
dispatch(appChanged(action.payload.app));
@@ -87,6 +88,17 @@ export const prepareSuiteMiddleware = createMiddlewareWithExtraDeps(
8788
// pass action to reducers
8889
next(action);
8990

91+
if (deviceActions.forgetDevice.match(action)) {
92+
const { device } = action.payload;
93+
94+
dispatch(handleDeviceDisconnect(device));
95+
if (isTrezorDeviceWithState(device)) {
96+
extra.services.suiteSync.turnOffSuiteSyncForWallet({
97+
owner: device.suiteSyncOwner,
98+
});
99+
}
100+
}
101+
90102
switch (action.type) {
91103
case SUITE.DESKTOP_HANDSHAKE:
92104
if (action.payload.protocol) {

suite-common/suite-sync/src/refreshSuiteSyncKeys.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export const createRefreshSuiteSyncKeys =
2424
return err(RefreshSuiteKeysUnavailable());
2525
}
2626

27-
// On connect device (musi mit features)
2827
const delegatedKeyResult = await deps.ensureDelegatedIdentityKey({ device });
2928

3029
if (!delegatedKeyResult.ok) {
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { isAnyOf } from '@reduxjs/toolkit';
22

33
import { createMiddlewareWithExtraDeps } from '@suite-common/redux-utils';
4-
import {
5-
applyDeviceStatesThunk,
6-
deviceActions,
7-
handleDeviceDisconnect,
8-
selectDeviceThunk,
9-
} from '@suite-common/wallet-core';
10-
import { isTrezorDeviceWithState } from '@suite-common/wallet-utils';
4+
import { applyDeviceStatesThunk, selectDeviceThunk } from '@suite-common/wallet-core';
115

126
import { selectIsSuiteSyncEnabled } from './suiteSyncSelectors';
137

@@ -20,25 +14,14 @@ const suiteSyncTurnOnTriggers = [
2014
] as const;
2115

2216
export const prepareSuiteSyncMiddleware = createMiddlewareWithExtraDeps(
23-
(action, { next, getState, extra, dispatch }) => {
17+
(action, { next, getState, extra }) => {
2418
if (selectIsSuiteSyncEnabled(getState()) && isAnyOf(...suiteSyncTurnOnTriggers)(action)) {
2519
const { payload } = action as ReturnType<(typeof suiteSyncTurnOnTriggers)[number]>;
2620
extra.services.suiteSync.turnOnSuiteSyncForWallet({
2721
staticSessionId: payload.device.state?.staticSessionId,
2822
});
2923
}
3024

31-
if (deviceActions.forgetDevice.match(action)) {
32-
const { device } = action.payload;
33-
34-
dispatch(handleDeviceDisconnect(device));
35-
if (isTrezorDeviceWithState(device)) {
36-
extra.services.suiteSync.turnOffSuiteSyncForWallet({
37-
owner: device.suiteSyncOwner,
38-
});
39-
}
40-
}
41-
4225
return next(action);
4326
},
4427
);

suite-native/device/src/middlewares/deviceMiddleware.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const isActionDeviceRelated = (action: AnyAction): boolean => {
3737
};
3838

3939
export const prepareDeviceMiddleware = createMiddlewareWithExtraDeps(
40-
(action, { dispatch, next, getState }) => {
40+
(action, { dispatch, next, getState, extra }) => {
4141
if (isDeviceEventAction(action, DEVICE.DISCONNECT)) {
4242
dispatch(forgetDisconnectedDevices({ device: action.payload }));
4343

@@ -53,9 +53,15 @@ export const prepareDeviceMiddleware = createMiddlewareWithExtraDeps(
5353

5454
if (deviceActions.forgetDevice.match(action)) {
5555
const { device } = action.payload;
56+
57+
dispatch(handleDeviceDisconnect(device));
58+
5659
if (isTrezorDeviceWithState(device)) {
5760
const accountsToRemove = selectAccountsByDeviceState(getState(), device.state);
5861
dispatch(accountsActions.removeAccount(accountsToRemove));
62+
extra.services.suiteSync.turnOffSuiteSyncForWallet({
63+
owner: device.suiteSyncOwner,
64+
});
5965
}
6066
}
6167

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export enum AccountLabelId {
22
BitcoinDefault1 = "m/84'/0'/0'",
33
BitcoinDefault2 = "m/84'/0'/1'",
4-
BitcoinDefault3 = "m/84'/0'/2'",
4+
BitcoinDefault3 = "m/84'/0'/3'",
55
BitcoinSegwit1 = "m/49'/0'/0'",
66
BitcoinSegwit2 = "m/49'/0'/1'",
77
}

suite/e2e/support/fixtures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ const test = suiteBaseTest.extend<Fixtures>({
9191
assetsSection: async ({ page }, use) => {
9292
await use(new AssetsSection(page));
9393
},
94-
metadataPage: async ({ page, settingsPage, dashboardPage, devicePrompt }, use) => {
95-
await use(new MetadataPage(page, settingsPage, dashboardPage, devicePrompt));
94+
metadataPage: async ({ page, settingsPage, devicePrompt }, use) => {
95+
await use(new MetadataPage(page, settingsPage, devicePrompt));
9696
},
9797
trezorInput: async ({ page }, use) => {
9898
await use(new TrezorInput(page));

suite/e2e/tests/metadata/account-metadata.test.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
4343
await expect(
4444
walletPage.accountLabel({ symbol: 'btc', type: 'normal', atIndex: 0 }),
4545
).toHaveText('even cooler');
46-
47-
await expect(
48-
metadataPage.account.successLabel(AccountLabelId.BitcoinDefault1),
49-
).toBeVisible();
50-
await expect(
51-
metadataPage.account.successLabel(AccountLabelId.BitcoinDefault1),
52-
).toBeHidden();
5346
});
5447

5548
await test.step('Discard label changes via Escape', async () => {
@@ -86,27 +79,6 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
8679
).toHaveText('Bitcoin #1');
8780
});
8881

89-
await test.step('Switch between segwit accounts and check success indicators', async () => {
90-
await walletPage.segwitGroupButton.click();
91-
await walletPage.openAccount({ symbol: 'btc', type: 'segwit', atIndex: 0 });
92-
93-
await metadataPage.account.addLabel(
94-
AccountLabelId.BitcoinSegwit1,
95-
'typing into one input',
96-
);
97-
await expect(
98-
metadataPage.account.successLabel(AccountLabelId.BitcoinSegwit1),
99-
).toBeVisible();
100-
101-
await walletPage.openAccount({ symbol: 'btc', type: 'segwit', atIndex: 1 });
102-
await expect(
103-
metadataPage.account.successLabel(AccountLabelId.BitcoinSegwit2),
104-
).toBeHidden();
105-
await expect(
106-
metadataPage.account.successLabel(AccountLabelId.BitcoinSegwit1),
107-
).toBeHidden();
108-
});
109-
11082
await test.step('Navigate to dashboard', async () => {
11183
await dashboardPage.dashboardMenuButton.click();
11284
await expect(dashboardPage.graph).toBeVisible();
@@ -122,7 +94,7 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
12294
'adding label to a newly added account. does it work?',
12395
);
12496
await expect(
125-
walletPage.accountLabel({ symbol: 'btc', type: 'normal', atIndex: 2 }),
97+
walletPage.accountLabel({ symbol: 'btc', type: 'normal', atIndex: 3 }),
12698
).toHaveText('adding label to a newly added account. does it work?');
12799
});
128100
});

0 commit comments

Comments
 (0)