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

[FIX] OpenSea Collection Name #628

Merged
merged 16 commits into from
Nov 25, 2021
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"ethjs-unit": "^0.1.6",
"ethjs-util": "^0.1.6",
"human-standard-collectible-abi": "^1.0.2",
"human-standard-multi-collectible-abi": "^1.0.2",
"human-standard-multi-collectible-abi": "^1.0.4",
"human-standard-token-abi": "^2.0.0",
"immer": "^9.0.6",
"isomorphic-fetch": "^3.0.0",
Expand Down
32 changes: 16 additions & 16 deletions src/assets/CollectibleDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,22 @@ describe('CollectibleDetectionController', () => {
name: 'Name',
symbol: 'FOO',
total_supply: 0,
collection: {
image_url: 'url',
name: 'Name',
},
})
.get(
`${OPEN_SEA_PATH}/asset_contract/0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD`,
)
.reply(200, {
description: 'Description HH',
image_url: 'url HH',
name: 'Name HH',
symbol: 'HH',
total_supply: 10,
collection: {
image_url: 'url HH',
name: 'Name HH',
},
})
.get(
`${OPEN_SEA_PATH}/asset_contract/0xCE7ec4B2DfB30eB6c0BB5656D33aAd6BFb4001Fc`,
Expand Down Expand Up @@ -282,8 +288,6 @@ describe('CollectibleDetectionController', () => {
name: 'ID 2574',
tokenId: '2574',
standard: 'ERC721',
collectionImage: 'url',
collectionName: 'Collection 2574',
},
]);
});
Expand Down Expand Up @@ -321,8 +325,6 @@ describe('CollectibleDetectionController', () => {
name: 'ID 2574',
tokenId: '2574',
standard: 'ERC721',
collectionImage: 'url',
collectionName: 'Collection 2574',
},
]);
});
Expand Down Expand Up @@ -382,8 +384,6 @@ describe('CollectibleDetectionController', () => {
name: 'ID 2574',
tokenId: '2574',
standard: 'ERC721',
collectionImage: 'url',
collectionName: 'Collection 2574',
};
const collectibleGG2574 = {
address: '0xCE7ec4B2DfB30eB6c0BB5656D33aAd6BFb4001Fc',
Expand All @@ -392,8 +392,6 @@ describe('CollectibleDetectionController', () => {
name: 'ID 2574',
tokenId: '2574',
standard: 'ERC721',
collectionImage: 'url',
collectionName: 'Collection 2574',
};
const collectibleII2577 = {
address: '0x0B0fa4fF58D28A88d63235bd0756EDca69e49e6d',
Expand All @@ -402,8 +400,6 @@ describe('CollectibleDetectionController', () => {
name: 'ID 2577',
tokenId: '2577',
standard: 'ERC721',
collectionImage: 'url',
collectionName: 'Collection 2577',
};
const collectibleContractHH = {
address: '0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD',
Expand Down Expand Up @@ -450,20 +446,24 @@ describe('CollectibleDetectionController', () => {
)
.reply(200, {
description: 'Description GG',
image_url: 'url GG',
name: 'Name GG',
symbol: 'GG',
total_supply: 10,
collection: {
image_url: 'url GG',
name: 'Name GG',
},
})
.get(
`${OPEN_SEA_PATH}/asset_contract/0x0B0fa4fF58D28A88d63235bd0756EDca69e49e6d`,
)
.reply(200, {
description: 'Description II',
image_url: 'url II',
name: 'Name II',
symbol: 'II',
total_supply: 10,
collection: {
image_url: 'url II',
name: 'Name II',
},
})
.get(`${OPEN_SEA_PATH}/assets?owner=0x1&offset=0&limit=50`)
.reply(200, {
Expand Down
28 changes: 5 additions & 23 deletions src/assets/CollectibleDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const DEFAULT_INTERVAL = 180000;
* @property assetContract - The collectible contract information object
* @property creator - The collectible owner information object
* @property lastSale - When this item was last sold
* @property collection - Collectible collection data object.
*/
export interface ApiCollectible {
token_id: string;
Expand All @@ -48,7 +47,6 @@ export interface ApiCollectible {
asset_contract: ApiCollectibleContract;
creator: ApiCollectibleCreator;
last_sale: ApiCollectibleLastSale | null;
collection: ApiCollectibleCollection;
}

/**
Expand All @@ -58,25 +56,26 @@ export interface ApiCollectible {
* @property address - Address of the collectible contract
* @property asset_contract_type - The collectible type, it could be `semi-fungible` or `non-fungible`
* @property created_date - Creation date
* @property name - The collectible contract name
* @property collection - Object containing the contract name and URI of an image associated
* @property schema_name - The schema followed by the contract, it could be `ERC721` or `ERC1155`
* @property symbol - The collectible contract symbol
* @property total_supply - Total supply of collectibles
* @property description - The collectible contract description
* @property external_link - External link containing additional information
* @property image_url - URI of an image associated with this collectible contract
*/
export interface ApiCollectibleContract {
address: string;
asset_contract_type: string | null;
created_date: string | null;
name: string | null;
schema_name: string | null;
symbol: string | null;
total_supply: string | null;
description: string | null;
external_link: string | null;
image_url: string | null;
collection: {
name: string | null;
image_url: string | null;
};
}

/**
Expand Down Expand Up @@ -107,18 +106,6 @@ export interface ApiCollectibleCreator {
address: string;
}

/**
* @type ApiCollectibleCollection
*
* Collectible collection object from OpenSea api.
* @property name - Collection name.
* @property image_url - URI collection image.
*/
export interface ApiCollectibleCollection {
name: string;
image_url: string;
}

/**
* @type CollectibleDetectionConfig
*
Expand Down Expand Up @@ -335,7 +322,6 @@ export class CollectibleDetectionController extends BaseController<
external_link,
creator,
asset_contract: { address, schema_name },
collection,
last_sale,
} = collectible;

Expand Down Expand Up @@ -376,10 +362,6 @@ export class CollectibleDetectionController extends BaseController<
schema_name && { standard: schema_name },
external_link && { externalLink: external_link },
last_sale && { lastSale: last_sale },
collection.name && { collectionName: collection.name },
collection.image_url && {
collectionImage: collection.image_url,
},
);
await this.addCollectible(
address,
Expand Down
32 changes: 12 additions & 20 deletions src/assets/CollectiblesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ describe('CollectiblesController', () => {
.get(`${OPEN_SEA_PATH}/asset_contract/0x01`)
.reply(200, {
description: 'Description',
image_url: 'url',
name: 'Name',
symbol: 'FOO',
total_supply: 0,
collection: {
name: 'Name',
image_url: 'url',
},
})
.get(`${OPEN_SEA_PATH}/asset_contract/0x02`)
.reply(200, {
Expand All @@ -82,6 +84,10 @@ describe('CollectiblesController', () => {
name: 'Name',
symbol: 'FOU',
total_supply: 10,
collection: {
name: 'Name',
image_url: 'url',
},
})
.get(`${OPEN_SEA_PATH}/asset/0x01/1`)
.reply(200, {
Expand All @@ -92,10 +98,6 @@ describe('CollectiblesController', () => {
asset_contract: {
schema_name: 'ERC1155',
},
collection: {
name: 'Collection Name',
image_url: 'collection.url',
},
})
.get(
`${OPEN_SEA_PATH}/asset/0x2aEa4Add166EBf38b63d09a75dE1a7b94Aa24163/1203`,
Expand All @@ -107,10 +109,6 @@ describe('CollectiblesController', () => {
asset_contract: {
schema_name: 'ERC721',
},
collection: {
name: 'Collection Name',
image_url: 'collection.url',
},
})
.get(
`${OPEN_SEA_PATH}/asset/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab/798958393`,
Expand All @@ -125,10 +123,12 @@ describe('CollectiblesController', () => {
)
.reply(200, {
description: 'Kudos Description',
image_url: 'Kudos url',
name: 'Kudos',
symbol: 'KDO',
total_supply: 10,
collection: {
name: 'Kudos',
image_url: 'Kudos url',
},
});

nock('https://ipfs.gitcoin.co:443')
Expand Down Expand Up @@ -162,7 +162,6 @@ describe('CollectiblesController', () => {
image: 'image',
description: 'description',
asset_contract: { schema_name: 'ERC1155' },
collection: { name: 'collection', image_uri: 'collection.uri' },
});

nock(CLOUDFARE_PATH).get(DEPRESSIONIST_IPFS_PATH).reply(200, {
Expand Down Expand Up @@ -317,8 +316,6 @@ describe('CollectiblesController', () => {
name: 'Name',
standard: 'ERC1155',
tokenId: '1',
collectionName: 'Collection Name',
collectionImage: 'collection.url',
});
});

Expand All @@ -336,7 +333,6 @@ describe('CollectiblesController', () => {
description: 'description',
tokenId:
'40815311521795738946686668571398122012172359753720345430028676522525371400193',
collectionName: 'collection',
imageOriginal: 'image.uri',
numberOfSales: 1,
standard: 'ERC1155',
Expand All @@ -360,8 +356,6 @@ describe('CollectiblesController', () => {
name: 'Kudos Name (from uri)',
description: 'Kudos Description (from uri)',
tokenId: '1203',
collectionImage: 'collection.url',
collectionName: 'Collection Name',
imageOriginal: 'Kudos url',
standard: 'ERC721',
});
Expand Down Expand Up @@ -472,8 +466,6 @@ describe('CollectiblesController', () => {
image: null,
standard: 'ERC721',
tokenId: '1203',
collectionImage: 'collection.url',
collectionName: 'Collection Name',
},
]);

Expand Down
15 changes: 3 additions & 12 deletions src/assets/CollectiblesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ export interface CollectibleContract {
* @property externalLink - External link containing additional information
* @property creator - The collectible owner information object
* @property standard - NFT standard name for the collectible, e.g., ERC-721 or ERC-1155
* @property collectionName - The name of the collectible collection.
* @property collectionImage - The image URI of the collectible collection.
*/
export interface CollectibleMetadata {
name: string | null;
Expand All @@ -114,8 +112,6 @@ export interface CollectibleMetadata {
externalLink?: string;
creator?: ApiCollectibleCreator;
lastSale?: ApiCollectibleLastSale;
collectionName?: string;
collectionImage?: string;
}

/**
Expand Down Expand Up @@ -219,7 +215,6 @@ export class CollectiblesController extends BaseController<
creator,
last_sale,
asset_contract: { schema_name },
collection,
} = collectibleInformation;

/* istanbul ignore next */
Expand All @@ -241,8 +236,6 @@ export class CollectiblesController extends BaseController<
external_link && { externalLink: external_link },
last_sale && { lastSale: last_sale },
schema_name && { standard: schema_name },
collection.name && { collectionName: collection.name },
collection.image_url && { collectionImage: collection.image_url },
);

return collectibleMetadata;
Expand Down Expand Up @@ -414,7 +407,7 @@ export class CollectiblesController extends BaseController<
const name = await this.getAssetName(contractAddress);
const symbol = await this.getAssetSymbol(contractAddress);
return {
name,
collection: { name, image_url: null },
symbol,
address: contractAddress,
};
Expand Down Expand Up @@ -450,13 +443,12 @@ export class CollectiblesController extends BaseController<
address: contractAddress,
asset_contract_type: null,
created_date: null,
name: null,
schema_name: null,
symbol: null,
total_supply: null,
description: null,
external_link: null,
image_url: null,
collection: { name: null, image_url: null },
};
}

Expand Down Expand Up @@ -561,13 +553,12 @@ export class CollectiblesController extends BaseController<
const {
asset_contract_type,
created_date,
name,
schema_name,
symbol,
total_supply,
description,
external_link,
image_url,
collection: { name, image_url },
} = contractInformation;
// If being auto-detected opensea information is expected
// Otherwise at least name and symbol from contract is needed
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4221,10 +4221,10 @@ human-standard-collectible-abi@^1.0.2:
resolved "https://registry.yarnpkg.com/human-standard-collectible-abi/-/human-standard-collectible-abi-1.0.2.tgz#077bae9ed1b0b0b82bc46932104b4b499c941aa0"
integrity sha512-nD3ITUuSAIBgkaCm9J2BGwlHL8iEzFjJfTleDAC5Wi8RBJEXXhxV0JeJjd95o+rTwf98uTE5MW+VoBKOIYQh0g==

human-standard-multi-collectible-abi@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/human-standard-multi-collectible-abi/-/human-standard-multi-collectible-abi-1.0.3.tgz#be5896b13f8622289cff70040e478366931bf3d7"
integrity sha512-1VXqats7JQqDZozLKhpmFG0S33hVePrkLNRJNKfJTxewR0heYKjSoz72kqs+6O/Tywi0zW4fWe7dfTaPX4j7gQ==
human-standard-multi-collectible-abi@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/human-standard-multi-collectible-abi/-/human-standard-multi-collectible-abi-1.0.4.tgz#981625bc1a6bea5fef90567f9e12c11581fac497"
integrity sha512-ylR9JDXClDJAxWD/QJxsjXJJdLTUmhipTquMAgrfybXL3qX3x3P/vmKg92A7qFu7SqVOf2hyv5dA8vX0j+0Thg==

human-standard-token-abi@^2.0.0:
version "2.0.0"
Expand Down