@kippurocks/libticketto-papi
Version:
A Kippu implementation of The Ticketto Protocol with Polkadot-API
83 lines (82 loc) • 3.02 kB
JavaScript
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); }
};
import { inject, injectable } from "inversify";
import { TOKEN, } from "./types.js";
import { AttendancePolicyType, } from "@ticketto/types";
let TickettoModelConverter = class TickettoModelConverter {
api;
constructor(api) {
this.api = api;
}
intoTickettoAttendancePolicy(attendancePolicy) {
switch (attendancePolicy.type) {
case "Single": {
return {
type: AttendancePolicyType.Single,
};
}
case "Multiple": {
return {
type: AttendancePolicyType.Multiple,
max: attendancePolicy.value.max,
until: attendancePolicy.value.maybe_until,
};
}
case "Unlimited": {
return {
type: 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,
};
}
};
TickettoModelConverter = __decorate([
injectable(),
__param(0, inject(TOKEN.KREIVO_API)),
__metadata("design:paramtypes", [Object])
], TickettoModelConverter);
export { TickettoModelConverter };