UNPKG

aftermath-ts-sdk

Version:
151 lines (150 loc) 6.55 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuiFren = void 0; const caller_1 = require("../../general/utils/caller"); const dayjs_1 = __importDefault(require("dayjs")); const __1 = require(".."); class SuiFren extends caller_1.Caller { // ========================================================================= // Constructor // ========================================================================= constructor(suiFren, config, isStaked = false, isOwned = false, Provider) { super(config, "sui-frens"); this.suiFren = suiFren; this.isStaked = isStaked; this.isOwned = isOwned; this.Provider = Provider; // ========================================================================= // Private Helpers // ========================================================================= this.useProvider = () => { var _a; const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.SuiFrens(); if (!provider) throw new Error("missing AftermathApi Provider"); return provider; }; } // ========================================================================= // Getters // ========================================================================= suiFrenType() { return __1.Coin.getInnerCoinType(this.suiFren.objectType); } properties() { return { Skin: this.suiFren.attributes.skin, Ears: this.suiFren.attributes.ears, Expression: this.suiFren.attributes.expression, "Main Color": this.suiFren.attributes.main, "Secondary Color": this.suiFren.attributes.secondary, "Birth Location": this.suiFren.birthLocation, Birthday: (0, dayjs_1.default)(this.suiFren.birthdate).format("MMMM D, YYYY"), Cohort: this.suiFren.cohort.toString(), Generation: this.suiFren.generation.toString(), // Genes: this.suiFren.genes.toString(), }; } dynamicFields() { return Object.assign(Object.assign({}, (this.suiFren.mixLimit ? { "Mixes Remaining": this.suiFren.mixLimit.toString(), } : {})), (this.suiFren.lastEpochMixed ? { "Last Epoch Mixed": this.suiFren.lastEpochMixed.toString(), } : {})); } displayNumber() { return this.suiFren.objectId.slice(-5, -1).toUpperCase(); } clone() { return new SuiFren(this.suiFren, this.config, this.isStaked, this.isOwned); } // public asNft(): Nft { // return { // info: { // objectId: this.suiFren.objectId, // objectType: this.suiFren.objectType, // }, // display: { // suggested: { // name: "SuiFren", // ...this.suiFren.display, // }, // other: { // Skin: this.suiFren.attributes.skin, // Ears: this.suiFren.attributes.ears, // Expression: this.suiFren.attributes.expression, // "Main Color": this.suiFren.attributes.main, // "Secondary Color": this.suiFren.attributes.secondary, // "Birth Location": this.suiFren.birthLocation, // Birthday: dayjs(this.suiFren.birthdate).format( // "MMMM D, YYYY" // ), // Cohort: this.suiFren.cohort.toString(), // Generation: this.suiFren.generation.toString(), // ...(this.suiFren.mixLimit // ? { // "Mixes Remaining": // this.suiFren.mixLimit.toString(), // } // : {}), // ...(this.suiFren.lastEpochMixed // ? { // "Last Epoch Mixed": // this.suiFren.lastEpochMixed.toString(), // } // : {}), // // Genes: this.suiFren.genes.toString(), // }, // }, // }; // } // ========================================================================= // Objects // ========================================================================= getAccessories() { return __awaiter(this, void 0, void 0, function* () { return this.fetchApi("accessories", { suiFrenId: this.suiFren.objectId, }); }); } // ========================================================================= // Transactions // ========================================================================= getStakeTransaction(inputs) { return __awaiter(this, void 0, void 0, function* () { if (this.isStaked) throw new Error("unable to stake already staked suiFren"); return this.useProvider().fetchStakeTx(Object.assign(Object.assign({}, inputs), { suiFrenType: this.suiFrenType(), suiFrenId: this.suiFren.objectId })); }); } getAddAccessoryTransaction(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.useProvider().fetchBuildAddAccessoryTx(Object.assign(Object.assign({}, inputs), { isOwned: this.isOwned, suiFrenType: this.suiFrenType(), suiFrenId: this.suiFren.objectId })); }); } getRemoveAccessoryTransaction(inputs) { return __awaiter(this, void 0, void 0, function* () { if (!this.isOwned) throw new Error("unable to remove accessory from suiFren that is not owned by caller"); return this.useProvider().fetchBuildRemoveAccessoryTx(Object.assign(Object.assign({}, inputs), { suiFrenType: this.suiFrenType(), suiFrenId: this.suiFren.objectId })); }); } } exports.SuiFren = SuiFren;