From f826cd46c6f605850b8b4f91186c6c487aafd8d7 Mon Sep 17 00:00:00 2001 From: jvaleskadevs Date: Sun, 26 Mar 2023 15:10:07 +0200 Subject: [PATCH 01/11] adding method: nft-with-attributes --- example/next-demo-app/config/config.ts | 11 ++++ .../next-demo-app/pages/privateattributes.js | 7 ++ example/react-demo-app/src/config/config.ts | 11 ++++ .../react-demo-app/src/privateattributes.js | 7 ++ src/components/config/config.tsx | 2 + src/components/nextWrapper/nextWrapper.tsx | 64 +++++++++++++++++++ src/components/reactWrapper/reactWrapper.tsx | 64 +++++++++++++++++++ .../universalWrapper/universalWrapper.tsx | 64 +++++++++++++++++++ 8 files changed, 230 insertions(+) create mode 100644 example/next-demo-app/pages/privateattributes.js create mode 100644 example/react-demo-app/src/privateattributes.js diff --git a/example/next-demo-app/config/config.ts b/example/next-demo-app/config/config.ts index 72d2cd2..3f2df6f 100644 --- a/example/next-demo-app/config/config.ts +++ b/example/next-demo-app/config/config.ts @@ -32,4 +32,15 @@ export const configData: configType = [ amount: 100000000, }, }, + { + path: "/privateattributes", + methodName: methods.NFTWithAttributes, + network: networks.Ethereum, + data: { + contractAddress: "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85", + attributes: [ + { value: "letter", trait_type: "Character Set" }, + ], + }, + }, ]; diff --git a/example/next-demo-app/pages/privateattributes.js b/example/next-demo-app/pages/privateattributes.js new file mode 100644 index 0000000..c364950 --- /dev/null +++ b/example/next-demo-app/pages/privateattributes.js @@ -0,0 +1,7 @@ +import React from "react"; + +const privateattributes = () => { + return
privateattributes
; +}; + +export default privateattributes; diff --git a/example/react-demo-app/src/config/config.ts b/example/react-demo-app/src/config/config.ts index 72d2cd2..3f2df6f 100644 --- a/example/react-demo-app/src/config/config.ts +++ b/example/react-demo-app/src/config/config.ts @@ -32,4 +32,15 @@ export const configData: configType = [ amount: 100000000, }, }, + { + path: "/privateattributes", + methodName: methods.NFTWithAttributes, + network: networks.Ethereum, + data: { + contractAddress: "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85", + attributes: [ + { value: "letter", trait_type: "Character Set" }, + ], + }, + }, ]; diff --git a/example/react-demo-app/src/privateattributes.js b/example/react-demo-app/src/privateattributes.js new file mode 100644 index 0000000..c364950 --- /dev/null +++ b/example/react-demo-app/src/privateattributes.js @@ -0,0 +1,7 @@ +import React from "react"; + +const privateattributes = () => { + return
privateattributes
; +}; + +export default privateattributes; diff --git a/src/components/config/config.tsx b/src/components/config/config.tsx index e49a2f1..fb169b9 100644 --- a/src/components/config/config.tsx +++ b/src/components/config/config.tsx @@ -10,6 +10,7 @@ export enum methods { "NFTCollection", "TOKEN", "TOKENwithAmount", + "NFTWithAttributes" } export type configDataType = { @@ -20,6 +21,7 @@ export type configDataType = { contractAddress: string; tokenId?: string; amount?: number; + attributes?: { value: string, trait_type: string } []; }; }; diff --git a/src/components/nextWrapper/nextWrapper.tsx b/src/components/nextWrapper/nextWrapper.tsx index e2127d5..f608c39 100644 --- a/src/components/nextWrapper/nextWrapper.tsx +++ b/src/components/nextWrapper/nextWrapper.tsx @@ -214,6 +214,53 @@ export const TokenGatingWrapper: React.FunctionComponent< } }; + // 4. Owns a particular attribute from a particular NFT collection + // The trait should match trait type and value. + const checkNFTAttributes = async ( + userAddress: string, + contractAddress: string, + attributes: { value: string, trait_type: string } [], + network: Network, + alchemyApiKey: string + ) => { + try { + const settings = { + apiKey: alchemyApiKey, // Replace with your Alchemy API Key. + network: network, // Replace with your network. + }; + + const alchemy = new Alchemy(settings); + + console.log("Checking for the attributes"); + + const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); + //console.log(response); + + for await (const nft of response) { + if (nft.contract.address === contractAddress) { + const nftAttributes = nft.rawMetadata?.attributes; + if (nftAttributes) { + for (let x = 0; x < nftAttributes.length; x++) { + for (let y = 0; y < attributes.length; y++) { + if ( + nftAttributes[x].trait_type === attributes[y].trait_type && + nftAttributes[x].value === attributes[y].value + ) { + setAuthorised(true); + return true; + } + } + } + } + } + } + setAuthorised(false); + return false; + } catch (error) { + console.log(error); + } + } + // check the URL and accordingly the condition // Open up a ConnectWallet section in case there is no address // Show a Loading icon when the details are loading @@ -305,6 +352,18 @@ export const TokenGatingWrapper: React.FunctionComponent< finalNetwork, alchemyApiKey ); + } else if (configData.methodName == methods.NFTWithAttributes) { + if (!configData.data.attributes) { + console.log("INCORRECT INPUT DATA"); + return; + } + response = await checkNFTAttributes( + address, + configData.data.contractAddress, + configData.data.attributes, + finalNetwork, + alchemyApiKey + ); } console.log(response); @@ -361,6 +420,11 @@ export const TokenGatingWrapper: React.FunctionComponent< 0, 8 )}`; + } else if (configData.methodName == methods.NFTWithAttributes) { + return `NFT from the Collection ${configData.data.contractAddress.slice( + 0, + 8 + )} with the attributes ${configData.data.attributes.map(attribute => JSON.stringify(attribute)).join(",")}`; } else { return `all the conditions fulfilled`; } diff --git a/src/components/reactWrapper/reactWrapper.tsx b/src/components/reactWrapper/reactWrapper.tsx index 65f6f24..974d8eb 100644 --- a/src/components/reactWrapper/reactWrapper.tsx +++ b/src/components/reactWrapper/reactWrapper.tsx @@ -215,6 +215,53 @@ export const TokenGatingWrapper: React.FunctionComponent< } }; + // 4. Owns a particular attribute from a particular NFT collection + // The trait should match trait type and value. + const checkNFTAttributes = async ( + userAddress: string, + contractAddress: string, + attributes: { value: string, trait_type: string } [], + network: Network, + alchemyApiKey: string + ) => { + try { + const settings = { + apiKey: alchemyApiKey, // Replace with your Alchemy API Key. + network: network, // Replace with your network. + }; + + const alchemy = new Alchemy(settings); + + console.log("Checking for the attributes"); + + const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); + //console.log(response); + + for await (const nft of response) { + if (nft.contract.address === contractAddress) { + const nftAttributes = nft.rawMetadata?.attributes; + if (nftAttributes) { + for (let x = 0; x < nftAttributes.length; x++) { + for (let y = 0; y < attributes.length; y++) { + if ( + nftAttributes[x].trait_type === attributes[y].trait_type && + nftAttributes[x].value === attributes[y].value + ) { + setAuthorised(true); + return true; + } + } + } + } + } + } + setAuthorised(false); + return false; + } catch (error) { + console.log(error); + } + } + // check the URL and accordingly the condition // Open up a ConnectWallet section in case there is no address // Show a Loading icon when the details are loading @@ -306,6 +353,18 @@ export const TokenGatingWrapper: React.FunctionComponent< finalNetwork, alchemyApiKey ); + } else if (configData.methodName == methods.NFTWithAttributes) { + if (!configData.data.attributes) { + console.log("INCORRECT INPUT DATA"); + return; + } + response = await checkNFTAttributes( + address, + configData.data.contractAddress, + configData.data.attributes, + finalNetwork, + alchemyApiKey + ); } console.log(response); @@ -362,6 +421,11 @@ export const TokenGatingWrapper: React.FunctionComponent< 0, 8 )}`; + } else if (configData.methodName == methods.NFTWithAttributes) { + return `NFT from the Collection ${configData.data.contractAddress.slice( + 0, + 8 + )} with the attributes ${configData.data.attributes.map(attribute => JSON.stringify(attribute)).join(",")}`; } else { return `all the conditions fulfilled`; } diff --git a/src/components/universalWrapper/universalWrapper.tsx b/src/components/universalWrapper/universalWrapper.tsx index fce8d40..d1ec3c5 100644 --- a/src/components/universalWrapper/universalWrapper.tsx +++ b/src/components/universalWrapper/universalWrapper.tsx @@ -210,6 +210,53 @@ export const TokenGatingWrapper: React.FunctionComponent< console.log(error); } }; + + // 4. Owns a particular attribute from a particular NFT collection + // The trait should match trait type and value. + const checkNFTAttributes = async ( + userAddress: string, + contractAddress: string, + attributes: { value: string, trait_type: string } [], + network: Network, + alchemyApiKey: string + ) => { + try { + const settings = { + apiKey: alchemyApiKey, // Replace with your Alchemy API Key. + network: network, // Replace with your network. + }; + + const alchemy = new Alchemy(settings); + + console.log("Checking for the attributes"); + + const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); + //console.log(response); + + for await (const nft of response) { + if (nft.contract.address === contractAddress) { + const nftAttributes = nft.rawMetadata?.attributes; + if (nftAttributes) { + for (let x = 0; x < nftAttributes.length; x++) { + for (let y = 0; y < attributes.length; y++) { + if ( + nftAttributes[x].trait_type === attributes[y].trait_type && + nftAttributes[x].value === attributes[y].value + ) { + setAuthorised(true); + return true; + } + } + } + } + } + } + setAuthorised(false); + return false; + } catch (error) { + console.log(error); + } + } // check the URL and accordingly the condition // Open up a ConnectWallet section in case there is no address @@ -302,6 +349,18 @@ export const TokenGatingWrapper: React.FunctionComponent< finalNetwork, alchemyApiKey ); + } else if (configData.methodName == methods.NFTWithAttributes) { + if (!configData.data.attributes) { + console.log("INCORRECT INPUT DATA"); + return; + } + response = await checkNFTAttributes( + address, + configData.data.contractAddress, + configData.data.attributes, + finalNetwork, + alchemyApiKey + ); } console.log(response); @@ -358,6 +417,11 @@ export const TokenGatingWrapper: React.FunctionComponent< 0, 8 )}`; + } else if (configData.methodName == methods.NFTWithAttributes) { + return `NFT from the Collection ${configData.data.contractAddress.slice( + 0, + 8 + )} with the attributes ${configData.data.attributes.map(attribute => JSON.stringify(attribute)).join(",")}`; } else { return `all the conditions fulfilled`; } From 3ac2acae383b13e1e9889832fc505bc11e97e4b2 Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:28:21 +0200 Subject: [PATCH 02/11] fix indentation --- src/components/nextWrapper/nextWrapper.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/nextWrapper/nextWrapper.tsx b/src/components/nextWrapper/nextWrapper.tsx index f608c39..a40da94 100644 --- a/src/components/nextWrapper/nextWrapper.tsx +++ b/src/components/nextWrapper/nextWrapper.tsx @@ -217,9 +217,9 @@ export const TokenGatingWrapper: React.FunctionComponent< // 4. Owns a particular attribute from a particular NFT collection // The trait should match trait type and value. const checkNFTAttributes = async ( - userAddress: string, - contractAddress: string, - attributes: { value: string, trait_type: string } [], + userAddress: string, + contractAddress: string, + attributes: { value: string, trait_type: string } [], network: Network, alchemyApiKey: string ) => { From 19e1d36ebb20ad789d011f3890f1c6919091733f Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:29:09 +0200 Subject: [PATCH 03/11] fix indentation --- src/components/reactWrapper/reactWrapper.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/reactWrapper/reactWrapper.tsx b/src/components/reactWrapper/reactWrapper.tsx index 974d8eb..e1460f7 100644 --- a/src/components/reactWrapper/reactWrapper.tsx +++ b/src/components/reactWrapper/reactWrapper.tsx @@ -218,9 +218,9 @@ export const TokenGatingWrapper: React.FunctionComponent< // 4. Owns a particular attribute from a particular NFT collection // The trait should match trait type and value. const checkNFTAttributes = async ( - userAddress: string, - contractAddress: string, - attributes: { value: string, trait_type: string } [], + userAddress: string, + contractAddress: string, + attributes: { value: string, trait_type: string } [], network: Network, alchemyApiKey: string ) => { From 71597f7825f9b6225f4eee3350176f5c430d5411 Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:31:29 +0200 Subject: [PATCH 04/11] fix indentation --- src/components/universalWrapper/universalWrapper.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/universalWrapper/universalWrapper.tsx b/src/components/universalWrapper/universalWrapper.tsx index d1ec3c5..66b73de 100644 --- a/src/components/universalWrapper/universalWrapper.tsx +++ b/src/components/universalWrapper/universalWrapper.tsx @@ -214,9 +214,9 @@ export const TokenGatingWrapper: React.FunctionComponent< // 4. Owns a particular attribute from a particular NFT collection // The trait should match trait type and value. const checkNFTAttributes = async ( - userAddress: string, - contractAddress: string, - attributes: { value: string, trait_type: string } [], + userAddress: string, + contractAddress: string, + attributes: { value: string, trait_type: string } [], network: Network, alchemyApiKey: string ) => { @@ -256,7 +256,7 @@ export const TokenGatingWrapper: React.FunctionComponent< } catch (error) { console.log(error); } - } + }; // check the URL and accordingly the condition // Open up a ConnectWallet section in case there is no address From 5a3f7a24ab65deaa7850e663973f8eb3465d5974 Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:39:32 +0200 Subject: [PATCH 05/11] Adding nft-with-attributes details --- README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96a73f8..dfcffb4 100644 --- a/README.md +++ b/README.md @@ -167,13 +167,14 @@ configDataType = { contractAddress: string; // contractAddress of Token or NFT tokenId?: string; // Token Id of the NFT (if req.) amount?: number; // Amount of tokens (if req.) + attributes?: { value: string, trait_type: string }; // Array of NFT Attributes (if req.) }; }[] ``` ### Methods -There are currently 4 methods available , as follows : +There are currently 5 methods available , as follows : - `NFTWithTokenID` for NFT with a Specific Token ID from a collection, E.g. BAYC No. 8378 @@ -237,6 +238,22 @@ Need to add contractAddress and amount of the token }, ``` +- `NFTWithAttributes` for NFT with a Specific Atrtibute (trait type and value) from a collection, E.g. BAYC. Fur -> Pink. + +Need to add contractAddress and an array of attributes of the NFT + +```javascript +{ + path: "/page", + methodName: methods.NFTWithTokenID, + network: networks.Ethereum, + data: { + contractAddress: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D", + attributes: [ { value: "Pink", trait_type: "Fur" } ] + }, + }, +``` + These can be accessed by importing methods ```javascript @@ -245,6 +262,7 @@ export enum methods { "NFTCollection", "TOKEN", "TOKENwithAmount", + "NFTWithAttributes" } ``` @@ -270,7 +288,7 @@ export enum networks { ## Example -Here is an example config File , for all the 4 types of Methods. Refer the same for more info - +Here is an example config File , for all the 5 types of Methods. Refer the same for more info - ```javascript import { configType, methods, networks } from "token-gating-sdk"; @@ -307,6 +325,17 @@ export const configData: configType = [ amount: 100000000, }, }, + { + path: "/privateattributes", + methodName: methods.NFTWithAttributes, + network: networks.Ethereum, + data: { + contractAddress: "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85", + attributes: [ + { value: "letter", trait_type: "Character Set" }, + ], + }, + }, ]; ``` From 5c0b0e96af24c88eb911b8f4a11ab48be298200f Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:40:56 +0200 Subject: [PATCH 06/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dfcffb4..91476fa 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ Need to add contractAddress and amount of the token }, ``` -- `NFTWithAttributes` for NFT with a Specific Atrtibute (trait type and value) from a collection, E.g. BAYC. Fur -> Pink. +- `NFTWithAttributes` for NFT with an Specific Attribute (trait type and value) from a collection, E.g. BAYC. Fur -> Pink. Need to add contractAddress and an array of attributes of the NFT From b00d6775872a631ef6bc851922ea5d669c2e686b Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:43:20 +0200 Subject: [PATCH 07/11] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 91476fa..50925f6 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ type configDataType = { contractAddress: string, tokenId?: string, amount?: number, + attributes?: { value: string, trait_type: string } [], }, }[]; ``` @@ -167,7 +168,7 @@ configDataType = { contractAddress: string; // contractAddress of Token or NFT tokenId?: string; // Token Id of the NFT (if req.) amount?: number; // Amount of tokens (if req.) - attributes?: { value: string, trait_type: string }; // Array of NFT Attributes (if req.) + attributes?: { value: string, trait_type: string } []; // Array of NFT Attributes (if req.) }; }[] ``` From 7e97854d652ca867c3b4cf462f087ea1eb896e74 Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:51:35 +0200 Subject: [PATCH 08/11] fixing indentation --- src/components/nextWrapper/nextWrapper.tsx | 62 +++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/components/nextWrapper/nextWrapper.tsx b/src/components/nextWrapper/nextWrapper.tsx index a40da94..d2a403c 100644 --- a/src/components/nextWrapper/nextWrapper.tsx +++ b/src/components/nextWrapper/nextWrapper.tsx @@ -222,43 +222,43 @@ export const TokenGatingWrapper: React.FunctionComponent< attributes: { value: string, trait_type: string } [], network: Network, alchemyApiKey: string - ) => { + ) => { try { - const settings = { - apiKey: alchemyApiKey, // Replace with your Alchemy API Key. + const settings = { + apiKey: alchemyApiKey, // Replace with your Alchemy API Key. network: network, // Replace with your network. - }; + }; - const alchemy = new Alchemy(settings); + const alchemy = new Alchemy(settings); - console.log("Checking for the attributes"); + console.log("Checking for the attributes"); - const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); - //console.log(response); + const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); + //console.log(response); - for await (const nft of response) { - if (nft.contract.address === contractAddress) { - const nftAttributes = nft.rawMetadata?.attributes; - if (nftAttributes) { - for (let x = 0; x < nftAttributes.length; x++) { - for (let y = 0; y < attributes.length; y++) { - if ( - nftAttributes[x].trait_type === attributes[y].trait_type && - nftAttributes[x].value === attributes[y].value - ) { - setAuthorised(true); - return true; - } - } - } - } - } - } - setAuthorised(false); - return false; - } catch (error) { - console.log(error); - } + for await (const nft of response) { + if (nft.contract.address === contractAddress) { + const nftAttributes = nft.rawMetadata?.attributes; + if (nftAttributes) { + for (let x = 0; x < nftAttributes.length; x++) { + for (let y = 0; y < attributes.length; y++) { + if ( + nftAttributes[x].trait_type === attributes[y].trait_type && + nftAttributes[x].value === attributes[y].value + ) { + setAuthorised(true); + return true; + } + } + } + } + } + } + setAuthorised(false); + return false; + } catch (error) { + console.log(error); + } } // check the URL and accordingly the condition From cbed468cedfea4b4e40bf18748ded04ce8388c18 Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:54:33 +0200 Subject: [PATCH 09/11] Update nextWrapper.tsx --- src/components/nextWrapper/nextWrapper.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/nextWrapper/nextWrapper.tsx b/src/components/nextWrapper/nextWrapper.tsx index d2a403c..23ebc12 100644 --- a/src/components/nextWrapper/nextWrapper.tsx +++ b/src/components/nextWrapper/nextWrapper.tsx @@ -223,14 +223,14 @@ export const TokenGatingWrapper: React.FunctionComponent< network: Network, alchemyApiKey: string ) => { - try { - const settings = { - apiKey: alchemyApiKey, // Replace with your Alchemy API Key. - network: network, // Replace with your network. + try { + const settings = { + apiKey: alchemyApiKey, // Replace with your Alchemy API Key. + network: network, // Replace with your network. }; - const alchemy = new Alchemy(settings); - + const alchemy = new Alchemy(settings); + console.log("Checking for the attributes"); const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); From cc683e97a05758aaf50d6cb4b3b0961fa9e29872 Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:55:47 +0200 Subject: [PATCH 10/11] Update reactWrapper.tsx --- src/components/reactWrapper/reactWrapper.tsx | 68 ++++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/components/reactWrapper/reactWrapper.tsx b/src/components/reactWrapper/reactWrapper.tsx index e1460f7..4af9dc3 100644 --- a/src/components/reactWrapper/reactWrapper.tsx +++ b/src/components/reactWrapper/reactWrapper.tsx @@ -223,43 +223,43 @@ export const TokenGatingWrapper: React.FunctionComponent< attributes: { value: string, trait_type: string } [], network: Network, alchemyApiKey: string - ) => { - try { - const settings = { - apiKey: alchemyApiKey, // Replace with your Alchemy API Key. - network: network, // Replace with your network. - }; - - const alchemy = new Alchemy(settings); + ) => { + try { + const settings = { + apiKey: alchemyApiKey, // Replace with your Alchemy API Key. + network: network, // Replace with your network. + }; - console.log("Checking for the attributes"); + const alchemy = new Alchemy(settings); + + console.log("Checking for the attributes"); - const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); - //console.log(response); + const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); + //console.log(response); - for await (const nft of response) { - if (nft.contract.address === contractAddress) { - const nftAttributes = nft.rawMetadata?.attributes; - if (nftAttributes) { - for (let x = 0; x < nftAttributes.length; x++) { - for (let y = 0; y < attributes.length; y++) { - if ( - nftAttributes[x].trait_type === attributes[y].trait_type && - nftAttributes[x].value === attributes[y].value - ) { - setAuthorised(true); - return true; - } - } - } - } - } - } - setAuthorised(false); - return false; - } catch (error) { - console.log(error); - } + for await (const nft of response) { + if (nft.contract.address === contractAddress) { + const nftAttributes = nft.rawMetadata?.attributes; + if (nftAttributes) { + for (let x = 0; x < nftAttributes.length; x++) { + for (let y = 0; y < attributes.length; y++) { + if ( + nftAttributes[x].trait_type === attributes[y].trait_type && + nftAttributes[x].value === attributes[y].value + ) { + setAuthorised(true); + return true; + } + } + } + } + } + } + setAuthorised(false); + return false; + } catch (error) { + console.log(error); + } } // check the URL and accordingly the condition From ed5762ba17d8828dec626051df8e4e99892b29bb Mon Sep 17 00:00:00 2001 From: jvaleskadevs <85419347+jvaleskadevs@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:56:13 +0200 Subject: [PATCH 11/11] Update universalWrapper.tsx --- .../universalWrapper/universalWrapper.tsx | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/components/universalWrapper/universalWrapper.tsx b/src/components/universalWrapper/universalWrapper.tsx index 66b73de..546e723 100644 --- a/src/components/universalWrapper/universalWrapper.tsx +++ b/src/components/universalWrapper/universalWrapper.tsx @@ -219,44 +219,44 @@ export const TokenGatingWrapper: React.FunctionComponent< attributes: { value: string, trait_type: string } [], network: Network, alchemyApiKey: string - ) => { - try { - const settings = { - apiKey: alchemyApiKey, // Replace with your Alchemy API Key. - network: network, // Replace with your network. - }; - - const alchemy = new Alchemy(settings); + ) => { + try { + const settings = { + apiKey: alchemyApiKey, // Replace with your Alchemy API Key. + network: network, // Replace with your network. + }; - console.log("Checking for the attributes"); + const alchemy = new Alchemy(settings); + + console.log("Checking for the attributes"); - const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); - //console.log(response); + const response = await alchemy.nft.getNftsForOwnerIterator(userAddress); + //console.log(response); - for await (const nft of response) { - if (nft.contract.address === contractAddress) { - const nftAttributes = nft.rawMetadata?.attributes; - if (nftAttributes) { - for (let x = 0; x < nftAttributes.length; x++) { - for (let y = 0; y < attributes.length; y++) { - if ( - nftAttributes[x].trait_type === attributes[y].trait_type && - nftAttributes[x].value === attributes[y].value - ) { - setAuthorised(true); - return true; - } - } - } - } - } - } - setAuthorised(false); - return false; - } catch (error) { - console.log(error); - } - }; + for await (const nft of response) { + if (nft.contract.address === contractAddress) { + const nftAttributes = nft.rawMetadata?.attributes; + if (nftAttributes) { + for (let x = 0; x < nftAttributes.length; x++) { + for (let y = 0; y < attributes.length; y++) { + if ( + nftAttributes[x].trait_type === attributes[y].trait_type && + nftAttributes[x].value === attributes[y].value + ) { + setAuthorised(true); + return true; + } + } + } + } + } + } + setAuthorised(false); + return false; + } catch (error) { + console.log(error); + } + } // check the URL and accordingly the condition // Open up a ConnectWallet section in case there is no address