UNPKG

rubic-sdk-next

Version:
57 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDepositStatus = getDepositStatus; const errors_1 = require("../../../../../../../common/errors"); const cross_chain_trade_type_1 = require("../../../../models/cross-chain-trade-type"); const changelly_api_service_1 = require("../../../changelly-provider/services/changelly-api-service"); const changenow_cross_chain_api_service_1 = require("../../../changenow-provider/services/changenow-cross-chain-api-service"); const simple_swap_api_service_1 = require("../../../simple-swap-provider/services/simple-swap-api-service"); const cross_chain_deposit_statuses_1 = require("../models/cross-chain-deposit-statuses"); const injector_1 = require("../../../../../../../core/injector/injector"); const getDepositStatusFnMap = { [cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.CHANGENOW]: changenow_cross_chain_api_service_1.ChangeNowCrossChainApiService.getTxStatus, [cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.SIMPLE_SWAP]: simple_swap_api_service_1.SimpleSwapApiService.getTxStatus, [cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.CHANGELLY]: changelly_api_service_1.ChangellyApiService.getTxStatus, [cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.EXOLIX]: getExolixStatus }; function getDepositStatus(id, tradeType) { const getDepositStatusFn = getDepositStatusFnMap[tradeType]; if (!getDepositStatusFn) { throw new errors_1.RubicSdkError('Unsupported cross chain provider'); } return getDepositStatusFn(id); } async function getExolixStatus(id) { try { const { status, hashOut } = await injector_1.Injector.httpClient.get(`https://exolix.com/api/v2/transactions/${id}`); if (status === 'success' || status === 'refunded') { return { status: cross_chain_deposit_statuses_1.CROSS_CHAIN_DEPOSIT_STATUS.FINISHED, dstHash: hashOut.hash }; } if (status === 'overdue') { return { status: cross_chain_deposit_statuses_1.CROSS_CHAIN_DEPOSIT_STATUS.FAILED, dstHash: null }; } if (status === 'wait') { return { status: cross_chain_deposit_statuses_1.CROSS_CHAIN_DEPOSIT_STATUS.WAITING, dstHash: null }; } return { status: status, dstHash: hashOut?.hash || null }; } catch { return { status: cross_chain_deposit_statuses_1.CROSS_CHAIN_DEPOSIT_STATUS.WAITING, dstHash: null }; } } //# sourceMappingURL=get-deposit-status.js.map