UNPKG

@getclave/lifi-sdk

Version:

LI.FI Any-to-Any Cross-Chain-Swap SDK

43 lines (42 loc) 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.waitForRelayedTransactionReceipt = void 0; const constants_1 = require("../../errors/constants"); const errors_1 = require("../../errors/errors"); const api_1 = require("../../services/api"); const waitForResult_1 = require("../../utils/waitForResult"); const waitForRelayedTransactionReceipt = async (taskId, step) => { return (0, waitForResult_1.waitForResult)(async () => { const result = await (0, api_1.getRelayedTransactionStatus)({ taskId, fromChain: step.action.fromChainId, toChain: step.action.toChainId, ...(step.tool !== 'custom' && { bridge: step.tool }), }).catch((e) => { if (process.env.NODE_ENV === 'development') { console.debug('Fetching status from relayer failed.', e); } return undefined; }); switch (result?.status) { case 'PENDING': return undefined; case 'DONE': { const sending = result ?.transactionStatus?.sending; return { status: 'success', gasUsed: sending?.gasUsed, transactionHash: result?.metadata.txHash, }; } case 'FAILED': throw new errors_1.TransactionError(constants_1.LiFiErrorCode.TransactionFailed, 'Transaction was reverted.'); default: throw new errors_1.TransactionError(constants_1.LiFiErrorCode.TransactionNotFound, 'Transaction not found.'); } }, 5000, 3, (_, error) => { return !(error instanceof errors_1.TransactionError); }); }; exports.waitForRelayedTransactionReceipt = waitForRelayedTransactionReceipt;