UNPKG

@yoroi/portfolio

Version:

The Portfolio package of Yoroi SDK

79 lines (78 loc) 4.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseTokenInfoWithCacheRecord = exports.parseTokenInfo = exports.parseSecondaryTokenInfoWithCacheRecord = exports.isTokenInfoWithCacheRecord = exports.isTokenInfo = exports.isSecondaryTokenInfoWithCacheRecord = exports.isSecondaryTokenInfo = exports.isPrimaryTokenInfo = exports.TokenInfoWithCacheRecordSchema = exports.TokenInfoSchema = exports.SecondaryTokenInfoSchema = exports.SecondaryTokenInfoApiResponseWithCacheRecordSchema = exports.SecondaryTokenInfoApiResponseSchema = exports.PrimaryTokenInfoSchema = exports.CommonTokenInfoSchema = void 0; var _types = require("@yoroi/types"); var _common = require("@yoroi/common"); var _zod = require("zod"); var _tokenStatus = require("./token-status"); var _tokenApplication = require("./token-application"); var _tokenId = require("./token-id"); var _tokenType = require("./token-type"); var _responseRecordWithCacheSchemaMaker = require("./response-record-with-cache-schema-maker"); var _constants = require("../constants"); const CommonTokenInfoSchema = _zod.z.object({ decimals: _zod.z.number().nonnegative(), ticker: _zod.z.string(), name: _zod.z.string(), symbol: _zod.z.string(), status: _tokenStatus.TokenStatusSchema, application: _tokenApplication.TokenApplicationSchema, tag: _zod.z.string(), reference: _zod.z.string(), fingerprint: _zod.z.string(), website: _zod.z.string(), originalImage: _zod.z.string(), description: _zod.z.string().optional(), icon: _zod.z.string().optional(), mediaType: _zod.z.string().optional() }); exports.CommonTokenInfoSchema = CommonTokenInfoSchema; const PrimaryTokenInfoSchema = CommonTokenInfoSchema.merge(_zod.z.object({ id: _zod.z.literal(_constants.primaryTokenId), nature: _zod.z.literal(_types.Portfolio.Token.Nature.Primary), type: _zod.z.literal(_types.Portfolio.Token.Type.FT) })); exports.PrimaryTokenInfoSchema = PrimaryTokenInfoSchema; const SecondaryTokenInfoSchema = CommonTokenInfoSchema.merge(_zod.z.object({ id: _tokenId.TokenIdSchema, nature: _zod.z.literal(_types.Portfolio.Token.Nature.Secondary), type: _tokenType.TokenTypeSchema })); exports.SecondaryTokenInfoSchema = SecondaryTokenInfoSchema; const SecondaryTokenInfoApiResponseSchema = CommonTokenInfoSchema.merge(_zod.z.object({ id: _tokenId.TokenIdSchema, nature: _zod.z.literal(_types.Portfolio.Token.Nature.Secondary).optional(), type: _tokenType.TokenTypeSchema })); exports.SecondaryTokenInfoApiResponseSchema = SecondaryTokenInfoApiResponseSchema; const TokenInfoSchema = _zod.z.union([PrimaryTokenInfoSchema, SecondaryTokenInfoSchema]); exports.TokenInfoSchema = TokenInfoSchema; const isPrimaryTokenInfo = data => PrimaryTokenInfoSchema.safeParse(data).success; exports.isPrimaryTokenInfo = isPrimaryTokenInfo; const isSecondaryTokenInfo = data => SecondaryTokenInfoSchema.safeParse(data).success; exports.isSecondaryTokenInfo = isSecondaryTokenInfo; const isTokenInfo = data => isPrimaryTokenInfo(data) || isSecondaryTokenInfo(data); exports.isTokenInfo = isTokenInfo; const parseTokenInfo = data => { return isTokenInfo(data) ? data : undefined; }; exports.parseTokenInfo = parseTokenInfo; const SecondaryTokenInfoApiResponseWithCacheRecordSchema = (0, _responseRecordWithCacheSchemaMaker.responseRecordWithCacheSchemaMaker)(SecondaryTokenInfoApiResponseSchema); exports.SecondaryTokenInfoApiResponseWithCacheRecordSchema = SecondaryTokenInfoApiResponseWithCacheRecordSchema; const isSecondaryTokenInfoWithCacheRecord = data => SecondaryTokenInfoApiResponseWithCacheRecordSchema.safeParse(data).success; exports.isSecondaryTokenInfoWithCacheRecord = isSecondaryTokenInfoWithCacheRecord; const parseSecondaryTokenInfoWithCacheRecord = data => { return isSecondaryTokenInfoWithCacheRecord(data) ? data : undefined; }; exports.parseSecondaryTokenInfoWithCacheRecord = parseSecondaryTokenInfoWithCacheRecord; const TokenInfoWithCacheRecordSchema = (0, _common.cacheRecordSchemaMaker)(TokenInfoSchema); exports.TokenInfoWithCacheRecordSchema = TokenInfoWithCacheRecordSchema; const isTokenInfoWithCacheRecord = data => TokenInfoWithCacheRecordSchema.safeParse(data).success; exports.isTokenInfoWithCacheRecord = isTokenInfoWithCacheRecord; const parseTokenInfoWithCacheRecord = data => { return isTokenInfoWithCacheRecord(data) ? data : undefined; }; exports.parseTokenInfoWithCacheRecord = parseTokenInfoWithCacheRecord; //# sourceMappingURL=token-info.js.map