@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
97 lines (96 loc) • 4.59 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.HplVirtualAccountCacheDataHandler = void 0;
const hplWrappers_1 = require("../../../hplWrappers");
const canisterService_1 = require("../../../service/canisterService");
const common_1 = require("@ic-wallet-kit/common");
require("reflect-metadata");
const typedi_1 = require("typedi");
let HplVirtualAccountCacheDataHandler = class HplVirtualAccountCacheDataHandler extends common_1.BaseCacheDataHandler {
identifierService;
canisterService;
getLoadForceType() {
return [common_1.LoadType.Full];
}
hplDataCacheRepository;
constructor(logger, identifierService, hplDataCacheRepository, canisterService) {
super(logger);
this.identifierService = identifierService;
this.canisterService = canisterService;
this.hplDataCacheRepository = hplDataCacheRepository;
}
async validate(info) { }
// eslint-disable-next-line require-await
async getLocalCacheData(info) {
const hplAsset = this.hplDataCacheRepository.getHplDataByCanisterId(this.canisterService.getLedgerCanisterId());
if (hplAsset && hplAsset.virtualAccounts) {
return hplAsset.virtualAccounts;
}
return undefined;
}
async getExternalData(info) {
const ingressActorWrapper = hplWrappers_1.IngressActorWrapper.create(this.identifierService.getAgent(), this.canisterService.getLedgerCanisterId(), this.logger);
const result = {
virtualAccountLastId: BigInt(0),
virtualAccounts: []
};
try {
result.virtualAccountLastId = await ingressActorWrapper.getVirtualAccounts();
}
catch (e) {
throw new common_1.CacheDataError("virtualAccount.getVirtualAccounts.unavailable", "getVirtualAccounts canister method unavailable");
}
if (result.virtualAccountLastId !== BigInt(0)) {
const virtualAccountInfo = await ingressActorWrapper.getAllVirtualAccountInfo(result.virtualAccountLastId);
result.virtualAccounts = virtualAccountInfo;
}
return result;
}
updateField(info, data) {
let hplData = this.hplDataCacheRepository.getHplDataByCanisterId(this.canisterService.getLedgerCanisterId());
if (!hplData) {
hplData = {
accounts: {
accountLastId: BigInt(0),
accounts: []
},
virtualAccounts: {
virtualAccountLastId: BigInt(0),
virtualAccounts: []
},
ftAssets: {
ftAssetLastId: BigInt(0),
ftAssets: []
},
remotes: []
};
}
hplData.virtualAccounts = {
virtualAccountLastId: data.virtualAccountLastId,
virtualAccounts: data.virtualAccounts
};
this.hplDataCacheRepository.setHplData(this.canisterService.getLedgerCanisterId(), hplData);
}
getCacheDataError(info) {
return new common_1.CacheDataError("virtualAccount.unavailable", "Virtual Account unavailable");
}
};
exports.HplVirtualAccountCacheDataHandler = HplVirtualAccountCacheDataHandler;
exports.HplVirtualAccountCacheDataHandler = HplVirtualAccountCacheDataHandler = __decorate([
(0, typedi_1.Service)(),
__param(0, (0, typedi_1.Inject)("ILogger")),
__param(2, (0, typedi_1.Inject)("IHplDataCacheRepository")),
__metadata("design:paramtypes", [Object, common_1.IdentifierService, Object, canisterService_1.CanisterService])
], HplVirtualAccountCacheDataHandler);