import { Button, Col, Row, Timeline, Typography } from 'antd'
import BigNumber from 'bignumber.js'
import { useMemo } from 'react'
import { formatTokenAmount, parseSecondsAsTime } from '../../services/utils'
import { getChainById, Route as RouteType, Step } from '../../types'
import { getToolAvatarPrioritizeLifi } from '../Avatars/Avatars'
interface RouteProps {
route: RouteType
selected: boolean
onSelect: Function
}
const RouteCard = ({ route, selected, onSelect }: RouteProps) => {
const tag: string | undefined = useMemo(() => {
if (!route.tags || !route.tags.length) {
return 'GENERAL'
} else if (route.tags.includes('RECOMMENDED')) {
return 'RECOMMENDED'
} else if (route.tags[0] === 'SAFEST') {
return 'SAFE'
} else if (route.tags[0] === 'CHEAPEST') {
return 'CHEAP'
} else if (route.tags[0] === 'FASTEST') {
return 'FAST'
} else {
return route.tags[0]
}
}, [route])
const parseStepShort = (step: Step) => {
switch (step.type) {
case 'swap':
return (
<>
Swap to {formatTokenAmount(step.action.toToken, step.estimate.toAmount)} via{' '}
{step.toolDetails.name}
>
)
case 'cross':
return (
<>
Transfer to {formatTokenAmount(step.action.toToken, step.estimate.toAmount)} via{' '}
{step.toolDetails.name}
>
)
default:
// eslint-disable-next-line no-console
console.error('invalid short step')
return <>>
}
}
const parseStep = (step: Step) => {
const { action, estimate } = step
switch (step.type) {
case 'swap':
return {
title: 'Swap Tokens',
description: `${formatTokenAmount(
action.fromToken,
estimate.fromAmount,
)} for ${formatTokenAmount(action.toToken, estimate.toAmount)} via ${
step.toolDetails.name
}`,
}
case 'cross':
return {
title: 'Cross Chains',
description: `${getChainById(action.fromChainId).name}: ${formatTokenAmount(
action.fromToken,
estimate.fromAmount,
)} to ${getChainById(action.toChainId).name}: ${formatTokenAmount(
action.toToken,
estimate.toAmount,
)} via ${step.toolDetails.name}`,
}
case 'lifi':
return {
title: 'LI.FI Contract',
description: (
<>
Single transaction including: