-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: images not showing properly (#179)
* image fallback * fixed lounge * refactor: extracted starknet nft api calls to its own helper * refactor: endpoints * fixed ark project logo link not working when both wallets connected
- Loading branch information
Showing
16 changed files
with
238 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type Media } from "alchemy-sdk"; | ||
|
||
import { type NftMedia } from "../types"; | ||
|
||
export function getMediaObjectFromAlchemyMedia( | ||
alchemyMedia: Media | undefined | ||
): NftMedia { | ||
if (alchemyMedia === undefined) { | ||
return { format: "image", src: undefined }; | ||
} | ||
const mediaSrc = | ||
alchemyMedia?.gateway ?? alchemyMedia?.thumbnail ?? alchemyMedia?.raw; | ||
const mediaFormat = alchemyMedia?.format === "mp4" ? "video" : "image"; | ||
|
||
return { format: mediaFormat, src: mediaSrc }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { validateAndParseAddress } from "starknet"; | ||
|
||
import { type NftMedia } from "../types"; | ||
|
||
const requestsHeader = { | ||
"Content-Type": "application/json", | ||
"X-API-KEY": process.env.ARK_API_KEY ?? "", | ||
}; | ||
const nftApiUrl = process.env.NEXT_PUBLIC_ARK_API_DOMAIN ?? ""; | ||
|
||
type ArkCollectionsApiResponse = { | ||
result: Array<{ | ||
contract_address: string; | ||
contract_type: string; | ||
image?: string; | ||
name: string; | ||
symbol: string; | ||
tokens_count: number; | ||
}>; | ||
total_count: number; | ||
}; | ||
export async function getL2ContractsForOwner(address: string) { | ||
const url = `${nftApiUrl}/v1/owners/${validateAndParseAddress( | ||
address | ||
)}/contracts`; | ||
|
||
const contractsResponse = await fetch(url, { | ||
headers: requestsHeader, | ||
}); | ||
const contracts = | ||
(await contractsResponse.json()) as ArkCollectionsApiResponse; | ||
|
||
return contracts; | ||
} | ||
|
||
type ArkBatchNftsApiResponse = { | ||
result: Array<{ | ||
contract_address: string; | ||
contract_name: string; | ||
metadata?: { normalized: { image?: string; name?: string } }; | ||
owner: string; | ||
token_id: string; | ||
}>; | ||
}; | ||
export async function getL2NftsMetadataBatch( | ||
tokens: Array<{ contract_address: string; token_id: string }> | ||
) { | ||
const url = `${nftApiUrl}/v1/tokens/batch`; | ||
|
||
const nftsResponse = await fetch(url, { | ||
body: JSON.stringify({ | ||
tokens: tokens.map((token) => ({ | ||
contract_address: validateAndParseAddress(token.contract_address), | ||
token_id: token.token_id, | ||
})), | ||
}), | ||
headers: requestsHeader, | ||
method: "POST", | ||
}); | ||
|
||
const nfts = (await nftsResponse.json()) as ArkBatchNftsApiResponse; | ||
|
||
return nfts; | ||
} | ||
|
||
type ArkNftsApiResponse = { | ||
result: Array<{ | ||
contract_address: string; | ||
metadata: { | ||
normalized: { image: null | string; name: null | string }; | ||
} | null; | ||
owner: string; | ||
token_id: string; | ||
}>; | ||
total_count: number; | ||
}; | ||
export async function getL2NftsForOwner( | ||
userAddress: string, | ||
contractAddress: string | undefined | ||
) { | ||
const url = `${nftApiUrl}/v1/owners/${validateAndParseAddress( | ||
userAddress | ||
)}/tokens${ | ||
contractAddress !== undefined | ||
? `?contract_address=${validateAndParseAddress(contractAddress)}` | ||
: "" | ||
}`; | ||
|
||
const nftsResponse = await fetch(url, { | ||
headers: requestsHeader, | ||
}); | ||
|
||
const nfts = (await nftsResponse.json()) as ArkNftsApiResponse; | ||
|
||
return nfts; | ||
} | ||
|
||
type ArkCollectionInfoApiResponse = { | ||
result: { contract_address: string; name: string; symbol: string }; | ||
}; | ||
export async function getL2ContractMetadata(contractAddress: string) { | ||
const url = `${nftApiUrl}/v1/contracts/${validateAndParseAddress( | ||
contractAddress | ||
)}`; | ||
|
||
const contractInfoResponse = await fetch(url, { | ||
headers: requestsHeader, | ||
}); | ||
|
||
const contractInfo = | ||
(await contractInfoResponse.json()) as ArkCollectionInfoApiResponse; | ||
|
||
return contractInfo; | ||
} | ||
|
||
export function getMediaObjectFromUrl(image: string | undefined): NftMedia { | ||
if (image === undefined) { | ||
return { format: "image", src: undefined }; | ||
} | ||
const mediaSrc = image.replace("ipfs://", process.env.IPFS_GATEWAY ?? ""); | ||
const mediaFormat = mediaSrc?.split(".").pop() === "mp4" ? "video" : "image"; | ||
|
||
return { format: mediaFormat, src: mediaSrc }; | ||
} |
Oops, something went wrong.