UNPKG

@cryptopuppie/useatomicassets

Version:

Custom SWR hooks for Atomicassets api data fetching.

697 lines (673 loc) 19.4 kB
import { ReactNode } from 'react'; interface UseAtomicAssetsProps { children: ReactNode; endpoint?: string; } declare const UseAtomicAssetsProvider: ({ children, endpoint }: UseAtomicAssetsProps) => JSX.Element; declare class FetchError extends Error { readonly status: number; constructor(message: string, status: number); } interface FetchResult<T> { data?: T; error?: FetchError; isError: boolean; } interface useAtomicGetterProps<T, K = Record<string, any>> { /** * Api url endpoint to send request. */ uri: string; /** * Request params. */ params?: T; /** * Atomicassets api endpoint. */ endpoint?: string; /** * Set initial data, used when using SSR or SSG rendering with Next */ initialData?: K; } /** * Custom request hook for sending request to custom atomicasset endpoints. * * @param props Request props. * @returns FetchResult<K> */ declare const useAtomicGetter: <K, T extends Record<string, any> = Record<string, any>>(props?: useAtomicGetterProps<T, Record<string, any>> | null | undefined) => FetchResult<K>; interface QueryOptions<T> { endpoint?: string; initialData?: T; } declare enum OfferState { Pending = 0, Invalid = 1, Unknown = 2, Accepted = 3, Declined = 4, Canceled = 5 } declare enum OrderParam { Asc = "asc", Desc = "desc" } declare enum AssetsSort { AssetId = "asset_id", Updated = "updated", Transferred = "transferred", Minted = "minted", TemplateMint = "template_mint", Name = "name" } declare enum CollectionsSort { Created = "created", CollectionName = "collection_name" } declare enum OffersSort { Created = "created", Updated = "updated" } declare enum SchemasSort { Created = "created", SchemaName = "schema_name" } declare enum TemplatesSort { Created = "created", Name = "name" } declare enum TransfersSort { Created = "created" } interface SchemaObject { name: string; type: string; parent?: number; } declare type DataOptions = Array<{ key: string; value: any; type?: string; }>; interface ILightCollection { contract: string; collection_name: string; name: string; img: string; author: string; allow_notify: boolean; authorized_accounts: string[]; notify_accounts: string[]; market_fee: number; data: { [key: string]: any; }; created_at_block: string; created_at_time: string; } interface ILightSchema { schema_name: string; format: SchemaObject[]; created_at_block: string; created_at_time: string; } interface ILightTemplate { template_id: string; max_supply: string; is_transferable: boolean; is_burnable: boolean; issued_supply: string; immutable_data: { [key: string]: any; }; created_at_block: string; created_at_time: string; } interface IAsset { contract: string; asset_id: string; owner: string | null; name: string; is_transferable: boolean; is_burnable: boolean; template_mint: string; collection: ILightCollection; schema: ILightSchema; template: ILightTemplate | null; backed_tokens: Array<{ token_contract: string; token_symbol: string; token_precision: number; amount: string; }>; immutable_data: { [key: string]: any; }; mutable_data: { [key: string]: any; }; data: { [key: string]: any; }; burned_by_account: string | null; burned_at_block: string | null; burned_at_time: string | null; updated_at_block: string; updated_at_time: string; transferred_at_block: string; transferred_at_time: string; minted_at_block: string; minted_at_time: string; } interface ICollection extends ILightCollection { contract: string; } interface ISchema extends ILightSchema { contract: string; collection: ILightCollection; } interface ITemplate extends ILightTemplate { contract: string; collection: ILightCollection; schema: ILightSchema; } interface IOffer { contract: string; offer_id: string; sender_name: string; recipient_name: string; memo: string; state: OfferState; sender_assets: IAsset[]; recipient_assets: IAsset[]; is_sender_contract: boolean; is_recipient_contract: boolean; updated_at_block: string; updated_at_time: string; created_at_block: string; created_at_time: string; } interface ITransfer { contract: string; transfer_id: string; sender_name: string; recipient_name: string; memo: string; txid: string; assets: IAsset[]; created_at_block: string; created_at_time: string; } interface ILog { log_id: string; name: string; data: { [key: string]: any; }; txid: string; created_at_block: string; created_at_time: string; } interface IConfig { contract: string; version: string; collection_format: SchemaObject[]; supported_tokens: Array<{ token_contract: string; token_symbol: string; token_precision: number; }>; } interface IAssetStats { template_mint: number; } interface ICollectionStats { assets: string; burned: string; templates: string; schemas: string; burned_by_template: Array<{ template_id: string; burned: number; }>; burned_by_schema: Array<{ schema_name: string; burned: number; }>; } interface ISchemaStats { assets: string; burned: string; templates: string; } interface ITemplateStats { assets: string; burned: string; } interface IAccountStats { collections: Array<{ collection: ICollection; assets: string; }>; templates: Array<{ template_id: string; assets: string; }>; assets: string; } interface IAccountCollectionStats { schemas: Array<{ schema_name: ICollection; assets: string; }>; templates: Array<{ template_id: string; assets: string; }>; } interface GreylistParams { collection_blacklist?: string; collection_whitelist?: string; } interface HideOffersParams { hide_offers?: boolean; } interface PrimaryBoundaryParams { ids?: string; lower_bound?: string; upper_bound?: string; } interface DateBoundaryParams { before?: number; after?: number; } interface AssetFilterParams { asset_id?: string; owner?: string; burned?: boolean; collection_name?: string; schema_name?: string; template_id?: number; match?: string; is_transferable?: boolean; is_burnable?: boolean; [key: string]: any; } interface AssetsApiParams extends AssetFilterParams, GreylistParams, HideOffersParams, PrimaryBoundaryParams, DateBoundaryParams { authorized_account?: string; only_duplicate_templates?: boolean; min_template_mint?: number; max_template_mint?: number; template_blacklist?: string; template_whitelist?: string; order?: OrderParam; sort?: AssetsSort; } interface CollectionApiParams extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams { author?: string; match?: string; authorized_account?: string; notify_account?: string; order?: OrderParam; sort?: CollectionsSort; } interface SchemaApiParams extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams { collection_name?: string; schema_name?: string; match?: string; authorized_account?: string; order?: OrderParam; sort?: SchemasSort; } interface TemplateApiParams extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams { collection_name?: string; schema_name?: string; authorized_account?: string; template_id?: string; max_supply?: number; has_assets?: boolean; issued_supply?: number; min_issued_supply?: number; max_issued_supply?: number; is_transferable?: boolean; is_burnable?: boolean; order?: OrderParam; sort?: TemplatesSort; [key: string]: any; } interface TransferApiParams extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams { account?: string; sender?: string; recipient?: string; asset_id?: string; order?: OrderParam; sort?: TransfersSort; } interface OfferApiParams extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams { account?: string; sender?: string; recipient?: string; asset_id?: string; state?: OfferState; is_recipient_contract?: boolean; hide_contracts?: boolean; recipient_asset_blacklist?: string; recipient_asset_whitelist?: string; sender_asset_blacklist?: string; sender_asset_whitelist?: string; account_whitelist?: string; account_blacklist?: string; order?: OrderParam; sort?: OffersSort; } interface AccountApiParams extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams { match?: string; collection_name?: string; schema_name?: string; template_id?: string; } interface useGetAccountProps extends GreylistParams, HideOffersParams { } /** * Get a specific account stats. * * `/atomicassets/v1/accounts/{accountName}` * * @param account Account name. * @param props Query props. * @param options Set custom fetch options. * @returns FetchResult<IAccountStats> */ declare const useGetAccount: <T = Record<string, any>>(account?: string | null, props?: useGetAccountProps | null, options?: QueryOptions<T> | undefined) => FetchResult<IAccountStats>; interface IAccountsProps { account: string; assets: string; } interface ISales { market_contract: string; assets_contract: string; sale_id: string; seller: string; buyer: string; offer_id: string; price: Price; listing_price: number; listing_symbol: string; assets: Asset[]; maker_marketplace: string; taker_marketplace: string; collection: Collection; state: number; updated_at_block: string; updated_at_time: string; created_at_block: string; created_at_time: string; } interface Asset { contract: string; asset_id: string; owner: string; name: string; is_transferable: boolean; is_burnable: boolean; template_mint: string; collection: Collection; schema: ILightSchema; template: Template; backed_tokens: Price[]; immutable_data: Data; mutable_data: Data; data: Data; burned_by_account: string; burned_at_block: string; burned_at_time: string; updated_at_block: string; updated_at_time: string; transferred_at_block: string; transferred_at_time: string; minted_at_block: string; minted_at_time: string; } interface Price { token_contract: string; token_symbol: string; token_precision: number; amount: string; } interface Collection { collection_name: string; name: string; author: string; allow_notify: boolean; authorized_accounts: string[]; notify_accounts: string[]; market_fee: number; created_at_block: string; created_at_time: string; } declare type Data = Record<string, any>; interface Template { template_id: string; max_supply: string; issued_supply: string; is_transferable: boolean; is_burnable: boolean; immutable_data: Data; created_at_time: string; created_at_block: string; } interface PageLimitOrderParams { page?: number; limit?: number; order?: 'asc' | 'desc'; } interface BurnableTransferableParams { is_burnable?: boolean; is_transferable?: boolean; } interface useGetAccountsProps extends GreylistParams, HideOffersParams, PrimaryBoundaryParams, PageLimitOrderParams { match?: string; collection_name?: string; schema_name?: string; template_id?: string; } /** * Get accounts which own atomicassets NFTs. * * `/atomicassets/v1/accounts` * * @param props Query props. * @param options Set custom fetch options. * @returns FechResult<IAccountsProps> */ declare const useGetAccounts: <T = Record<string, any>>(props?: useGetAccountsProps | null, options?: QueryOptions<T> | undefined) => FetchResult<IAccountsProps[]>; /** * Fetch asset by id. * * `/atomicassets/v1/assets/{assetId}` * * @param assetId ID of asset * @param options Set custom fetch options. * @returns FetchResult<IAsset> */ declare const useGetAssetID: <T = Record<string, any>>(assetId?: string | null, options?: QueryOptions<T> | undefined) => FetchResult<IAsset>; interface useGetAssetsProps extends GreylistParams, HideOffersParams, DateBoundaryParams, PrimaryBoundaryParams, PageLimitOrderParams, BurnableTransferableParams { collection_name?: string; schema_name?: string; template_id?: string; burned?: boolean; owner?: string; match?: string; match_immutable_name?: string; match_mutable_name?: string; only_duplicate_templates?: boolean; has_backed_tokens?: boolean; authorized_account?: string; template_whitelist?: string; template_blacklist?: string; hide_template_by_accounts?: string; sort?: 'asset_id' | 'minted' | 'updated' | 'transferred' | 'template_mint' | 'name'; } /** * Fetch assets. * * `/atomicassets/v1/assets` * * @param props Query options * @param dataOptions Custom query options for asset / template data fields. * @param options Set custom fetch options. * @returns FetchResult<IAsset[]> */ declare const useGetAssets: <T = Record<string, any>>(props?: useGetAssetsProps | null, dataOptions?: DataOptions, options?: QueryOptions<T> | undefined) => FetchResult<IAsset[]>; /** * Find collection by its name. * * `/atomicassets/v1/collection/{collectionName}` * * @param collectionName Name of collection. * @param options Set custom fetch options. * @returns FetchResult<ICollection> */ declare const useGetCollectionName: <T = Record<string, any>>(collectionName?: string | null, options?: QueryOptions<T> | undefined) => FetchResult<ICollection>; interface useGetCollectionsProps extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams, PageLimitOrderParams { author?: string; match?: string; authorized_account?: string; notify_account?: string; sort?: 'created' | 'collection_name'; } /** * Fetch collections. * * `/atomicassets/v1/collections` * * @param props Query options. * @param options Set custom fetch options. * @returns FetchResult<ICollection[]> */ declare const useGetCollections: <T = Record<string, any>>(props?: useGetCollectionsProps | null, options?: QueryOptions<T> | undefined) => FetchResult<ICollection[]>; interface useGetSchemaNameProps { /** * Name of schema. */ schemaName: string; /** * Collection name of schema. */ collectionName: string; } /** * Find schema by its name. * * `/atomicassets/v1/schemas/{collectionName}/{schemaName}` * * @param props Path params. * @param options Set custom fetch options. * @returns FetchResult<ISchema> */ declare const useGetSchemaName: <T = Record<string, any>>(props?: useGetSchemaNameProps | null, options?: QueryOptions<T> | undefined) => FetchResult<ISchema>; interface useGetSchemasProps extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams, PageLimitOrderParams { collection_name?: string; authorized_account?: string; schema_name?: string; match?: string; sort?: 'created' | 'schema_name'; } /** * Fetch schemas. * * `/atomicassets/v1/schemas` * * @param props Query options * @param options Set custom fetch options. * @returns FetchResult<ISchema[]> */ declare const useGetSchemas: <T = Record<string, any>>(props?: useGetSchemasProps | null, options?: QueryOptions<T> | undefined) => FetchResult<ISchema[]>; interface useGetTemplateIDProps { /** * Name of collection. */ collectionName: string; /** * ID of template. */ templateID: number; } /** * Find template by id. * * `/atomicassets/v1/templates/{collectionName}/{templateID}` * * @param props Path params. * @param options Set custom fetch options. * @returns FetchResult<ITemplate> */ declare const useGetTemplateID: <T = Record<string, any>>(props?: useGetTemplateIDProps | null, options?: QueryOptions<T> | undefined) => FetchResult<ITemplate>; interface useGetTemplatesProps extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams, PageLimitOrderParams, BurnableTransferableParams { collection_name?: string; schema_name?: string; issued_supply?: number; min_issued_supply?: number; max_issued_supply?: number; has_assets?: boolean; max_supply?: number; authorized_account?: string; match?: string; sort?: 'name' | 'created'; } /** * Fetch templates. * * `/atomicassets/v1/templates` * * @param props Query options. * @param options Set custom fetch options. * @returns FetchResult<ITemplate[]> */ declare const useGetTemplates: <T = Record<string, any>>(props?: useGetTemplatesProps | null, options?: QueryOptions<T> | undefined) => FetchResult<ITemplate[]>; interface useMarketGetSalesProps extends GreylistParams, PrimaryBoundaryParams, DateBoundaryParams, PageLimitOrderParams { state?: string; max_assets?: number; min_assets?: number; show_seller_contracts?: boolean; contract_whitelist?: string; seller_blacklist?: string; buyer_blacklist?: string; asset_id?: number; marketplace?: string; maker_marketplace?: string; taker_marketplace?: string; symbol?: string; account?: string; seller?: string; buyer?: string; min_price?: number; max_price?: number; min_template_mint?: number; max_template_mint?: number; collection_name?: string; schema_name?: string; template_id?: number; is_transferable?: boolean; is_burnable?: boolean; burned?: boolean; owner?: string; match?: string; match_immutable_name?: string; match_mutable_name?: string; sort?: 'created' | 'updated' | 'sale_id' | 'price' | 'template_mint'; } /** * Get market sales. * * `/atomicmarket/v1/sales` * * @param props Query options. * @param dataOptions Custom query options for asset / template data fields. * @param options Set custom fetch options. * @returns FetchResult<ISales[]> */ declare const useMarketGetSales: <T = Record<string, any>>(props?: useMarketGetSalesProps | null, dataOptions?: DataOptions, options?: QueryOptions<T> | undefined) => FetchResult<ISales[]>; export { AccountApiParams, AssetFilterParams, AssetsApiParams, AssetsSort, CollectionApiParams, CollectionsSort, DataOptions, DateBoundaryParams, GreylistParams, HideOffersParams, IAccountCollectionStats, IAccountStats, IAsset, IAssetStats, ICollection, ICollectionStats, IConfig, ILightCollection, ILightSchema, ILightTemplate, ILog, IOffer, ISchema, ISchemaStats, ITemplate, ITemplateStats, ITransfer, OfferApiParams, OfferState, OffersSort, OrderParam, PrimaryBoundaryParams, SchemaApiParams, SchemaObject, SchemasSort, TemplateApiParams, TemplatesSort, TransferApiParams, TransfersSort, UseAtomicAssetsProvider, useAtomicGetter, useGetAccount, useGetAccounts, useGetAssetID, useGetAssets, useGetCollectionName, useGetCollections, useGetSchemaName, useGetSchemas, useGetTemplateID, useGetTemplates, useMarketGetSales };