Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/assets-controllers/src/NftDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,34 @@ describe('NftDetectionController', () => {
},
);
});

it('should only re-detect when relevant settings change', async () => {
await withController(
{},
async ({ controller, triggerPreferencesStateChange }) => {
const detectNfts = sinon.stub(controller, 'detectNfts');

// Repeated preference changes should only trigger 1 detection
for (let i = 0; i < 5; i++) {
triggerPreferencesStateChange({
...getDefaultPreferencesState(),
useNftDetection: true,
});
}
await advanceTime({ clock, duration: 1 });
expect(detectNfts.callCount).toBe(1);

// Irrelevant preference changes shouldn't trigger a detection
triggerPreferencesStateChange({
...getDefaultPreferencesState(),
useNftDetection: true,
securityAlertsEnabled: true,
});
await advanceTime({ clock, duration: 1 });
expect(detectNfts.callCount).toBe(1);
},
);
});
});

type WithControllerCallback<ReturnValue> = ({
Expand Down
3 changes: 0 additions & 3 deletions packages/assets-controllers/src/NftDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ export class NftDetectionController extends StaticIntervalPollingControllerV1<
!useNftDetection !== disabled
) {
this.configure({ selectedAddress, disabled: !useNftDetection });
}

if (useNftDetection !== undefined) {
if (useNftDetection) {
this.start();
} else {
Expand Down