Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/collectible detection by acccount #487

Merged
merged 3 commits into from
Jun 4, 2021
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
29 changes: 29 additions & 0 deletions src/assets/AssetsDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
});
});

Expand Down Expand Up @@ -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',
Expand Down
10 changes: 7 additions & 3 deletions src/assets/AssetsDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,10 @@ export class AssetsDetectionController extends BaseController<
if (!this.isMainnet()) {
return;
}
const { selectedAddress } = this.config;
const requestedSelectedAddress = this.config.selectedAddress;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for the rename? seems selectedAddress would still be fine no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm not really, just to be clear that it was the address from where it was being called

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go back to selectedAddress if you want 👌

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah it's fine.

just to be clear that it was the address from where it was being called

I think that's plenty reason enough to rename. feel free to merge.


/* istanbul ignore else */
if (!selectedAddress) {
if (!requestedSelectedAddress) {
return;
}
await safelyExecute(async () => {
Expand Down Expand Up @@ -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(
{},
Expand Down