diff --git a/src/assets/AssetsDetectionController.test.ts b/src/assets/AssetsDetectionController.test.ts index ba3f03e1b51..a0d0eefcfa6 100644 --- a/src/assets/AssetsDetectionController.test.ts +++ b/src/assets/AssetsDetectionController.test.ts @@ -132,6 +132,21 @@ describe('AssetsDetectionController', () => { token_id: '2574', }, ], + }) + .get(`${OPEN_SEA_PATH}/assets?owner=0x9&limit=300`) + .delay(800) + .reply(200, { + assets: [ + { + asset_contract: { + address: '0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD', + }, + description: 'Description 2574', + image_url: 'image/2574.png', + name: 'ID 2574', + token_id: '2574', + }, + ], }); }); @@ -292,6 +307,20 @@ describe('AssetsDetectionController', () => { expect(assets.state.collectibles).toStrictEqual([]); }); + it('should not detect and add collectibles to the wrong selectedAddress', async () => { + assetsDetection.configure({ + networkType: MAINNET, + selectedAddress: '0x9', + }); + assets.configure({ selectedAddress: '0x9' }); + assetsDetection.detectCollectibles(); + assetsDetection.configure({ selectedAddress: '0x12' }); + assets.configure({ selectedAddress: '0x12' }); + await new Promise((res) => setTimeout(() => res(true), 1000)); + expect(assetsDetection.config.selectedAddress).toStrictEqual('0x12'); + expect(assets.state.collectibles).toStrictEqual([]); + }); + it('should not add collectible if collectible or collectible contract has no information to display', async () => { const collectibleHH2574 = { address: '0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD', diff --git a/src/assets/AssetsDetectionController.ts b/src/assets/AssetsDetectionController.ts index 794af2e5c64..1193055324f 100644 --- a/src/assets/AssetsDetectionController.ts +++ b/src/assets/AssetsDetectionController.ts @@ -355,9 +355,10 @@ export class AssetsDetectionController extends BaseController< if (!this.isMainnet()) { return; } - const { selectedAddress } = this.config; + const requestedSelectedAddress = this.config.selectedAddress; + /* istanbul ignore else */ - if (!selectedAddress) { + if (!requestedSelectedAddress) { return; } await safelyExecute(async () => { @@ -395,7 +396,10 @@ export class AssetsDetectionController extends BaseController< }); } /* istanbul ignore else */ - if (!ignored) { + if ( + !ignored && + requestedSelectedAddress === this.config.selectedAddress + ) { /* istanbul ignore next */ const collectibleMetadata: CollectibleMetadata = Object.assign( {},