From 1d618616f4028c7ec53673449f0c3a1a4b954303 Mon Sep 17 00:00:00 2001 From: Tim <6887938+digitalmnt@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:03:46 -0700 Subject: [PATCH] feat(platforms): refactor nft stamp to exclude erc1155 (#2006) * feat(platforms): refactor nft stamp to exclude erc1155 * chore(platforms): update description --- platforms/src/NFT/Providers-config.ts | 3 +- .../src/NFT/Providers/__tests__/nft.test.ts | 33 ++++++++++++++++--- platforms/src/NFT/Providers/nft.ts | 19 ++++++----- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/platforms/src/NFT/Providers-config.ts b/platforms/src/NFT/Providers-config.ts index 437480a3f2..2c8d565078 100644 --- a/platforms/src/NFT/Providers-config.ts +++ b/platforms/src/NFT/Providers-config.ts @@ -5,7 +5,8 @@ export const PlatformDetails: PlatformSpec = { icon: "./assets/nftStampIcon.svg", platform: "NFT", name: "NFT Holder", - description: "Connect your Ethereum wallet to verify that you own an Ethereum-based NFT.", + description: + "Connect your Ethereum wallet to verify that you own an Ethereum-based NFT. Currently, we only recognize NFTs (ERC-721s).", connectMessage: "Connect NFT", isEVM: true, website: "https://ethereum.org/en/nft/", diff --git a/platforms/src/NFT/Providers/__tests__/nft.test.ts b/platforms/src/NFT/Providers/__tests__/nft.test.ts index aaa15ea152..c19e8275c6 100644 --- a/platforms/src/NFT/Providers/__tests__/nft.test.ts +++ b/platforms/src/NFT/Providers/__tests__/nft.test.ts @@ -20,11 +20,13 @@ beforeEach(() => { const mockTokenAddress = "0x06012c8cf97bead5deae237070f9587f8e7a266d"; const mockTokenId = "100000"; +const tokenType = "ERC721"; const mockContracts = [ { address: mockTokenAddress, tokenId: mockTokenId, + tokenType, }, ]; @@ -52,9 +54,8 @@ describe("Attempt verification", function () { expect(axios.get).toHaveBeenCalledTimes(1); expect(mockedAxios.get).toBeCalledWith(getNFTEndpoint(), { params: { - withMetadata: "false", + withMetadata: "true", owner: MOCK_ADDRESS_LOWER, - pageSize: 1, orderBy: "transferTime", }, }); @@ -109,9 +110,8 @@ describe("Attempt verification", function () { expect(axios.get).toHaveBeenCalledTimes(1); expect(mockedAxios.get).toBeCalledWith(getNFTEndpoint(), { params: { - withMetadata: "false", + withMetadata: "true", owner: MOCK_ADDRESS_LOWER, - pageSize: 1, orderBy: "transferTime", }, }); @@ -125,4 +125,29 @@ describe("Attempt verification", function () { }); } ); + it("should not validate an ERC1155 token", async () => { + (axios.get as jest.Mock).mockImplementation((url) => { + return Promise.resolve({ + status: 200, + data: { + totalCount: 1, + contracts: [ + { + ...mockContracts[0], + tokenType: "ERC1155", + }, + ], + }, + }); + }); + + const nftProvider = new NFTProvider(); + + await expect( + async () => + await nftProvider.verify({ + address: MOCK_ADDRESS, + } as unknown as RequestPayload) + ).rejects.toThrowError("Unable to find an ERC721 token that you own."); + }); }); diff --git a/platforms/src/NFT/Providers/nft.ts b/platforms/src/NFT/Providers/nft.ts index 0f73bad632..188c29132b 100644 --- a/platforms/src/NFT/Providers/nft.ts +++ b/platforms/src/NFT/Providers/nft.ts @@ -18,6 +18,7 @@ type GetContractsForOwnerResponse = { contracts: { address: string; tokenId: string; + tokenType: string; }[]; totalCount: number; }; @@ -48,20 +49,21 @@ export class NFTProvider implements Provider { let valid = false, record = undefined; - const { totalCount, contracts } = await this.queryNFTs(address); + const data = await this.queryNFTs(address); + + const { contracts, totalCount } = data; if (totalCount > 0) { - const tokenAddress = contracts?.[0]?.address; - const tokenId = contracts?.[0]?.tokenId; + const erc721 = contracts.find((contract) => contract.tokenType === "ERC721"); - if (tokenAddress && tokenId) { + if (erc721) { valid = true; record = { - tokenAddress, - tokenId, + tokenAddress: erc721.address, + tokenId: erc721.tokenId, }; } else { - throw new ProviderExternalVerificationError("Unable to find token info in response from NFT provider."); + throw new ProviderExternalVerificationError("Unable to find an ERC721 token that you own."); } } else { errors.push("You do not own any NFTs."); @@ -80,9 +82,8 @@ export class NFTProvider implements Provider { return ( await axios.get(providerUrl, { params: { - withMetadata: "false", + withMetadata: "true", owner: address, - pageSize: 1, orderBy: "transferTime", }, })