opensea-js
Version:
TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data
119 lines • 4.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.feeFromJSON = exports.accountFromJSON = exports.paymentTokenFromJSON = exports.rarityFromJSON = exports.collectionFromJSON = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Converts a collection JSON response to an OpenSeaCollection object.
* @param collection The raw collection JSON from the API
* @returns OpenSeaCollection object
*/
const collectionFromJSON = (collection) => {
return {
name: collection.name,
collection: collection.collection,
description: collection.description,
imageUrl: collection.image_url,
bannerImageUrl: collection.banner_image_url,
owner: collection.owner,
safelistStatus: collection.safelist_status,
category: collection.category,
isDisabled: collection.is_disabled,
isNSFW: collection.is_nsfw,
traitOffersEnabled: collection.trait_offers_enabled,
collectionOffersEnabled: collection.collection_offers_enabled,
openseaUrl: collection.opensea_url,
projectUrl: collection.project_url,
wikiUrl: collection.wiki_url,
discordUrl: collection.discord_url,
telegramUrl: collection.telegram_url,
twitterUsername: collection.twitter_username,
instagramUsername: collection.instagram_username,
contracts: (collection.contracts ?? []).map((contract) => ({
address: contract.address,
chain: contract.chain,
})),
editors: collection.editors,
fees: (collection.fees ?? []).map(exports.feeFromJSON),
rarity: (0, exports.rarityFromJSON)(collection.rarity),
paymentTokens: (collection.payment_tokens ?? []).map(exports.paymentTokenFromJSON),
totalSupply: collection.total_supply,
uniqueItemCount: collection.unique_item_count,
createdDate: collection.created_date,
requiredZone: collection.required_zone,
};
};
exports.collectionFromJSON = collectionFromJSON;
/**
* Converts a rarity JSON response to a RarityStrategy object.
* @param rarity The raw rarity JSON from the API
* @returns RarityStrategy object or null
*/
const rarityFromJSON = (rarity) => {
if (!rarity) {
return null;
}
const fromJSON = {
strategyId: rarity.strategy_id,
strategyVersion: rarity.strategy_version,
calculatedAt: rarity.calculated_at,
maxRank: rarity.max_rank,
tokensScored: rarity.tokens_scored,
};
return fromJSON;
};
exports.rarityFromJSON = rarityFromJSON;
/**
* Converts a payment token JSON response to an OpenSeaPaymentToken object.
* @param token The raw payment token JSON from the API
* @returns OpenSeaPaymentToken object
*/
const paymentTokenFromJSON = (token) => {
const fromJSON = {
name: token.name,
symbol: token.symbol,
decimals: token.decimals,
address: token.address,
chain: token.chain,
imageUrl: token.image,
ethPrice: token.eth_price,
usdPrice: token.usd_price,
};
return fromJSON;
};
exports.paymentTokenFromJSON = paymentTokenFromJSON;
/**
* Converts an account JSON response to an OpenSeaAccount object.
* @param account The raw account JSON from the API
* @returns OpenSeaAccount object
*/
const accountFromJSON = (account) => {
return {
address: account.address,
username: account.username,
profileImageUrl: account.profile_image_url,
bannerImageUrl: account.banner_image_url,
website: account.website,
socialMediaAccounts: (account.social_media_accounts ?? []).map((acct) => ({
platform: acct.platform,
username: acct.username,
})),
bio: account.bio,
joinedDate: account.joined_date,
};
};
exports.accountFromJSON = accountFromJSON;
/**
* Converts a fee JSON response to a Fee object.
* @param fee The raw fee JSON from the API
* @returns Fee object
*/
const feeFromJSON = (fee) => {
const fromJSON = {
fee: fee.fee,
recipient: fee.recipient,
required: fee.required,
};
return fromJSON;
};
exports.feeFromJSON = feeFromJSON;
//# sourceMappingURL=converters.js.map