UNPKG

@cross-nft-marketplace/auction-house-nft-hooks

Version:

Generic react hooks for fetching cross-nft-marketplace auctions, nfts, and data on arbitary 721s. Powers nft-components.

213 lines (212 loc) 11.6 kB
import { NetworkIDs } from '../constants/networks'; import type { ReserveAuctionPartialFragment } from '../graph-queries/zora-graph-types'; import { MediaContentType } from './FetchResultTypes'; import { CurrencyLookupType } from './AuctionInfoTypes'; import { OpenseaResponse } from './OpenseaUtils'; import { NotFoundError } from './ErrorUtils'; import { IndexerTokenWithAuctionFragment } from '../graph-queries/zora-indexer-types'; import { MetadataIsh } from './MetadataTypes'; import { BlockchainResponse } from './BlockchainUtils'; import { TokenWithMarketsSummary } from '@zoralabs/zdk/dist/queries/queries-sdk'; export interface MediaFetchAgentProps { network?: NetworkIDs; infuraApiKey?: string; zdkApiKey?: string; batchScheduleTimeoutMs?: number; } /** * Internal agent for NFT Hooks to fetch NFT information. * Can be used directly for interaction with non-react web frameworks or server frameworks. * Uses a cached promise-based API. * Fetches from IPFS providers and thegraph. */ export declare class MediaFetchAgent { readonly networkId: NetworkIDs; readonly infuraApiKey: string; private timeouts; private zdk; private loaders; constructor(props_?: MediaFetchAgentProps); /** * Clear all cached responses from metadata, currency, and NFT chain information loaders */ clearCache(): void; /** * Gets information of currencies and trading prices from uniswap * @param currencies list of currency contract ids on ethereum * @returns Promise<CurrencyLookupType> */ loadCurrencies(currencies: string[]): Promise<CurrencyLookupType>; /** * Fetch NFT content or retun URI if content shouild not be fetched * @param url NFT Content URL * @param contentType string mime type to fetch * @returns Promise<MediaContentType> Media content information or URL */ fetchContent(url: string, contentType: string): Promise<MediaContentType>; /** * Fetch Content MIME type from content URI * * @param url IPFS Content URI * @returns mime type as a string * @throws RequestError */ fetchContentMimeType(url: string): Promise<string>; loadEnsBatch(addresses: readonly string[]): Promise<(string | Error)[]>; fetchZoraNFTIndexerNFTs(keys: readonly string[]): Promise<any[]>; fetchZoraNFTIndexerV2NFTs(keys: readonly string[]): Promise<(TokenWithMarketsSummary | NotFoundError)[]>; loadZoraNFTIndexerNFTUntransformed(contractAddress: string, tokenId: string): Promise<IndexerTokenWithAuctionFragment>; loadZoraNFTIndexerV2NFTUntransformed(contractAddress: string, tokenId: string): Promise<TokenWithMarketsSummary>; loadNFTData(contractAddress: string, tokenId: string, auctionData?: ReserveAuctionPartialFragment, currencyData?: CurrencyLookupType): Promise<import("./AuctionInfoTypes").OpenseaNFTDataType>; loadNFTDataUntransformed(contractAddress: string, tokenId: string): Promise<OpenseaResponse>; loadBlockchainNFTDataUntransformed(contractAddress: string, tokenId: string): Promise<BlockchainResponse>; loadAuctionInfo(tokenContract: string, tokenId: string): Promise<ReserveAuctionPartialFragment>; loadAuctionInfos(tokenContractAndIds: readonly string[]): Promise<(Error | ReserveAuctionPartialFragment)[]>; loadEnsName(address: string): Promise<string>; /** * Fetch function to retrieve Graph data for matching curated auctions * This function is not cached * * @function fetchReserveAuctions * @private * @param curatorIds list of Zora NFT IDs to fetch from the graph datastore * @returns mapped transformed list of curated auction results */ fetchReserveAuctions(curatorIds: readonly string[], isApproved?: boolean | null, first?: number, skip?: number): Promise<({ __typename?: "ReserveAuction" | undefined; } & { __typename?: "ReserveAuction" | undefined; } & Pick<import("../graph-queries/zora-graph-types").ReserveAuction, "id" | "createdAtTimestamp" | "transactionHash" | "approved" | "tokenId" | "tokenContract" | "status" | "reservePrice" | "buyNowPrice" | "firstBidTime" | "token" | "approvedTimestamp" | "curatorFeePercentage" | "duration" | "expectedEndTimestamp" | "finalizedAtTimestamp"> & { reserveAndBuyNowCurrency: { __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">; curator: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; tokenOwner: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; auctionCurrencies?: import("../graph-queries/zora-graph-types").Maybe<({ __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">)[]> | undefined; currentBid?: import("../graph-queries/zora-graph-types").Maybe<{ __typename?: "ReserveAuctionBid" | undefined; } & { __typename?: "ReserveAuctionBid" | undefined; } & Pick<import("../graph-queries/zora-graph-types").ReserveAuctionBid, "id" | "amount" | "createdAtTimestamp" | "transactionHash" | "bidType" | "buyNowRequested" | "buyNowActual"> & { bidder: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; currency: { __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">; }> | undefined; previousBids?: import("../graph-queries/zora-graph-types").Maybe<({ __typename?: "InactiveReserveAuctionBid" | undefined; } & { __typename?: "InactiveReserveAuctionBid" | undefined; } & Pick<import("../graph-queries/zora-graph-types").InactiveReserveAuctionBid, "id" | "amount" | "createdAtTimestamp" | "transactionHash" | "bidType" | "buyNowRequested" | "buyNowActual" | "bidInactivatedAtTimestamp" | "bidInactivatedAtBlockNumber"> & { bidder: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; currency: { __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">; })[]> | undefined; })[]>; /** * Fetch function to retrieve Graph data for matching curated auctions * This function is not cached * * @function fetchReserveAuctionsByOwner * @private * @param curatorIds list of Zora NFT IDs to fetch from the graph datastore * @returns mapped transformed list of curated auction results */ fetchReserveAuctionsByOwner(owner: string, curatorIds: readonly string[], isApproved?: boolean | null, first?: number, skip?: number): Promise<({ __typename?: "ReserveAuction" | undefined; } & { __typename?: "ReserveAuction" | undefined; } & Pick<import("../graph-queries/zora-graph-types").ReserveAuction, "id" | "createdAtTimestamp" | "transactionHash" | "approved" | "tokenId" | "tokenContract" | "status" | "reservePrice" | "buyNowPrice" | "firstBidTime" | "token" | "approvedTimestamp" | "curatorFeePercentage" | "duration" | "expectedEndTimestamp" | "finalizedAtTimestamp"> & { reserveAndBuyNowCurrency: { __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">; curator: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; tokenOwner: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; auctionCurrencies?: import("../graph-queries/zora-graph-types").Maybe<({ __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">)[]> | undefined; currentBid?: import("../graph-queries/zora-graph-types").Maybe<{ __typename?: "ReserveAuctionBid" | undefined; } & { __typename?: "ReserveAuctionBid" | undefined; } & Pick<import("../graph-queries/zora-graph-types").ReserveAuctionBid, "id" | "amount" | "createdAtTimestamp" | "transactionHash" | "bidType" | "buyNowRequested" | "buyNowActual"> & { bidder: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; currency: { __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">; }> | undefined; previousBids?: import("../graph-queries/zora-graph-types").Maybe<({ __typename?: "InactiveReserveAuctionBid" | undefined; } & { __typename?: "InactiveReserveAuctionBid" | undefined; } & Pick<import("../graph-queries/zora-graph-types").InactiveReserveAuctionBid, "id" | "amount" | "createdAtTimestamp" | "transactionHash" | "bidType" | "buyNowRequested" | "buyNowActual" | "bidInactivatedAtTimestamp" | "bidInactivatedAtBlockNumber"> & { bidder: { __typename?: "User" | undefined; } & Pick<import("../graph-queries/zora-graph-types").User, "id">; currency: { __typename?: "Currency" | undefined; } & { __typename?: "Currency" | undefined; } & Pick<import("../graph-queries/zora-graph-types").Currency, "symbol" | "id" | "name" | "decimals">; })[]> | undefined; })[]>; private fetchAuctionNFTInfo; /** * Fetches generic NFT information * * @param nftAddresses list of addresses in a 0xcontractid:tokenid format * @returns */ private fetchGenericNFT; private fetchBlockchainGenericNFT; /** * Internal fetch function to retrieve currency information from TheGraph * * @function fetchCurrenciesGraph * @private * @param currencyContracts list of Ethereum addresses of currency contract data to retrieve * @returns mapped transformed list of ETH currency mapping data */ private fetchCurrenciesGraph; /** * Fetch method to query metadata from IPFS. Not cached * * @function fetchIPFSMetadataCached * @public * @param url Metadata Source * @returns IPFS Metadata Fetch * @throws RequestError */ fetchIPFSMetadata(url: string): Promise<MetadataIsh>; }