UNPKG

test-ic-wallet-middleware-icrc

Version:
39 lines (38 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IcrcLedgerServiceWrapper = void 0; const agent_1 = require("@dfinity/agent"); const strategy_1 = require("@dfinity/agent/lib/cjs/polling/strategy"); const icrcLedgerCandid_did_1 = require("../../../candid/icrcLedger/icrcLedgerCandid.did"); const FIVE_MINUTES_IN_MSEC = 5 * 60 * 1000; const DELAY = 250; class IcrcLedgerServiceWrapper { logger; icrcLedgerService; constructor(logger, icrcLedgerService) { this.logger = logger; this.icrcLedgerService = icrcLedgerService; } static create(params, logger) { const icrcLedgerService = agent_1.Actor.createActor(icrcLedgerCandid_did_1.idlFactory, { agent: params.agent, canisterId: params.ledgerAddress, pollingStrategyFactory: this.pollingStrategy, }); return new IcrcLedgerServiceWrapper(logger, icrcLedgerService); } static pollingStrategy() { return (0, strategy_1.chain)((0, strategy_1.conditionalDelay)((0, strategy_1.once)(), DELAY), (0, strategy_1.backoff)(0, 0), (0, strategy_1.timeout)(FIVE_MINUTES_IN_MSEC)); } async getICRCSupportedStandards() { try { const response = await this.icrcLedgerService.icrc1_supported_standards(); return response.map((standard) => standard.name); } catch (error) { this.logger.logError(error, "IcrcLedgerServiceWrapper error"); return []; } } } exports.IcrcLedgerServiceWrapper = IcrcLedgerServiceWrapper;