Skip to content

Commit

Permalink
fix: add patch
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri committed Jun 27, 2024
1 parent e551de3 commit 588985c
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 3 deletions.
149 changes: 149 additions & 0 deletions .yarn/patches/@metamask-assets-controllers-npm-33.0.0-3e7448c4cd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
diff --git a/dist/chunk-354SINOH.js b/dist/chunk-354SINOH.js
index 7f87776370b755bf04765b8a0ae0145bf3a0b5e6..3882dc6679b4479489e01162ccb17af13dbf8a9a 100644
--- a/dist/chunk-354SINOH.js
+++ b/dist/chunk-354SINOH.js
@@ -2,14 +2,13 @@



-
var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');

// src/NftDetectionController.ts
var _basecontroller = require('@metamask/base-controller');


-
+var _chunkNYVA7ZTQjs = require('./chunk-NYVA7ZTQ.js');



@@ -25,6 +24,7 @@ var BlockaidResultType = /* @__PURE__ */ ((BlockaidResultType2) => {
BlockaidResultType2["Malicious"] = "Malicious";
return BlockaidResultType2;
})(BlockaidResultType || {});
+var MAX_GET_COLLECTION_BATCH_SIZE = 20;
var _disabled, _addNft, _getNftState, _inProcessNftFetchingUpdates, _onPreferencesControllerStateChange, onPreferencesControllerStateChange_fn, _getOwnerNftApi, getOwnerNftApi_fn, _getOwnerNfts, getOwnerNfts_fn;
var NftDetectionController = class extends _basecontroller.BaseController {
/**
@@ -134,6 +134,56 @@ var NftDetectionController = class extends _basecontroller.BaseController {
apiNfts = resultNftApi.tokens.filter(
(elm) => elm.token.isSpam === false && (elm.blockaidResult?.result_type ? elm.blockaidResult?.result_type === "Benign" /* Benign */ : true)
);
+ const collections = apiNfts.reduce((acc, currValue) => {
+ if (!acc.includes(currValue.token.contract)) {
+ acc.push(currValue.token.contract);
+ }
+ return acc;
+ }, []);
+ const collectionResponse = await _chunkNYVA7ZTQjs.reduceInBatchesSerially.call(void 0, {
+ values: collections,
+ batchSize: MAX_GET_COLLECTION_BATCH_SIZE,
+ eachBatch: async (allResponses, batch) => {
+ const params = new URLSearchParams(
+ batch.map((s) => ["contract", s])
+ );
+ params.append("chainId", "1");
+ const collectionResponseForBatch = await _controllerutils.fetchWithErrorHandling.call(void 0, {
+ url: `${_controllerutils.NFT_API_BASE_URL}/collections?${params.toString()}`,
+ options: {
+ headers: {
+ Version: '1'
+ }
+ },
+ timeout: _controllerutils.NFT_API_TIMEOUT
+ });
+ return {
+ ...allResponses,
+ ...collectionResponseForBatch
+ };
+ },
+ initialResult: {}
+ });
+ if (collectionResponse.collections?.length) {
+ apiNfts.forEach((singleNFT) => {
+ const found = collectionResponse.collections.find(
+ (elm) => elm.id?.toLowerCase() === singleNFT.token.contract.toLowerCase()
+ );
+ if (found) {
+ singleNFT.token = {
+ ...singleNFT.token,
+ collection: {
+ ...singleNFT.token.collection ? singleNFT.token.collection : {},
+ creator: found?.creator,
+ openseaVerificationStatus: found?.openseaVerificationStatus,
+ contractDeployedAt: found.contractDeployedAt,
+ ownerCount: found.ownerCount,
+ topBid: found.topBid
+ }
+ };
+ }
+ });
+ }
const addNftPromises = apiNfts.map(async (nft) => {
const {
tokenId,
diff --git a/dist/chunk-7JWDWDXT.js b/dist/chunk-7JWDWDXT.js
index af5d78416658763da52305f9e08b286733310898..a82d8f01f004ed876edf1f34fcb1de5f05cbbcef 100644
--- a/dist/chunk-7JWDWDXT.js
+++ b/dist/chunk-7JWDWDXT.js
@@ -873,14 +873,33 @@ getNftInformationFromApi_fn = async function(contractAddress, tokenId) {
includeAttributes: "true",
includeLastSale: "true"
}).toString();
- const nftInformation = await _controllerutils.fetchWithErrorHandling.call(void 0, {
- url: `${this.getNftApi()}?${urlParams}`,
- options: {
- headers: {
- Version: "1"
- }
- }
- });
+ const getCollectionParams = new URLSearchParams({
+ chainIds: "1",
+ contract: `${contractAddress}`
+ }).toString();
+ const [nftInformation, collectionInformation] = await Promise.all([
+ _controllerutils.safelyExecute.call(void 0,
+ () => _controllerutils.fetchWithErrorHandling.call(void 0, {
+ url: `${this.getNftApi()}?${urlParams}`,
+ options: {
+ headers: {
+ Version: "1"
+ }
+ }
+ })
+ ),
+ _controllerutils.safelyExecute.call(void 0,
+ () => _controllerutils.fetchWithErrorHandling.call(void 0, {
+ url: `${_controllerutils.NFT_API_BASE_URL}/collections?${getCollectionParams}`,
+ options: {
+ headers: {
+ Version: "1"
+ }
+ }
+ })
+ )
+ ]);
+
if (!nftInformation?.tokens?.[0]?.token) {
return {
name: null,
@@ -918,7 +937,16 @@ getNftInformationFromApi_fn = async function(contractAddress, tokenId) {
},
rarityRank && { rarityRank },
rarity && { rarity },
- collection && { collection }
+ (collection || collectionInformation) && {
+ collection: {
+ ...collection || {},
+ creator: collection?.creator || collectionInformation?.collections[0].creator,
+ openseaVerificationStatus: collectionInformation?.collections[0].openseaVerificationStatus,
+ contractDeployedAt: collectionInformation?.collections[0].contractDeployedAt,
+ ownerCount: collectionInformation?.collections[0].ownerCount,
+ topBid: collectionInformation?.collections[0].topBid
+ }
+ }
);
return nftMetadata;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
"@metamask/address-book-controller": "^4.0.1",
"@metamask/announcement-controller": "^6.1.0",
"@metamask/approval-controller": "^7.0.0",
"@metamask/assets-controllers": "^33.0.0",
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A33.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-33.0.0-3e7448c4cd.patch",
"@metamask/base-controller": "^5.0.1",
"@metamask/browser-passworder": "^4.3.0",
"@metamask/contract-metadata": "^2.5.0",
Expand Down
46 changes: 44 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4824,7 +4824,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/assets-controllers@npm:^33.0.0":
"@metamask/assets-controllers@npm:33.0.0":
version: 33.0.0
resolution: "@metamask/assets-controllers@npm:33.0.0"
dependencies:
Expand Down Expand Up @@ -4866,6 +4866,48 @@ __metadata:
languageName: node
linkType: hard

"@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A33.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-33.0.0-3e7448c4cd.patch":
version: 33.0.0
resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A33.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-33.0.0-3e7448c4cd.patch::version=33.0.0&hash=58fb82"
dependencies:
"@ethereumjs/util": "npm:^8.1.0"
"@ethersproject/address": "npm:^5.7.0"
"@ethersproject/bignumber": "npm:^5.7.0"
"@ethersproject/contracts": "npm:^5.7.0"
"@ethersproject/providers": "npm:^5.7.0"
"@metamask/abi-utils": "npm:^2.0.2"
"@metamask/accounts-controller": "npm:^17.0.0"
"@metamask/approval-controller": "npm:^7.0.0"
"@metamask/base-controller": "npm:^6.0.0"
"@metamask/contract-metadata": "npm:^2.4.0"
"@metamask/controller-utils": "npm:^11.0.0"
"@metamask/eth-query": "npm:^4.0.0"
"@metamask/keyring-controller": "npm:^17.1.0"
"@metamask/metamask-eth-abis": "npm:^3.1.1"
"@metamask/network-controller": "npm:^19.0.0"
"@metamask/polling-controller": "npm:^8.0.0"
"@metamask/preferences-controller": "npm:^13.0.0"
"@metamask/rpc-errors": "npm:^6.2.1"
"@metamask/utils": "npm:^8.3.0"
"@types/bn.js": "npm:^5.1.5"
"@types/uuid": "npm:^8.3.0"
async-mutex: "npm:^0.5.0"
bn.js: "npm:^5.2.1"
cockatiel: "npm:^3.1.2"
lodash: "npm:^4.17.21"
multiformats: "npm:^9.5.2"
single-call-balance-checker-abi: "npm:^1.0.0"
uuid: "npm:^8.3.2"
peerDependencies:
"@metamask/accounts-controller": ^17.0.0
"@metamask/approval-controller": ^7.0.0
"@metamask/keyring-controller": ^17.0.0
"@metamask/network-controller": ^19.0.0
"@metamask/preferences-controller": ^13.0.0
checksum: 10/c0f86025ff564274946ce616f615cee5ba77771df4d88dddb02f18a538462b5bae8ef0fb224a034565195dde691d2e6870a68aef9fb24eb36bc7fa835952675e
languageName: node
linkType: hard

"@metamask/auto-changelog@npm:^2.1.0":
version: 2.6.1
resolution: "@metamask/auto-changelog@npm:2.6.1"
Expand Down Expand Up @@ -25337,7 +25379,7 @@ __metadata:
"@metamask/announcement-controller": "npm:^6.1.0"
"@metamask/api-specs": "npm:^0.9.3"
"@metamask/approval-controller": "npm:^7.0.0"
"@metamask/assets-controllers": "npm:^33.0.0"
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A33.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-33.0.0-3e7448c4cd.patch"
"@metamask/auto-changelog": "npm:^2.1.0"
"@metamask/base-controller": "npm:^5.0.1"
"@metamask/browser-passworder": "npm:^4.3.0"
Expand Down

0 comments on commit 588985c

Please sign in to comment.