@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
74 lines (73 loc) • 3.26 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); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HplMintCacheDataHandler = void 0;
const hplWrappers_1 = require("../../../hplWrappers");
const common_1 = require("@ic-wallet-kit/common");
require("reflect-metadata");
const typedi_1 = require("typedi");
let HplMintCacheDataHandler = class HplMintCacheDataHandler extends common_1.BaseCacheDataHandler {
identifierService;
getLoadForceType() {
return [common_1.LoadType.Full];
}
hplMintCacheRepository;
constructor(logger, identifierService, hplMintCacheRepository) {
super(logger);
this.identifierService = identifierService;
this.hplMintCacheRepository = hplMintCacheRepository;
}
async validate(info) { }
// eslint-disable-next-line require-await
async getLocalCacheData(info) {
const hplDictionary = this.hplMintCacheRepository.getHplMintByCanisterId(info.canisterId);
return hplDictionary;
}
async getExternalData(info) {
const agent = await this.identifierService.getAnonymousAgent();
const hplMintActorWrapper = hplWrappers_1.HplMintActorWrapper.create(agent, info.canisterId);
let result = {
canisterId: info.canisterId,
isMinter: false
};
try {
result.isMinter = await hplMintActorWrapper.isHplMinter();
}
catch (e) {
this.logger.logError(e);
}
return result;
}
updateField(info, data) {
let hplMint = this.hplMintCacheRepository.getHplMintByCanisterId(info.canisterId);
if (!hplMint) {
hplMint = {
canisterId: info.canisterId,
isMinter: false
};
}
hplMint.isMinter = data.isMinter;
this.hplMintCacheRepository.setHplMint(hplMint);
}
getCacheDataError(info) {
return new common_1.CacheDataError("minter.unavailable", "Minter unavailable");
}
};
exports.HplMintCacheDataHandler = HplMintCacheDataHandler;
exports.HplMintCacheDataHandler = HplMintCacheDataHandler = __decorate([
(0, typedi_1.Service)(),
__param(0, (0, typedi_1.Inject)("ILogger")),
__param(2, (0, typedi_1.Inject)("IHplMintCacheRepository")),
__metadata("design:paramtypes", [Object, common_1.IdentifierService, Object])
], HplMintCacheDataHandler);