Skip to content

Commit

Permalink
feat(platforms): refactor nft stamp to exclude erc1155 (#2006)
Browse files Browse the repository at this point in the history
* feat(platforms): refactor nft stamp to exclude erc1155

* chore(platforms): update description
  • Loading branch information
tim-schultz authored Dec 29, 2023
1 parent fc0eca1 commit 1d61861
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
3 changes: 2 additions & 1 deletion platforms/src/NFT/Providers-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
33 changes: 29 additions & 4 deletions platforms/src/NFT/Providers/__tests__/nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ beforeEach(() => {

const mockTokenAddress = "0x06012c8cf97bead5deae237070f9587f8e7a266d";
const mockTokenId = "100000";
const tokenType = "ERC721";

const mockContracts = [
{
address: mockTokenAddress,
tokenId: mockTokenId,
tokenType,
},
];

Expand Down Expand Up @@ -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",
},
});
Expand Down Expand Up @@ -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",
},
});
Expand All @@ -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.");
});
});
19 changes: 10 additions & 9 deletions platforms/src/NFT/Providers/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type GetContractsForOwnerResponse = {
contracts: {
address: string;
tokenId: string;
tokenType: string;
}[];
totalCount: number;
};
Expand Down Expand Up @@ -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.");
Expand All @@ -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",
},
})
Expand Down

0 comments on commit 1d61861

Please sign in to comment.