@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
72 lines (71 loc) • 3.69 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.GetHplAccountListHandler = void 0;
const internalHandlers_1 = require("../../../internalHandlers");
const repositories_1 = require("../../../repositories");
const hplAccountRepository_1 = require("../../../repositories/persists/hplAccountRepository/hplAccountRepository");
const common_1 = require("@ic-wallet-kit/common");
require("reflect-metadata");
const typedi_1 = require("typedi");
let GetHplAccountListHandler = class GetHplAccountListHandler extends common_1.BaseHandler {
loadHplAccountHandler;
hplAccountRepository;
hplVirtualAccountRepository;
constructor(logger, loadHplAccountHandler, hplAccountRepository, hplVirtualAccountRepository) {
super(logger);
this.loadHplAccountHandler = loadHplAccountHandler;
this.hplAccountRepository = hplAccountRepository;
this.hplVirtualAccountRepository = hplVirtualAccountRepository;
}
async validate(form) {
}
async process(form) {
const cacheData = await this.loadHplAccountHandler.process({
loadType: form.loadType
});
const virtualAccountList = await this.hplVirtualAccountRepository.getVirtualAccounts();
const accountData = await this.hplAccountRepository.getAccounts();
for (let index = 0; index < cacheData.accounts.length; index++) {
const account = cacheData.accounts[index];
let findSubAccount = accountData.find((a) => a.id === account.accountId.toString());
if (!findSubAccount) {
findSubAccount = {
id: account.accountId.toString(),
name: account.name,
ftId: account.ft.toString()
};
await this.hplAccountRepository.addAccount(findSubAccount);
}
account.name = findSubAccount.name;
for (let va of account.virtualAccounts) {
const item = virtualAccountList.find((v) => v.id === va.virtualAccountId.toString());
va.name = item?.name ?? "";
}
}
return {
accounts: cacheData.accounts
};
}
};
exports.GetHplAccountListHandler = GetHplAccountListHandler;
exports.GetHplAccountListHandler = GetHplAccountListHandler = __decorate([
(0, typedi_1.Service)(),
__param(0, (0, typedi_1.Inject)("ILogger")),
__param(2, (0, typedi_1.Inject)("HplAccountRepository")),
__param(3, (0, typedi_1.Inject)("HplVirtualAccountRepository")),
__metadata("design:paramtypes", [Object, internalHandlers_1.LoadHplAccountsHandler,
hplAccountRepository_1.HplAccountRepository,
repositories_1.HplVirtualAccountRepository])
], GetHplAccountListHandler);