2019-05-30 23:42:25 +03:00
|
|
|
import React from 'react'
|
|
|
|
import styled, { keyframes } from 'styled-components'
|
2019-11-26 01:56:31 +03:00
|
|
|
import { Check } from 'react-feather'
|
2019-05-30 23:42:25 +03:00
|
|
|
|
2019-11-26 01:56:31 +03:00
|
|
|
import { useWeb3React } from '../../hooks'
|
2019-05-30 23:42:25 +03:00
|
|
|
import { getEtherscanLink } from '../../utils'
|
|
|
|
import { Link, Spinner } from '../../theme'
|
2019-11-26 01:56:31 +03:00
|
|
|
import Copy from './Copy'
|
2019-05-30 23:42:25 +03:00
|
|
|
import Circle from '../../assets/images/circle.svg'
|
|
|
|
|
|
|
|
import { transparentize } from 'polished'
|
|
|
|
|
|
|
|
const TransactionStatusWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
min-width: 12px;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
`
|
|
|
|
|
|
|
|
const TransactionWrapper = styled.div`
|
|
|
|
${({ theme }) => theme.flexRowNoWrap}
|
|
|
|
justify-content: space-between;
|
|
|
|
width: 100%;
|
|
|
|
margin-top: 0.75rem;
|
|
|
|
a {
|
|
|
|
/* flex: 1 1 auto; */
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
min-width: 0;
|
|
|
|
max-width: 250px;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const TransactionStatusText = styled.span`
|
|
|
|
margin-left: 0.5rem;
|
|
|
|
`
|
|
|
|
|
|
|
|
const rotate = keyframes`
|
|
|
|
from {
|
|
|
|
transform: rotate(0deg);
|
|
|
|
}
|
|
|
|
to {
|
|
|
|
transform: rotate(360deg);
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const TransactionState = styled.div`
|
|
|
|
display: flex;
|
|
|
|
background-color: ${({ pending, theme }) =>
|
|
|
|
pending ? transparentize(0.95, theme.royalBlue) : transparentize(0.95, theme.connectedGreen)};
|
|
|
|
border-radius: 1.5rem;
|
|
|
|
padding: 0.5rem 0.75rem;
|
|
|
|
font-weight: 500;
|
|
|
|
font-size: 0.75rem;
|
|
|
|
border: 1px solid;
|
|
|
|
border-color: ${({ pending, theme }) =>
|
|
|
|
pending ? transparentize(0.75, theme.royalBlue) : transparentize(0.75, theme.connectedGreen)};
|
|
|
|
|
|
|
|
#pending {
|
|
|
|
animation: 2s ${rotate} linear infinite;
|
|
|
|
}
|
|
|
|
|
|
|
|
:hover {
|
|
|
|
border-color: ${({ pending, theme }) =>
|
|
|
|
pending ? transparentize(0, theme.royalBlue) : transparentize(0, theme.connectedGreen)};
|
|
|
|
}
|
|
|
|
`
|
|
|
|
const ButtonWrapper = styled.div`
|
|
|
|
a {
|
|
|
|
color: ${({ pending, theme }) => (pending ? theme.royalBlue : theme.connectedGreen)};
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
export default function Transaction({ hash, pending }) {
|
2019-11-26 01:56:31 +03:00
|
|
|
const { chainId } = useWeb3React()
|
2019-05-30 23:42:25 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TransactionWrapper key={hash}>
|
|
|
|
<TransactionStatusWrapper>
|
2019-11-26 01:56:31 +03:00
|
|
|
<Link href={getEtherscanLink(chainId, hash, 'transaction')}>{hash} ↗ </Link>
|
2019-05-30 23:42:25 +03:00
|
|
|
<Copy toCopy={hash} />
|
|
|
|
</TransactionStatusWrapper>
|
|
|
|
{pending ? (
|
|
|
|
<ButtonWrapper pending={pending}>
|
2019-11-26 01:56:31 +03:00
|
|
|
<Link href={getEtherscanLink(chainId, hash, 'transaction')}>
|
2019-05-30 23:42:25 +03:00
|
|
|
<TransactionState pending={pending}>
|
|
|
|
<Spinner src={Circle} id="pending" />
|
|
|
|
<TransactionStatusText>Pending</TransactionStatusText>
|
|
|
|
</TransactionState>
|
|
|
|
</Link>
|
|
|
|
</ButtonWrapper>
|
|
|
|
) : (
|
|
|
|
<ButtonWrapper pending={pending}>
|
2019-11-26 01:56:31 +03:00
|
|
|
<Link href={getEtherscanLink(chainId, hash, 'transaction')}>
|
2019-05-30 23:42:25 +03:00
|
|
|
<TransactionState pending={pending}>
|
|
|
|
<Check size="16" />
|
|
|
|
<TransactionStatusText>Confirmed</TransactionStatusText>
|
|
|
|
</TransactionState>
|
|
|
|
</Link>
|
|
|
|
</ButtonWrapper>
|
|
|
|
)}
|
|
|
|
</TransactionWrapper>
|
|
|
|
)
|
|
|
|
}
|