Skip to content

Commit

Permalink
fix(platforms): use corrent alchemy url (passportxyz#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Schultz authored Apr 26, 2023
1 parent 98149fd commit 56abf2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions platforms/src/NFT/Providers/__tests__/nft.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
// ---- Test subject
import { alchemyGetNFTsUrl, NFTProvider } from "../nft";
import { getNFTEndpoint, NFTProvider } from "../nft";

import { RequestPayload } from "@gitcoin/passport-types";

Expand Down Expand Up @@ -45,7 +45,7 @@ describe("Attempt verification", function () {

// Check the request to get the NFTs
expect(axios.get).toHaveBeenCalledTimes(1);
expect(mockedAxios.get).toBeCalledWith(alchemyGetNFTsUrl, {
expect(mockedAxios.get).toBeCalledWith(getNFTEndpoint(), {
params: {
withMetadata: "false",
owner: MOCK_ADDRESS_LOWER,
Expand Down Expand Up @@ -81,4 +81,10 @@ describe("Attempt verification", function () {
expect(axios.get).toHaveBeenCalledTimes(1);
expect(nftPayload).toMatchObject({ valid: false });
});

it("should return the nft endpoint given an alchemy url", () => {
expect(getNFTEndpoint("https://eth-mainnet.alchemyapi.io/v2/123")).toBe(
"https://eth-mainnet.g.alchemy.com/nft/v2/123/getNFTs"
);
});
});
8 changes: 7 additions & 1 deletion platforms/src/NFT/Providers/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type NFTsResponse = {
totalCount: number;
};

export function getNFTEndpoint(rpcUrl?: string): string {
const nftAPIKey = rpcUrl ? rpcUrl.split("/").pop() : apiKey;

return `https://eth-mainnet.g.alchemy.com/nft/v2/${nftAPIKey}/getNFTs`;
}

// Export a NFT Provider
export class NFTProvider implements Provider {
// Give the provider a type so that we can select it with a payload
Expand All @@ -41,7 +47,7 @@ export class NFTProvider implements Provider {
totalCount: 0,
};

const providerUrl = alchemyGetNFTsUrl || payload.rpcUrl;
const providerUrl = getNFTEndpoint(payload.rpcUrl);

try {
const requestResponse = await axios.get(providerUrl, {
Expand Down

0 comments on commit 56abf2e

Please sign in to comment.