UNPKG

@kippurocks/libticketto-papi

Version:

A Kippu implementation of The Ticketto Protocol with Polkadot-API

86 lines (85 loc) 3.25 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TickettoModelConverter = void 0; const inversify_1 = require("inversify"); const types_ts_1 = require("./types.js"); const types_1 = require("@ticketto/types"); let TickettoModelConverter = class TickettoModelConverter { api; constructor(api) { this.api = api; } intoTickettoAttendancePolicy(attendancePolicy) { switch (attendancePolicy.type) { case "Single": { return { type: types_1.AttendancePolicyType.Single, }; } case "Multiple": { return { type: types_1.AttendancePolicyType.Multiple, max: attendancePolicy.value.max, until: attendancePolicy.value.maybe_until, }; } case "Unlimited": { return { type: types_1.AttendancePolicyType.Unlimited, until: attendancePolicy.value.maybe_until, }; } } } intoTickettoEventState(state) { switch (state) { case "Created": return 0; case "Sales": return 1; case "Ongoing": return 2; case "Finished": return 3; } } assetIdOf(id) { switch (id.type) { case "Here": return id.value; case "Sibling": return id.value.index; case "External": return id.value.child?.index ?? 0; } } async assetMetadata(id) { const assetMetadata = await this.api.query.Assets.Metadata.getValue(id); if (!assetMetadata) { throw new Error("AssetNotFound"); } return { id: this.assetIdOf(id), code: assetMetadata.symbol.asText(), decimals: assetMetadata.decimals, }; } }; exports.TickettoModelConverter = TickettoModelConverter; exports.TickettoModelConverter = TickettoModelConverter = __decorate([ (0, inversify_1.injectable)(), __param(0, (0, inversify_1.inject)(types_ts_1.TOKEN.KREIVO_API)), __metadata("design:paramtypes", [Object]) ], TickettoModelConverter);