Skip to content

Commit 05bf1ef

Browse files
committed
Move timeout to constant
1 parent d2326b8 commit 05bf1ef

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

packages/snaps-controllers/src/snaps/SnapController.test.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ import { pipeline } from 'readable-stream';
7171
import type { Duplex } from 'readable-stream';
7272
import { inc } from 'semver';
7373

74-
import { LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS } from './constants';
74+
import {
75+
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
76+
STATE_DEBOUNCE_TIMEOUT,
77+
} from './constants';
7578
import { SnapsRegistryStatus } from './registry';
7679
import type { SnapControllerState } from './SnapController';
7780
import {
@@ -9324,7 +9327,7 @@ describe('SnapController', () => {
93249327
DEFAULT_ENCRYPTION_KEY_DERIVATION_OPTIONS,
93259328
);
93269329

9327-
jest.advanceTimersByTime(5_000);
9330+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
93289331
await promise;
93299332

93309333
const result = await messenger.call(
@@ -9376,7 +9379,7 @@ describe('SnapController', () => {
93769379
true,
93779380
);
93789381

9379-
jest.advanceTimersByTime(5_000);
9382+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
93809383
await promise;
93819384

93829385
const encryptedState1 = await encrypt(
@@ -9605,7 +9608,7 @@ describe('SnapController', () => {
96059608
true,
96069609
);
96079610

9608-
jest.advanceTimersByTime(5_000);
9611+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
96099612
await promise;
96109613

96119614
expect(updateSnapStateSpy).toHaveBeenCalledTimes(1);
@@ -9641,7 +9644,7 @@ describe('SnapController', () => {
96419644

96429645
expect(updateSnapStateSpy).toHaveBeenCalledTimes(1);
96439646

9644-
jest.advanceTimersByTime(5_000);
9647+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
96459648
await promise;
96469649

96479650
expect(
@@ -9682,7 +9685,7 @@ describe('SnapController', () => {
96829685
true,
96839686
);
96849687

9685-
jest.advanceTimersByTime(5_000);
9688+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
96869689
await promise;
96879690

96889691
expect(hmacSha512).toHaveBeenCalledTimes(10);
@@ -9735,7 +9738,7 @@ describe('SnapController', () => {
97359738

97369739
expect(encryptWithKey).not.toHaveBeenCalled();
97379740

9738-
jest.advanceTimersByTime(5_000);
9741+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
97399742
await promise;
97409743

97419744
expect(encryptWithKey).toHaveBeenCalledTimes(1);
@@ -9752,7 +9755,7 @@ describe('SnapController', () => {
97529755
await messenger.call('SnapController:getSnapState', MOCK_SNAP_ID, true),
97539756
).toStrictEqual({ qux: 'quux' });
97549757

9755-
jest.advanceTimersByTime(5_000);
9758+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
97569759
await nextStateChange;
97579760

97589761
expect(encryptWithKey).toHaveBeenCalledTimes(2);
@@ -9788,7 +9791,7 @@ describe('SnapController', () => {
97889791
true,
97899792
);
97909793

9791-
jest.advanceTimersByTime(5_000);
9794+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
97929795
await promise;
97939796

97949797
expect(error).toHaveBeenCalledWith(errorValue);
@@ -9894,7 +9897,7 @@ describe('SnapController', () => {
98949897
// eslint-disable-next-line @typescript-eslint/await-thenable
98959898
await messenger.call('SnapController:clearSnapState', MOCK_SNAP_ID, true);
98969899

9897-
jest.advanceTimersByTime(5_000);
9900+
jest.advanceTimersByTime(STATE_DEBOUNCE_TIMEOUT);
98989901
await promise;
98999902

99009903
expect(error).toHaveBeenCalledWith(errorValue);

packages/snaps-controllers/src/snaps/SnapController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ import { gt } from 'semver';
134134
import {
135135
ALLOWED_PERMISSIONS,
136136
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
137+
STATE_DEBOUNCE_TIMEOUT,
137138
} from './constants';
138139
import type { SnapLocation } from './location';
139140
import { detectSnapLocation } from './location';
@@ -2000,7 +2001,7 @@ export class SnapController extends BaseController<
20002001
})
20012002
.catch(logError);
20022003
},
2003-
5_000,
2004+
STATE_DEBOUNCE_TIMEOUT,
20042005
);
20052006

20062007
/**

packages/snaps-controllers/src/snaps/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ export const LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = {
2020
iterations: 10_000,
2121
},
2222
};
23+
24+
/**
25+
* The timeout for debouncing state updates.
26+
*/
27+
export const STATE_DEBOUNCE_TIMEOUT = 1_000;

0 commit comments

Comments
 (0)