Skip to content

Commit

Permalink
bugfix/dont remove collectibles during auto detection (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino authored and MajorLift committed Oct 11, 2023
1 parent fb55479 commit 0600f65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
20 changes: 11 additions & 9 deletions src/assets/AssetsDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,22 @@ describe('AssetsDetectionController', () => {
]);
});

it('should detect, add collectibles and remove not detected collectibles correctly', async () => {
it('should detect, add collectibles and do nor remove not detected collectibles correctly', async () => {
assetsDetection.configure({ networkType: MAINNET, selectedAddress: '0x1' });
await assets.addCollectible('0x1D963688FE2209A98db35c67A041524822cf04Hh', 2573, {
description: 'desc',
image: 'image',
name: 'name',
});
await assets.addCollectible('0x1D963688FE2209A98db35c67A041524822cf04Hh', 2572, {
description: 'desc',
image: 'image',
name: 'name',
description: 'Description 2573',
image: 'image/2573.png',
name: 'ID 2573',
});
await assetsDetection.detectCollectibles();
expect(assets.state.collectibles).toEqual([
{
address: '0x1D963688FE2209A98db35c67A041524822cf04Hh',
description: 'Description 2573',
image: 'image/2573.png',
name: 'ID 2573',
tokenId: 2573,
},
{
address: '0x1D963688FE2209A98db35c67A041524822cf04Hh',
description: 'Description 2574',
Expand Down
7 changes: 0 additions & 7 deletions src/assets/AssetsDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ export class AssetsDetectionController extends BaseController<AssetsDetectionCon
await safelyExecute(async () => {
const assetsController = this.context.AssetsController as AssetsController;
const { ignoredCollectibles } = assetsController.state;
let collectiblesToRemove = assetsController.state.collectibles;
const apiCollectibles = await this.getOwnerCollectibles();
const addCollectiblesPromises = apiCollectibles.map(async (collectible: ApiCollectibleResponse) => {
const {
Expand Down Expand Up @@ -242,14 +241,8 @@ export class AssetsDetectionController extends BaseController<AssetsDetectionCon
true,
);
}
collectiblesToRemove = collectiblesToRemove.filter((c) => {
return !(c.tokenId === Number(token_id) && c.address === toChecksumAddress(address));
});
});
await Promise.all(addCollectiblesPromises);
collectiblesToRemove.forEach(({ address, tokenId }) => {
assetsController.removeCollectible(address, tokenId);
});
});
}

Expand Down

0 comments on commit 0600f65

Please sign in to comment.