-
Notifications
You must be signed in to change notification settings - Fork 61
/
index.tsx
42 lines (36 loc) · 1.28 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { Address, NftMetadata } from "../../types"
import type { EthereumFetcher, EthereumFetcherConfig } from "./types"
import { isAddress } from "../../utils"
import { fetchMetadata } from "../shared/fetch-metadata"
import { cryptoPunksMetadata, isCryptoPunks } from "../shared/cryptopunks"
import { cryptoKittiesMetadata, isCryptoKitties } from "../shared/cryptokitties"
import { moonCatsMetadata, isMoonCats } from "../shared/mooncats"
import { moonCatsCatId } from "./mooncats"
import { fetchStandardNftUrl } from "./standard-nft"
export default function ethereumFetcher(
config: EthereumFetcherConfig
): EthereumFetcher {
return {
config,
async fetchNft(
contractAddress: Address,
tokenId: string
): Promise<NftMetadata> {
if (!isAddress(contractAddress)) {
throw new Error("Invalid contract address: " + contractAddress)
}
if (isCryptoPunks(contractAddress)) {
return cryptoPunksMetadata(tokenId)
}
if (isCryptoKitties(contractAddress)) {
return cryptoKittiesMetadata(tokenId)
}
if (isMoonCats(contractAddress)) {
return moonCatsMetadata(tokenId, moonCatsCatId(config))
}
return fetchMetadata(
await fetchStandardNftUrl(contractAddress, tokenId, config)
)
},
}
}