diff --git a/packages/core/__test__/profile_mainnet.test.ts b/packages/core/__test__/profile_mainnet.test.ts index 22da5e3..eec9728 100644 --- a/packages/core/__test__/profile_mainnet.test.ts +++ b/packages/core/__test__/profile_mainnet.test.ts @@ -46,7 +46,6 @@ describe("test starknetid.js sdk on mainnet", () => { profile.profilePicture && profile.profilePicture.startsWith("https://img.starkurabu.com"), ).toBeTruthy(); - const expectedProfile = { name: "fricoben.stark", twitter: "1255853529866145794", @@ -78,6 +77,27 @@ describe("test starknetid.js sdk on mainnet", () => { expect(profile).toStrictEqual(expectedProfile); }); + test("getProfileData with a everai pfp", async () => { + const starknetIdNavigator = new StarknetIdNavigator( + provider, + constants.StarknetChainId.SN_MAIN, + ); + expect(starknetIdNavigator).toBeInstanceOf(StarknetIdNavigator); + const profile = await starknetIdNavigator.getProfileData( + "0x007b275f7524f39b99a51c7134bc44204fedc5dd1e982e920eb2047c6c2a71f0", + ); + const expectedProfile = { + name: "rob.cacango.stark", + twitter: undefined, + github: undefined, + discord: undefined, + proofOfPersonhood: false, + profilePicture: + "https://gateway.pinata.cloud/ipfs/QmZS7maV678eJW7wJaVXJc28aKXzdZrwS1hmBmSy6bUVJh/1925.jpg", + }; + expect(profile).toStrictEqual(expectedProfile); + }); + test("getProfileData on an address with no identity", async () => { const starknetIdNavigator = new StarknetIdNavigator( provider, @@ -156,16 +176,21 @@ describe("test starknetid.js sdk on mainnet", () => { "0x06fb5e4e650bb6ceb80923c008e81122129092efc7e6d6f3f5c9ac4eead25355", // blobbert "0x061b6c0a78f9edf13cea17b50719f3344533fadd470b8cb29c2b4318014f52d3", // starkurabu "0x0097095403155fcbFA72AA53270D6eDd0DCC830bBb9264455517DF3e508633E5", // nothing + "0x007b275f7524f39b99a51c7134bc44204fedc5dd1e982e920eb2047c6c2a71f0", // everai pfp ]); + console.log("profiles", profiles); const expectedProfiles = [ { name: "iris.stark" }, { name: "rmz.stark" }, { name: "fricoben.stark" }, { name: undefined }, + { name: "rob.cacango.stark" }, ]; + profiles.forEach((profile, index) => { expect(profile.name).toEqual(expectedProfiles[index].name); }); + expect( profiles[0].profilePicture && profiles[0].profilePicture.startsWith( @@ -184,6 +209,12 @@ describe("test starknetid.js sdk on mainnet", () => { profiles[3].profilePicture && profiles[3].profilePicture.startsWith("https://starknet.id"), ).toBeTruthy(); + expect( + profiles[4].profilePicture && + profiles[4].profilePicture.startsWith( + "https://gateway.pinata.cloud/ipfs/", + ), + ).toBeTruthy(); }); }); }); diff --git a/packages/core/src/starknetIdNavigator/internal.ts b/packages/core/src/starknetIdNavigator/internal.ts index d0317d0..1a779dc 100644 --- a/packages/core/src/starknetIdNavigator/internal.ts +++ b/packages/core/src/starknetIdNavigator/internal.ts @@ -17,9 +17,15 @@ export const parseBase64Image = (metadata: string): string => { return JSON.parse(atob(metadata.split(",")[1].slice(0, -1))).image; }; +export const parseImageUrl = (url: string): string => { + return url.startsWith("ipfs://") + ? url.replace("ipfs://", "https://gateway.pinata.cloud/ipfs/") + : url; +}; + export const fetchImageUrl = async (url: string): Promise => { try { - const response = await fetch(url); + const response = await fetch(parseImageUrl(url)); if (!response.ok) { throw new Error("Network response was not ok"); @@ -29,7 +35,7 @@ export const fetchImageUrl = async (url: string): Promise => { // Check if the "image" key exists and is not null if (data.image) { - return data.image; + return parseImageUrl(data.image); } else { return "Image is not set"; }