diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index db89426299bb..e6257b303769 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -661,6 +661,7 @@ export default class MetamaskController extends EventEmitter { this.assetsContractController, ), addNft: this.nftController.addNft.bind(this.nftController), + getNftApi: this.nftController.getNftApi.bind(this.nftController), getNftState: () => this.nftController.state, }); diff --git a/package.json b/package.json index d61f9e7fd54b..12c73efe7fa5 100644 --- a/package.json +++ b/package.json @@ -245,7 +245,7 @@ "@metamask/address-book-controller": "^3.0.0", "@metamask/announcement-controller": "^4.0.0", "@metamask/approval-controller": "^3.4.0", - "@metamask/assets-controllers": "^21.0.0", + "@metamask/assets-controllers": "^22.0.0", "@metamask/base-controller": "^3.2.0", "@metamask/browser-passworder": "^4.1.0", "@metamask/contract-metadata": "^2.3.1", diff --git a/test/e2e/tests/nft/mocks.js b/test/e2e/tests/nft/mocks.js index 7a94c76f76b5..e9909541d1db 100644 --- a/test/e2e/tests/nft/mocks.js +++ b/test/e2e/tests/nft/mocks.js @@ -1,279 +1,93 @@ function setupAutoDetectMocking(server) { - const assets = { - assets: [ + const nfts = { + nfts: [ { - id: 29383543, - token_id: + identifier: '86818186862637897590416402377730948900221574858925543698968316530334305793541', - num_sales: 0, - background_color: null, - image_url: 'https://metamask.github.io/test-dapp/metamask-fox.svg', // 'https://openseauserdata.com/files/ed6a6e7598980ee8ef8e5a08ea0304c9.svg', - image_preview_url: - 'https://metamask.github.io/test-dapp/metamask-fox.svg', // 'https://openseauserdata.com/files/ed6a6e7598980ee8ef8e5a08ea0304c9.svg', - image_thumbnail_url: - 'https://metamask.github.io/test-dapp/metamask-fox.svg', // 'https://openseauserdata.com/files/ed6a6e7598980ee8ef8e5a08ea0304c9.svg', - image_original_url: - 'https://metadata.ens.domains/mainnet/0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85/0xbff15a37063625e314d681fa9d4099080b40fcc7dc2bd4a338a0b5ecb24eb605/image', - animation_url: null, - animation_original_url: null, + collection: 'ens', + contract: '0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85', + token_standard: 'erc721', name: 'peteryinusa.eth', description: 'peteryinusa.eth, an ENS name.', - external_link: 'https://app.ens.domains/name/peteryinusa.eth', - asset_contract: { - address: '0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85', - asset_contract_type: 'non-fungible', - chain_identifier: 'ethereum', - created_date: '2019-05-08T21:59:29.327544', - name: 'Unidentified contract', - nft_version: null, - opensea_version: null, - owner: 111982386, - schema_name: 'ERC721', - symbol: '', - total_supply: '0', - description: - 'Ethereum Name Service (ENS) domains are secure domain names for the decentralized world. ENS domains provide a way for users to map human readable names to blockchain and non-blockchain resources, like Ethereum addresses, IPFS hashes, or website URLs. ENS domains can be bought and sold on secondary markets.', - external_link: 'https://ens.domains', - image_url: 'https://metamask.github.io/test-dapp/metamask-fox.svg', // 'https://i.seadn.io/gae/0cOqWoYA7xL9CkUjGlxsjreSYBdrUBE0c6EO1COG4XE8UeP-Z30ckqUNiL872zHQHQU5MUNMNhfDpyXIP17hRSC5HQ?w=500&auto=format', - default_to_fiat: false, - dev_buyer_fee_basis_points: 0, - dev_seller_fee_basis_points: 0, - only_proxied_transfers: false, - opensea_buyer_fee_basis_points: 0, - opensea_seller_fee_basis_points: 250, - buyer_fee_basis_points: 0, - seller_fee_basis_points: 250, - payout_address: null, - }, - permalink: - 'https://opensea.io/assets/ethereum/0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85/86818186862637897590416402377730948900221574858925543698968316530334305793541', - collection: { - banner_image_url: null, - chat_url: null, - created_date: '2019-05-08T21:59:36.282454+00:00', - default_to_fiat: false, - description: - 'Ethereum Name Service (ENS) domains are secure domain names for the decentralized world. ENS domains provide a way for users to map human readable names to blockchain and non-blockchain resources, like Ethereum addresses, IPFS hashes, or website URLs. ENS domains can be bought and sold on secondary markets.', - dev_buyer_fee_basis_points: '0', - dev_seller_fee_basis_points: '0', - discord_url: null, - display_data: { - card_display_style: 'cover', - }, - external_url: 'https://ens.domains', - featured: false, - featured_image_url: - 'https://i.seadn.io/gae/BBj09xD7R4bBtg1lgnAAS9_TfoYXKwMtudlk-0fVljlURaK7BWcARCpkM-1LGNGTAcsGO6V1TgrtmQFvCo8uVYW_QEfASK-9j6Nr?w=500&auto=format', - hidden: false, - safelist_request_status: 'verified', - image_url: 'https://metamask.github.io/test-dapp/metamask-fox.svg', // 'https://i.seadn.io/gae/0cOqWoYA7xL9CkUjGlxsjreSYBdrUBE0c6EO1COG4XE8UeP-Z30ckqUNiL872zHQHQU5MUNMNhfDpyXIP17hRSC5HQ?w=500&auto=format', - is_subject_to_whitelist: false, - large_image_url: - 'https://i.seadn.io/gae/BBj09xD7R4bBtg1lgnAAS9_TfoYXKwMtudlk-0fVljlURaK7BWcARCpkM-1LGNGTAcsGO6V1TgrtmQFvCo8uVYW_QEfASK-9j6Nr?w=500&auto=format', - medium_username: 'the-ethereum-name-service', - name: 'ENS: Ethereum Name Service', - only_proxied_transfers: false, - opensea_buyer_fee_basis_points: '0', - opensea_seller_fee_basis_points: 250, - payout_address: null, - require_email: false, - short_description: null, - slug: 'ens', - telegram_url: null, - twitter_username: 'ensdomains', - instagram_username: null, - wiki_url: null, - is_nsfw: false, - fees: { - seller_fees: {}, - opensea_fees: { - '0x0000a26b00c1f0df003000390027140000faa719': 250, - }, - }, - is_rarity_enabled: false, - is_creator_fees_enforced: false, - }, - decimals: null, - token_metadata: + image_url: 'https://metamask.github.io/test-dapp/metamask-fox.svg', + metadata_url: 'https://metadata.ens.domains/mainnet/0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85/86818186862637897590416402377730948900221574858925543698968316530334305793541', + opensea_url: + 'https://opensea.io/assets/ethereum/0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85/86818186862637897590416402377730948900221574858925543698968316530334305793541', + created_at: ' ', + updated_at: '2022-07-02T19:30:43.023572', + is_disabled: false, is_nsfw: false, - owner: null, - seaport_sell_orders: null, - creator: { - user: { - username: 'ENSDeployer', - }, - address: '0x4fe4e666be5752f1fdd210f4ab5de2cc26e3e0e8', - config: 'verified', - profile_img_url: '', - }, - traits: [ - { - trait_type: 'Length', - display_type: 'number', - max_value: null, - trait_count: 93526, - order: null, - value: 11, - }, - { - trait_type: 'Segment Length', - display_type: 'number', - max_value: null, - trait_count: 22322, - order: null, - value: 11, - }, - { - trait_type: 'Character Set', - display_type: null, - max_value: null, - trait_count: 233279, - order: null, - value: 'letter', - }, - { - trait_type: 'Created Date', - display_type: 'date', - max_value: null, - trait_count: 1, - order: null, - value: 1624394771.0, - }, - { - trait_type: 'Registration Date', - display_type: 'date', - max_value: null, - trait_count: 1, - order: null, - value: 1624394771.0, - }, - { - trait_type: 'Expiration Date', - display_type: 'date', - max_value: null, - trait_count: 1, - order: null, - value: 1687508675.0, - }, - ], - last_sale: null, - top_bid: null, - listing_date: null, - supports_wyvern: true, - rarity_data: null, - transfer_fee: null, - transfer_fee_payment_token: null, }, ], }; - const assetEmpty = { - assets: [], - }; - const assetContract = { - collection: { - banner_image_url: null, - chat_url: null, - created_date: '2019-05-08T21:59:36.282454+00:00', - default_to_fiat: false, - description: - 'Ethereum Name Service (ENS) domains are secure domain names for the decentralized world. ENS domains provide a way for users to map human readable names to blockchain and non-blockchain resources, like Ethereum addresses, IPFS hashes, or website URLs. ENS domains can be bought and sold on secondary markets.', - dev_buyer_fee_basis_points: '0', - dev_seller_fee_basis_points: '0', - discord_url: null, - display_data: { - card_display_style: 'cover', - }, - external_url: 'https://ens.domains', - featured: false, - featured_image_url: - 'https://i.seadn.io/gae/BBj09xD7R4bBtg1lgnAAS9_TfoYXKwMtudlk-0fVljlURaK7BWcARCpkM-1LGNGTAcsGO6V1TgrtmQFvCo8uVYW_QEfASK-9j6Nr?w=500&auto=format', - hidden: false, - safelist_request_status: 'verified', - image_url: 'https://metamask.github.io/test-dapp/metamask-fox.svg', // 'https://i.seadn.io/gae/0cOqWoYA7xL9CkUjGlxsjreSYBdrUBE0c6EO1COG4XE8UeP-Z30ckqUNiL872zHQHQU5MUNMNhfDpyXIP17hRSC5HQ?w=500&auto=format', - is_subject_to_whitelist: false, - large_image_url: - 'https://i.seadn.io/gae/BBj09xD7R4bBtg1lgnAAS9_TfoYXKwMtudlk-0fVljlURaK7BWcARCpkM-1LGNGTAcsGO6V1TgrtmQFvCo8uVYW_QEfASK-9j6Nr?w=500&auto=format', - medium_username: 'the-ethereum-name-service', - name: 'ENS: Ethereum Name Service', - only_proxied_transfers: false, - opensea_buyer_fee_basis_points: '0', - opensea_seller_fee_basis_points: 250, - payout_address: null, - require_email: false, - short_description: null, - slug: 'ens', - telegram_url: null, - twitter_username: 'ensdomains', - instagram_username: null, - wiki_url: null, - is_nsfw: false, - fees: { - seller_fees: {}, - opensea_fees: { - '0x0000a26b00c1f0df003000390027140000faa719': 250, - }, - }, - is_rarity_enabled: false, - is_creator_fees_enforced: false, - }, + + const nftContract = { address: '0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85', - asset_contract_type: 'non-fungible', - chain_identifier: 'ethereum', - created_date: '2019-05-08T21:59:29.327544', + chain: 'ethereum', + collection: 'ens', + contract_standard: 'erc721', name: 'Unidentified contract', - nft_version: null, - opensea_version: null, - owner: 111982386, - schema_name: 'ERC721', - symbol: '', - total_supply: '0', + supply: 0, + }; + + const nftCollection = { + collection: 'ens', + name: 'ENS: Ethereum Name Service', description: 'Ethereum Name Service (ENS) domains are secure domain names for the decentralized world. ENS domains provide a way for users to map human readable names to blockchain and non-blockchain resources, like Ethereum addresses, IPFS hashes, or website URLs. ENS domains can be bought and sold on secondary markets.', - external_link: 'https://ens.domains', - image_url: 'https://metamask.github.io/test-dapp/metamask-fox.svg', // 'https://i.seadn.io/gae/0cOqWoYA7xL9CkUjGlxsjreSYBdrUBE0c6EO1COG4XE8UeP-Z30ckqUNiL872zHQHQU5MUNMNhfDpyXIP17hRSC5HQ?w=500&auto=format', - default_to_fiat: false, - dev_buyer_fee_basis_points: 0, - dev_seller_fee_basis_points: 0, - only_proxied_transfers: false, - opensea_buyer_fee_basis_points: 0, - opensea_seller_fee_basis_points: 250, - buyer_fee_basis_points: 0, - seller_fee_basis_points: 250, - payout_address: null, + image_url: 'https://metamask.github.io/test-dapp/metamask-fox.svg', + banner_image_url: '', + owner: '0xfe89cc7abb2c4183683ab71653c4cdc9b02d44b7', + safelist_status: 'verified', + category: 'domain-names', + is_disabled: false, + is_nsfw: false, + trait_offers_enabled: false, + collection_offers_enabled: false, + opensea_url: 'https://opensea.io/collection/ens', + project_url: 'https://ens.domains', + wiki_url: '', + discord_url: '', + telegram_url: '', + twitter_username: 'ensdomains', + instagram_username: '', }; - // Get assets for owner + // Get assets for account server - .forGet('https://proxy.metafi.codefi.network/opensea/v1/api/v1/assets') - .withQuery({ offset: 0 }) + .forGet( + 'https://proxy.metafi.codefi.network/opensea/v1/api/v2/chain/ethereum/account/0x5cfe73b6021e818b776b421b1c4db2474086a7e1/nfts', + ) + .withQuery({ limit: 200, next: '' }) .thenCallback(() => { return { statusCode: 200, - json: assets, + json: nfts, }; }); - // Get assets for owner continued + // Get contract server - .forGet('https://proxy.metafi.codefi.network/opensea/v1/api/v1/assets') - .withQuery({ offset: 50 }) + .forGet( + 'https://proxy.metafi.codefi.network/opensea/v1/api/v2/chain/ethereum/contract/0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85', + ) .thenCallback(() => { return { statusCode: 200, - json: assetEmpty, + json: nftContract, }; }); - // Get asset contract details + // Get collection server .forGet( - 'https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset_contract/0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85', + 'https://proxy.metafi.codefi.network/opensea/v1/api/v2/collections/ens', ) .thenCallback(() => { return { statusCode: 200, - json: assetContract, + json: nftCollection, }; }); diff --git a/yarn.lock b/yarn.lock index 0e05f3bc78a4..7e51c079c1f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3835,9 +3835,9 @@ __metadata: languageName: node linkType: hard -"@metamask/assets-controllers@npm:^21.0.0": - version: 21.0.0 - resolution: "@metamask/assets-controllers@npm:21.0.0" +"@metamask/assets-controllers@npm:^22.0.0": + version: 22.0.0 + resolution: "@metamask/assets-controllers@npm:22.0.0" dependencies: "@ethersproject/address": "npm:^5.7.0" "@ethersproject/bignumber": "npm:^5.7.0" @@ -3847,7 +3847,7 @@ __metadata: "@metamask/approval-controller": "npm:^5.0.0" "@metamask/base-controller": "npm:^4.0.0" "@metamask/contract-metadata": "npm:^2.4.0" - "@metamask/controller-utils": "npm:^7.0.0" + "@metamask/controller-utils": "npm:^8.0.0" "@metamask/eth-query": "npm:^4.0.0" "@metamask/metamask-eth-abis": "npm:3.0.0" "@metamask/network-controller": "npm:^17.0.0" @@ -3867,7 +3867,7 @@ __metadata: "@metamask/approval-controller": ^5.0.0 "@metamask/network-controller": ^17.0.0 "@metamask/preferences-controller": ^5.0.0 - checksum: 6624b168465d6c4649577c005729a762a6e62524157b762c17426b84e4cc95bcaee05850c02bb2bb2afc930bd1976d5f106c46c6cbd08b40b35129092a084755 + checksum: 78ee0bb01b0bfb9ca876ea868583b47217b51f08c7839ce45f13236c70e175edc2a1243a3c930c8c24574dd266c267fe46c85a42b377d83239084528d3361713 languageName: node linkType: hard @@ -24353,7 +24353,7 @@ __metadata: "@metamask/address-book-controller": "npm:^3.0.0" "@metamask/announcement-controller": "npm:^4.0.0" "@metamask/approval-controller": "npm:^3.4.0" - "@metamask/assets-controllers": "npm:^21.0.0" + "@metamask/assets-controllers": "npm:^22.0.0" "@metamask/auto-changelog": "npm:^2.1.0" "@metamask/base-controller": "npm:^3.2.0" "@metamask/browser-passworder": "npm:^4.1.0"