Skip to content

Commit 1f7c63d

Browse files
chore(suite): fix lint assertions
1 parent 3dee20e commit 1f7c63d

4 files changed

Lines changed: 40 additions & 29 deletions

File tree

packages/suite/jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ module.exports = {
4040
],
4141
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
4242
moduleNameMapper: {
43-
'^@suite/(.+)': '<rootDir>/../../suite/$1',
4443
'^@suite-common/(.+)': '<rootDir>/../../suite-common/$1',
4544
'^@trezor/(?!coins-)(.+)': '<rootDir>/../$1',
4645
'^src/(.+)': '<rootDir>/src/$1',

packages/suite/src/storage/migrations/versions/__tests__/26.8.0.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import '@suite-common/test-utils/src/globalOverrides';
22
import { type IDBPDatabase, deleteDB, openDB } from 'idb';
33

4+
import { type AccountKey } from '@suite-common/wallet-types';
5+
46
import { type SuiteDBSchema } from 'src/storage/definitions';
57

68
import migration from '../26.8.0';
@@ -26,6 +28,8 @@ describe('migration 26.8.0', () => {
2628
db.createObjectStore('receive');
2729
},
2830
});
31+
const accountKey = 'btc-account-key' as AccountKey;
32+
2933
await db.put(
3034
'receive',
3135
{
@@ -41,13 +45,13 @@ describe('migration 26.8.0', () => {
4145
address: 'fresh-btc-address',
4246
},
4347
},
44-
'btc-account-key',
48+
accountKey,
4549
);
4650
db.close();
4751

4852
const migratedDb = await runMigration();
4953

50-
expect(await migratedDb.get('receive', 'btc-account-key')).toEqual({
54+
expect(await migratedDb.get('receive', accountKey)).toEqual({
5155
touchedAddresses: [
5256
{
5357
path: 'btc-path',

packages/suite/src/views/wallet/sign-verify/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from 'react';
22
import { type FieldError } from 'react-hook-form';
33

4-
import { selectSelectedAccount, selectSelectedAccountKey } from '@suite/account';
4+
import { selectFullSelectedAccount, selectSelectedAccountKey } from '@suite/account';
55
import { useDevice } from '@suite/device';
66
import { Translation, type TranslationKey, useTranslation } from '@suite/intl';
77
import { type ReceiveRootState, selectTouchedAddresses } from '@suite-common/receive';
@@ -41,9 +41,8 @@ const SignVerify = () => {
4141
const [page, setPage] = useState<'sign' | 'verify'>('sign');
4242
const [isCompleted, setIsCompleted] = useState(false);
4343

44-
const selectedAccount = useSelector(selectSelectedAccount);
44+
const selectedAccount = useSelector(selectFullSelectedAccount);
4545
const selectedAccountKey = useSelector(selectSelectedAccountKey);
46-
const selectedNetwork = useSelector(state => state.wallet.selectedAccount.network);
4746
const touchedAddresses = useSelector((state: ReceiveRootState) =>
4847
selectTouchedAddresses(state, selectedAccountKey),
4948
);
@@ -65,11 +64,11 @@ const SignVerify = () => {
6564
pathField,
6665
isElectrumField,
6766
cardanoPubKeyCoseField,
68-
} = useSignVerifyForm(isSignPage, selectedAccount!);
67+
} = useSignVerifyForm(isSignPage, selectedAccount.account!);
6968

7069
const { isLocked, device } = useDevice();
7170
const { translationString } = useTranslation();
72-
const { canCopy, copy } = useCopySignedMessage(formValues, selectedNetwork);
71+
const { canCopy, copy } = useCopySignedMessage(formValues, selectedAccount.network);
7372

7473
const getErrorMessage = (error?: FieldError) =>
7574
error ? translationString(error.message as TranslationKey) : undefined;

suite-common/receive/src/receiveSlice.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ type SetCurrentFreshAddressPayload = {
3333
currentFreshAddress?: CurrentFreshAddress;
3434
};
3535

36+
type ReceiveStorageLoadPayload = {
37+
receive?: {
38+
key: string;
39+
value: ReceiveAccountState;
40+
}[];
41+
};
42+
3643
export const receiveInitialState: ReceiveState = {
3744
accounts: {},
3845
};
@@ -96,27 +103,29 @@ export const receiveSlice = createSliceWithExtraDeps({
96103
delete state.accounts[account.key];
97104
});
98105
})
99-
.addCase(extra.actionTypes.storageLoad, (state, action) => {
100-
const entries = action.payload?.receive as
101-
| {
102-
key: string;
103-
value: ReceiveAccountState;
104-
}[]
105-
| undefined;
106-
107-
state.accounts =
108-
entries?.reduce<ReceiveState['accounts']>((accounts, { key, value }) => {
109-
accounts[key as AccountKey] = {
110-
touchedAddresses: value.touchedAddresses.map(({ path, address }) => ({
111-
path,
112-
address,
113-
})),
114-
currentFreshAddress: value.currentFreshAddress,
115-
};
116-
117-
return accounts;
118-
}, {}) ?? {};
119-
});
106+
.addMatcher(
107+
(action): action is PayloadAction<ReceiveStorageLoadPayload | undefined> =>
108+
action.type === extra.actionTypes.storageLoad,
109+
(state, action) => {
110+
state.accounts =
111+
action.payload?.receive?.reduce<ReceiveState['accounts']>(
112+
(accounts, { key, value }) => {
113+
accounts[key as AccountKey] = {
114+
touchedAddresses: value.touchedAddresses.map(
115+
({ path, address }) => ({
116+
path,
117+
address,
118+
}),
119+
),
120+
currentFreshAddress: value.currentFreshAddress,
121+
};
122+
123+
return accounts;
124+
},
125+
{},
126+
) ?? {};
127+
},
128+
);
120129
},
121130
});
122131

0 commit comments

Comments
 (0)