test-ic-wallet-middleware-icrc
Version:
Ic middleware wallet ICRC protocol
69 lines (68 loc) • 3.81 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.GetIcrcAllowanceCacheHandler = void 0;
const common_1 = require("@ic-wallet-middleware/common");
const allowanceLocalCache_1 = require("../../../../repositories/cache/allowanceLocalCache/allowanceLocalCache");
const ledgerWrapper_1 = require("../../../../wrappers/icrc/ledgerWrapper/ledgerWrapper");
const principal_1 = require("@dfinity/principal");
require("reflect-metadata");
const typedi_1 = require("typedi");
let GetIcrcAllowanceCacheHandler = class GetIcrcAllowanceCacheHandler extends common_1.BaseCacheDataHandlerV2 {
identifierService;
allowanceCacheStorage;
constructor(logger, identifierService, allowanceCacheStorage) {
super(logger);
this.identifierService = identifierService;
this.allowanceCacheStorage = allowanceCacheStorage;
this.allowanceCacheStorage = allowanceCacheStorage;
}
getLoadForceType() {
return [common_1.LoadType.Full, common_1.LoadType.Quick];
}
// eslint-disable-next-line require-await
async getLocalCacheData(info) {
return this.allowanceCacheStorage.getAllowance(info.spenderPrincipal, info.ledgerAddress, info.subAccountId.toString(), info.spenderSubId.toString());
}
async getExternalData(info) {
const ledgerWrapper = ledgerWrapper_1.LedgerWrapper.create(this.identifierService.getAgent(), info.ledgerAddress);
const spenderPrincipal = principal_1.Principal.fromText(info.spenderPrincipal);
const ledgerAllowance = await ledgerWrapper.getAllowance(this.identifierService.getPrincipal(), spenderPrincipal, info.subAccountId, info.spenderSubId);
const result = {
spenderPrincipal: info.spenderPrincipal,
spenderSubId: info.spenderSubId.toString(),
ledgerAddress: info.ledgerAddress,
subAccountId: info.subAccountId.toString(),
amount: ledgerAllowance.allowance,
expiration: ledgerAllowance.expiration
};
return result;
}
updateField(info, data) {
let allowance = this.allowanceCacheStorage.getAllowance(info.spenderPrincipal, info.ledgerAddress, info.subAccountId.toString(), info.spenderSubId.toString());
allowance = data;
this.allowanceCacheStorage.updateOrAddAllowance(allowance);
}
getCacheDataError(info) {
return new common_1.CacheDataError("allowance unavailable", "Allowance Unavailable");
}
async validate(info) { }
};
exports.GetIcrcAllowanceCacheHandler = GetIcrcAllowanceCacheHandler;
exports.GetIcrcAllowanceCacheHandler = GetIcrcAllowanceCacheHandler = __decorate([
(0, typedi_1.Service)(),
__param(0, (0, typedi_1.Inject)("ILogger")),
__metadata("design:paramtypes", [Object, common_1.IdentifierService,
allowanceLocalCache_1.AllowanceLocalCache])
], GetIcrcAllowanceCacheHandler);