UNPKG

@reservoir0x/relay-kit-ui

Version:

Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.

80 lines 3.14 kB
import { RelayClient } from '@reservoir0x/relay-sdk'; import {} from '../types/index.js'; import { relativeTime } from './time.js'; export const extractFromChain = (transaction, client) => { const chainId = transaction?.data?.inTxs?.[0]?.chainId; return client?.chains.find((chain) => chain.id === chainId); }; export const extractToChain = (transaction, client) => { const chainId = transaction?.data?.outTxs?.[0]?.chainId; return client?.chains.find((chain) => chain.id === chainId); }; export const calculateFillTime = (transaction) => { let fillTime = '-'; let seconds = 0; if (transaction?.status !== 'pending' && transaction?.status !== 'waiting' && transaction?.status !== 'delayed') { const inTxTimestamps = transaction?.data?.inTxs?.map((tx) => tx.timestamp) ?? null; const txStartTimestamp = inTxTimestamps ? Math.min(...inTxTimestamps) : null; const outTxTimestamps = transaction?.data?.outTxs ?.filter((tx) => tx.timestamp) ?.map((tx) => tx.timestamp) ?? null; const txEndTimestamp = outTxTimestamps && outTxTimestamps.length > 0 ? Math.max(...outTxTimestamps) : null; if (txStartTimestamp && txEndTimestamp) { seconds = txEndTimestamp - txStartTimestamp; if (seconds > 60) { fillTime = `${relativeTime(txEndTimestamp * 1000, txStartTimestamp * 1000, true)}`; } else { fillTime = `${seconds}s`; } } } return { fillTime, seconds }; }; export const calculateExecutionTime = (startTime, transaction) => { let fillTime = '-'; let seconds = 0; if (transaction?.status !== 'pending' && transaction?.status !== 'waiting' && transaction?.status !== 'delayed') { const inTxTimestamps = transaction?.data?.inTxs?.map((tx) => tx.timestamp) ?? null; const outTxTimestamps = transaction?.data?.outTxs ?.filter((tx) => tx.timestamp) ?.map((tx) => tx.timestamp) ?? null; const txEndTimestamp = outTxTimestamps && outTxTimestamps.length > 0 ? Math.max(...outTxTimestamps) : null; if (startTime && txEndTimestamp) { seconds = txEndTimestamp - startTime; if (seconds > 60) { fillTime = `${relativeTime(txEndTimestamp * 1000, startTime * 1000, true)}`; } else { fillTime = `${seconds}s`; } } else if (!txEndTimestamp && inTxTimestamps && inTxTimestamps.length > 0) { fillTime = '-'; seconds = 0; } } return { fillTime, seconds }; }; export const extractDepositRequestId = (steps) => { if (!steps?.length) return null; // Find the first step that has a requestId return steps.find((step) => step.requestId)?.requestId || null; }; export const statusToText = { pending: 'Pending', failure: 'Failure', received: 'Received', success: 'Success', fallback: 'Refunded' }; //# sourceMappingURL=relayTransaction.js.map