UNPKG

@reservoir0x/relay-kit-ui

Version:

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

87 lines 3.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStepActionText = exports.formatTransactionSteps = void 0; const formatTransactionSteps = ({ steps, fromToken, fromChain, toChain, operation }) => { if (!steps || steps.length === 0) return { formattedSteps: [], status: undefined }; const result = []; const executableSteps = steps?.filter((step) => step.items && step.items.length > 0); const lastStep = executableSteps[executableSteps.length - 1]; const lastStepItem = lastStep?.items?.[0]; const status = lastStepItem?.progressState === 'validating_delayed' ? 'delayed' : undefined; let activeStepIndex = executableSteps.findIndex((step) => step.items?.some((item) => item.status === 'incomplete')); if (activeStepIndex === -1) { activeStepIndex = executableSteps.length > 0 ? 0 : -1; } executableSteps.forEach((step, index) => { const isLastExecutableStep = index === executableSteps.length - 1; const firstItem = step.items?.[0]; const progressState = firstItem?.progressState; let isCompleted = step.items?.every((item) => item.status === 'complete') || false; if (isLastExecutableStep && !isCompleted && progressState) { if (step.kind === 'transaction' && progressState !== 'confirming') { isCompleted = true; } else if (step.kind === 'signature' && progressState !== 'signing') { isCompleted = true; } } const isActive = index === activeStepIndex && !isCompleted; const txHashes = step.items?.flatMap((item) => [ ...(item.txHashes || []), ...(item.internalTxHashes || []) ]) || []; const isApproveStep = step.id === 'approve' || step.id === 'approval'; result.push({ id: step.id, action: getStepActionText(step.id, operation), isActive, isCompleted, progressState, txHashes, isWalletAction: true, chainId: fromToken?.chainId, isApproveStep }); }); const allStepsComplete = result.every((step) => step.isCompleted); const isSameChain = fromChain?.id === toChain?.id; if (isSameChain) { result.push({ id: 'chain-confirm', action: `Relay processes your transaction on ${fromChain?.displayName}`, isActive: allStepsComplete, isCompleted: false, isWalletAction: false, chainId: fromChain?.id }); } else { result.push({ id: 'relay-fill', action: `Relay fills your order on ${toChain?.displayName}`, isActive: allStepsComplete, isCompleted: false, isWalletAction: false, chainId: toChain?.id }); } return { formattedSteps: result, status }; }; exports.formatTransactionSteps = formatTransactionSteps; function getStepActionText(stepId, operation) { if (stepId === 'approve' || stepId === 'approval') { return 'Approve token'; } if (stepId === 'authorize' || stepId === 'authorize1' || stepId === 'authorize2') { return 'Sign authorization'; } if (stepId === 'swap' || stepId === 'deposit' || stepId === 'send') { return `Confirm ${operation}`; } return 'Confirm transaction'; } exports.getStepActionText = getStepActionText; //# sourceMappingURL=steps.js.map