Skip to content

Commit 6884767

Browse files
authored
OpenSea supply -> total_supply (#3692)
## Explanation OpenSea renamed the field `supply`, which used to be required, to `total_supply`. Fixes the error: `undefined is not an object (evaluating 'contract.supply.toString')` A more accurate `total_supply` was also added to the collection object, which is now preferred to the one on the contract. ## References ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/assets-controllers` - **FIXED**: OpenSea response from `supply` to `total_supply` ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate
1 parent 509e580 commit 6884767

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

packages/assets-controllers/src/NftController.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ describe('NftController', () => {
272272
collection: 'FOO',
273273
contract_standard: 'erc721',
274274
name: 'Name',
275-
supply: 0,
275+
total_supply: 0,
276276
})
277277
.get(`/collections/FOO`)
278278
.reply(200, {
@@ -286,7 +286,7 @@ describe('NftController', () => {
286286
collection: 'FOU',
287287
contract_standard: 'erc721',
288288
name: 'FOU',
289-
supply: 0,
289+
total_supply: 0,
290290
})
291291
.get(`/collections/FOO`)
292292
.reply(200, {
@@ -1288,7 +1288,7 @@ describe('NftController', () => {
12881288
collection: 'Kudos',
12891289
contract_standard: 'erc721',
12901290
name: 'Name',
1291-
supply: 10,
1291+
total_supply: 10,
12921292
});
12931293

12941294
nock('https://ipfs.gitcoin.co:443')
@@ -1845,7 +1845,7 @@ describe('NftController', () => {
18451845
collection: 'KDO',
18461846
contract_standard: 'erc721',
18471847
name: 'Kudos',
1848-
supply: 10,
1848+
total_supply: 10,
18491849
})
18501850
.get(`/collections/KDO`)
18511851
.reply(200, {

packages/assets-controllers/src/NftController.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export type OpenSeaV2Contract = {
105105
collection: string;
106106
contract_standard: string;
107107
name: string;
108-
supply: number;
108+
total_supply?: number;
109109
};
110110

111111
export type OpenSeaV2Collection = {
@@ -125,6 +125,7 @@ export type OpenSeaV2Collection = {
125125
telegram_url?: string;
126126
twitter_username?: string;
127127
instagram_username?: string;
128+
total_supply?: number;
128129
};
129130

130131
/**

packages/assets-controllers/src/NftDetectionController.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('NftDetectionController', () => {
166166
collection: 'Name',
167167
contract_standard: 'erc721',
168168
name: 'Name',
169-
supply: 0,
169+
total_supply: 0,
170170
})
171171
.get(
172172
`/chain/ethereum/contract/0xebE4e5E773AFD2bAc25De0cFafa084CFb3cBf1eD`,
@@ -177,7 +177,7 @@ describe('NftDetectionController', () => {
177177
collection: 'Name HH',
178178
contract_standard: 'erc721',
179179
name: 'Name HH',
180-
supply: 10,
180+
total_supply: 10,
181181
})
182182
.get(`/collections/Name%20HH`)
183183
.reply(200, {
@@ -694,7 +694,7 @@ describe('NftDetectionController', () => {
694694
collection: 'Name GG',
695695
contract_standard: 'erc721',
696696
name: 'Name GG',
697-
supply: 10,
697+
total_supply: 10,
698698
})
699699
.get(`/collections/Name%20GG`)
700700
.reply(200, {
@@ -710,7 +710,7 @@ describe('NftDetectionController', () => {
710710
collection: 'Name II',
711711
contract_standard: 'erc721',
712712
name: 'Name II',
713-
supply: 10,
713+
total_supply: 10,
714714
})
715715
.get(`/collections/Name%20II`)
716716
.reply(200, {
@@ -878,7 +878,7 @@ describe('NftDetectionController', () => {
878878
collection: 'mycollection',
879879
contract_standard: 'erc721',
880880
name: 'myname',
881-
supply: 0,
881+
total_supply: 0,
882882
})
883883
.get(`/collections/mycollection`)
884884
.reply(200, {});

packages/assets-controllers/src/assetsUtil.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,10 @@ export function mapOpenSeaContractV2ToV1(
376376
created_date: null,
377377
schema_name: contract.contract_standard.toUpperCase(),
378378
symbol: null,
379-
total_supply: contract.supply.toString(),
379+
total_supply:
380+
collection?.total_supply?.toString() ??
381+
contract.total_supply?.toString() ??
382+
null,
380383
description: collection?.description ?? null,
381384
external_link: collection?.project_url ?? null,
382385
collection: {

0 commit comments

Comments
 (0)