UNPKG

test-ic-wallet-middleware-icrc

Version:
88 lines (87 loc) 4.78 kB
"use strict"; 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.GetListTransactionHandler = void 0; const common_1 = require("@ic-wallet-middleware/common"); const assetRepository_1 = require("../../../repositories/persists/assetRepository/assetRepository"); const transactionRepository_1 = require("../../../repositories/persists/transactionRepository/transactionRepository"); const types_1 = require("../../../types"); const typedi_1 = require("typedi"); let GetListTransactionHandler = class GetListTransactionHandler extends common_1.BaseHandler { configuration; transactionRepository; assetRepository; constructor(logger, configuration, transactionRepository, assetRepository) { super(logger); this.configuration = configuration; this.transactionRepository = transactionRepository; this.assetRepository = assetRepository; } async validate(form) { if (form.pageInfo.nextPageKey == common_1.PageResultEmptyKey) { throw new common_1.ValidationError("get.list.transaction.nextPageKey.lastIndex", "nextPageKey", "It was last page. Please check PageResult.hasNext on previous request. Please make sure that hasNext is true."); } if (!form.ledgerAddress) { throw new common_1.ValidationError("get.list.transaction.ledgerAddress.is.required", "ledgerAddress", "Field ledgerAddress is required"); } return Promise.resolve(); } async process(form) { const asset = await this.assetRepository.getAssetOrDefault(form.ledgerAddress); if (!asset) { throw new common_1.ValidationError("get.list.transaction.asset.not.found", "ledgerAddress", "Asset Not Found"); } const subAccountIds = form.subAccountId ? [form.subAccountId] : asset.subAccounts.map((sa) => types_1.SubAccountId.parseFromString(sa.subAccountId)); const assetInfo = { indexAsset: asset.indexAddress, subAccountIds: subAccountIds, symbol: asset.tokenSymbol, pageInfo: form.pageInfo }; let result; switch (asset.tokenSymbol) { case "ICP": result = await this.transactionRepository.getIcpListTransaction(assetInfo, { url: this.configuration.icpUrl, //"https://rosetta-api.internetcomputer.org/search/transactions", blockchain: this.configuration.icpBlockchain, //"Internet Computer", network: this.configuration.icpNetwork, // "00000000000000020101", canisterId: asset.ledgerAddress }); break; case "OGYL": result = await this.transactionRepository.getIcpListTransaction(assetInfo, { url: this.configuration.ogyUrl, // "https://rosetta-ogy.origyn.ch/search/transactions", blockchain: this.configuration.ogyBlockchain, //"ORIGYN Foundation", network: this.configuration.ogyNetwork, //`"00000000012000b90101", canisterId: asset.ledgerAddress }); break; default: result = await this.transactionRepository.getIcrcListTransactionByAsset(assetInfo); break; } return result; } }; exports.GetListTransactionHandler = GetListTransactionHandler; exports.GetListTransactionHandler = GetListTransactionHandler = __decorate([ (0, typedi_1.Service)(), __param(0, (0, typedi_1.Inject)("ILogger")), __param(1, (0, typedi_1.Inject)("TransactionConfiguration")), __param(3, (0, typedi_1.Inject)("AssetRepository")), __metadata("design:paramtypes", [Object, Object, transactionRepository_1.TransactionRepository, assetRepository_1.AssetRepository]) ], GetListTransactionHandler);