Skip to content

Commit

Permalink
fix: merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed May 1, 2024
2 parents 5c9f2d2 + 991588e commit 70f20f3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
33 changes: 32 additions & 1 deletion packages/core/__test__/profile_mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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();
});
});
});
10 changes: 8 additions & 2 deletions packages/core/src/starknetIdNavigator/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
try {
const response = await fetch(url);
const response = await fetch(parseImageUrl(url));

if (!response.ok) {
throw new Error("Network response was not ok");
Expand All @@ -29,7 +35,7 @@ export const fetchImageUrl = async (url: string): Promise<string> => {

// 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";
}
Expand Down

0 comments on commit 70f20f3

Please sign in to comment.