@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
93 lines (92 loc) • 4.33 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.GetHplContactListHandler = void 0;
const principal_1 = require("@dfinity/principal");
const internalHandlers_1 = require("../../../internalHandlers");
const hplContactRepository_1 = require("../../../repositories/persists/hplContactRepository/hplContactRepository");
const common_1 = require("@ic-wallet-kit/common");
require("reflect-metadata");
const typedi_1 = require("typedi");
let GetHplContactListHandler = class GetHplContactListHandler extends common_1.BaseHandler {
getHplContactRemotesHandler;
hplContactRepository;
constructor(logger, getHplContactRemotesHandler, hplContactRepository) {
super(logger);
this.getHplContactRemotesHandler = getHplContactRemotesHandler;
this.hplContactRepository = hplContactRepository;
}
async validate(form) {
}
async process(form) {
const contacts = [];
const contactsData = await this.hplContactRepository.getContacts();
for (let contactData of contactsData) {
const contactRemotesResult = await this.getHplContactRemotesHandler.handle({
principal: principal_1.Principal.fromText(contactData.principal),
loadType: form.loadType
});
const contact = {
name: contactData.name,
principal: principal_1.Principal.fromText(contactData.principal),
remotes: [],
availableRemotes: contactRemotesResult.data?.map((r) => {
return {
remoteAccountId: r.remoteAccountId,
assetId: r.assetId,
assetName: r.assetName,
assetSymbol: r.assetSymbol,
assetLogo: r.assetLogo,
code: r.code,
amount: r.amount,
expired: r.expired
};
}) ?? []
};
for (let remoteData of contactData.remotes) {
let contactRemote = contactRemotesResult?.data
?.find((r) => r.remoteAccountId == remoteData.remoteId);
if (contactRemote) {
contactRemote.name = remoteData.name;
}
else {
contactRemote = {
remoteAccountId: remoteData.remoteId,
name: remoteData.name,
amount: "",
code: "",
expired: 0,
assetId: "",
assetName: "",
assetSymbol: "",
assetLogo: ""
};
}
contact.remotes.push(contactRemote);
}
contacts.push(contact);
}
return {
contacts
};
}
};
exports.GetHplContactListHandler = GetHplContactListHandler;
exports.GetHplContactListHandler = GetHplContactListHandler = __decorate([
(0, typedi_1.Service)(),
__param(0, (0, typedi_1.Inject)("ILogger")),
__param(2, (0, typedi_1.Inject)("HplContactRepository")),
__metadata("design:paramtypes", [Object, internalHandlers_1.GetHplContactRemotesHandler,
hplContactRepository_1.HplContactRepository])
], GetHplContactListHandler);