@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
97 lines (96 loc) • 5.29 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.LoadHplAssetHandler = void 0;
const cacheDataHandlers_1 = require("../../internalHandlers/cacheDataHandlers");
const common_1 = require("@ic-wallet-kit/common");
require("reflect-metadata");
const typedi_1 = require("typedi");
let LoadHplAssetHandler = class LoadHplAssetHandler extends common_1.BaseHandler {
hplFtAssetCacheDataHandler;
hplAccountCacheDataHandler;
hplVirtualAccountCacheDataHandler;
hplFtSuppliesStateCacheDataHandler;
hplAdminStateCacheDataHandler;
hplDictionaryCacheDataHandler;
constructor(logger, hplFtAssetCacheDataHandler, hplAccountCacheDataHandler, hplVirtualAccountCacheDataHandler, hplFtSuppliesStateCacheDataHandler, hplAdminStateCacheDataHandler, hplDictionaryCacheDataHandler) {
super(logger);
this.hplFtAssetCacheDataHandler = hplFtAssetCacheDataHandler;
this.hplAccountCacheDataHandler = hplAccountCacheDataHandler;
this.hplVirtualAccountCacheDataHandler = hplVirtualAccountCacheDataHandler;
this.hplFtSuppliesStateCacheDataHandler = hplFtSuppliesStateCacheDataHandler;
this.hplAdminStateCacheDataHandler = hplAdminStateCacheDataHandler;
this.hplDictionaryCacheDataHandler = hplDictionaryCacheDataHandler;
}
async validate(form) { }
async process(form) {
const hplAssetInfo = {
loadType: form.loadType
};
const ftAssetResult = await this.hplFtAssetCacheDataHandler.process(hplAssetInfo);
const accountResult = await this.hplAccountCacheDataHandler.process(hplAssetInfo);
const virtualAccountResult = await this.hplVirtualAccountCacheDataHandler.process(hplAssetInfo);
const hplStateCacheDataInfo = {
accountCount: BigInt(0),
ftAssetCount: ftAssetResult.ftAssetLastId,
virtualAccountCount: BigInt(0),
remoteAccounts: [],
loadType: form.loadType
};
const [stateResult, adminStateResult] = await Promise.all([
this.hplFtSuppliesStateCacheDataHandler.process(hplStateCacheDataInfo),
this.hplAdminStateCacheDataHandler.process(hplStateCacheDataInfo),
]);
const dictFT = await this.hplDictionaryCacheDataHandler.process({ loadType: form.loadType });
const ftAssets = this.getFtsFormate(stateResult, ftAssetResult.ftAssets, dictFT.assetsDictionary, adminStateResult.accounts, accountResult.accounts.length, virtualAccountResult.virtualAccounts.length);
const result = {
ftAssets: ftAssets,
};
return result;
}
getFtsFormate(ftSupplies, ftsData, dictFT, adminAccountState, accountCount, virtualAccountCount) {
const auxFT = [];
ftSupplies.map((asst) => {
const ftData = ftsData.find((ft) => ft.assetId === asst.assetId);
const ftDict = dictFT.find((ft) => ft.assetId === asst.assetId);
const ftAdmin = adminAccountState.find((ft) => ft.accountId === asst.assetId);
auxFT.push({
id: asst.assetId,
assetName: ftDict ? ftDict.name : "",
assetSymbol: ftDict ? ftDict.symbol : "",
decimal: ftData ? Number(ftData.ftAssetInfo.decimals) : 0,
description: ftData ? ftData.ftAssetInfo.description : "",
logo: ftDict ? ftDict.logo : "",
controller: ftData ? ftData.ftAssetInfo.controller : "",
supply: asst.ftSupply,
ledgerBalance: ftAdmin ? ftAdmin.accountState.ft : BigInt(0),
accountCount: accountCount,
virtualAccountCount: virtualAccountCount
});
});
return auxFT;
}
;
};
exports.LoadHplAssetHandler = LoadHplAssetHandler;
exports.LoadHplAssetHandler = LoadHplAssetHandler = __decorate([
(0, typedi_1.Service)(),
__param(0, (0, typedi_1.Inject)("ILogger")),
__metadata("design:paramtypes", [Object, cacheDataHandlers_1.HplFtAssetCacheDataHandler,
cacheDataHandlers_1.HplAccountCacheDataHandler,
cacheDataHandlers_1.HplVirtualAccountCacheDataHandler,
cacheDataHandlers_1.HplFtSuppliesStateCacheDataHandler,
cacheDataHandlers_1.HplAdminStateCacheDataHandler,
cacheDataHandlers_1.HplDictionaryCacheDataHandler])
], LoadHplAssetHandler);