Commit 685bb174 authored by Moody Salem's avatar Moody Salem

Improve rendering of failed transactions

parent 9006acb4
import React from 'react' import React from 'react'
import styled, { keyframes } from 'styled-components' import styled, { keyframes } from 'styled-components'
import { Check } from 'react-feather' import { Check, Triangle } from 'react-feather'
import { useWeb3React } from '../../hooks' import { useWeb3React } from '../../hooks'
import { getEtherscanLink } from '../../utils' import { getEtherscanLink } from '../../utils'
...@@ -43,17 +43,25 @@ const rotate = keyframes` ...@@ -43,17 +43,25 @@ const rotate = keyframes`
} }
` `
const TransactionState = styled.div<{ pending?: boolean }>` const TransactionState = styled.div<{ pending: boolean; success?: boolean }>`
display: flex; display: flex;
background-color: ${({ pending, theme }) => background-color: ${({ pending, success, theme }) =>
pending ? transparentize(0.95, theme.primary1) : transparentize(0.95, theme.green1)}; pending
? transparentize(0.95, theme.primary1)
: success
? transparentize(0.95, theme.green1)
: transparentize(0.95, theme.red1)};
border-radius: 1.5rem; border-radius: 1.5rem;
padding: 0.5rem 0.75rem; padding: 0.5rem 0.75rem;
font-weight: 500; font-weight: 500;
font-size: 0.75rem; font-size: 0.75rem;
border: 1px solid; border: 1px solid;
border-color: ${({ pending, theme }) => border-color: ${({ pending, success, theme }) =>
pending ? transparentize(0.75, theme.primary1) : transparentize(0.75, theme.green1)}; pending
? transparentize(0.75, theme.primary1)
: success
? transparentize(0.75, theme.green1)
: transparentize(0.75, theme.red1)};
#pending { #pending {
animation: 2s ${rotate} linear infinite; animation: 2s ${rotate} linear infinite;
...@@ -64,17 +72,21 @@ const TransactionState = styled.div<{ pending?: boolean }>` ...@@ -64,17 +72,21 @@ const TransactionState = styled.div<{ pending?: boolean }>`
pending ? transparentize(0, theme.primary1) : transparentize(0, theme.green1)}; pending ? transparentize(0, theme.primary1) : transparentize(0, theme.green1)};
} }
` `
const ButtonWrapper = styled.div<{ pending: boolean }>` const ButtonWrapper = styled.div<{ pending: boolean; success?: boolean }>`
a { a {
color: ${({ pending, theme }) => (pending ? theme.primary1 : theme.green1)}; color: ${({ pending, success, theme }) => (pending ? theme.primary1 : success ? theme.green1 : theme.red1)};
} }
` `
export default function Transaction({ hash, pending }: { hash: string; pending: boolean }) { export default function Transaction({ hash }: { hash: string }) {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const allTransactions = useAllTransactions() const allTransactions = useAllTransactions()
const summary = allTransactions?.[hash]?.summary const summary = allTransactions?.[hash]?.summary
const pending = !allTransactions?.[hash]?.receipt
const success =
!pending &&
(allTransactions[hash].receipt.status === 1 || typeof allTransactions[hash].receipt.status === 'undefined')
return ( return (
<TransactionWrapper key={hash}> <TransactionWrapper key={hash}>
...@@ -82,25 +94,14 @@ export default function Transaction({ hash, pending }: { hash: string; pending: ...@@ -82,25 +94,14 @@ export default function Transaction({ hash, pending }: { hash: string; pending:
<Link href={getEtherscanLink(chainId, hash, 'transaction')}>{summary ? summary : hash}</Link> <Link href={getEtherscanLink(chainId, hash, 'transaction')}>{summary ? summary : hash}</Link>
<Copy toCopy={hash} /> <Copy toCopy={hash} />
</TransactionStatusWrapper> </TransactionStatusWrapper>
{pending ? ( <ButtonWrapper pending={false} success={success}>
<ButtonWrapper pending={pending}>
<Link href={getEtherscanLink(chainId, hash, 'transaction')}>
<TransactionState pending={pending}>
<Spinner src={Circle} id="pending" />
<TransactionStatusText>Pending</TransactionStatusText>
</TransactionState>
</Link>
</ButtonWrapper>
) : (
<ButtonWrapper pending={pending}>
<Link href={getEtherscanLink(chainId, hash, 'transaction')}> <Link href={getEtherscanLink(chainId, hash, 'transaction')}>
<TransactionState pending={pending}> <TransactionState pending={pending} success={success}>
<Check size="16" /> {pending ? <Spinner src={Circle} /> : success ? <Check size="16" /> : <Triangle size="16" />}
<TransactionStatusText>Confirmed</TransactionStatusText> <TransactionStatusText>{pending ? 'Pending' : success ? 'Success' : 'Failed'}</TransactionStatusText>
</TransactionState> </TransactionState>
</Link> </Link>
</ButtonWrapper> </ButtonWrapper>
)}
</TransactionWrapper> </TransactionWrapper>
) )
} }
...@@ -213,11 +213,11 @@ const MainWalletAction = styled(WalletAction)` ...@@ -213,11 +213,11 @@ const MainWalletAction = styled(WalletAction)`
color: ${({ theme }) => theme.primary1}; color: ${({ theme }) => theme.primary1};
` `
function renderTransactions(transactions, pending) { function renderTransactions(transactions) {
return ( return (
<TransactionListWrapper> <TransactionListWrapper>
{transactions.map((hash, i) => { {transactions.map((hash, i) => {
return <Transaction key={i} hash={hash} pending={pending} /> return <Transaction key={i} hash={hash} />
})} })}
</TransactionListWrapper> </TransactionListWrapper>
) )
...@@ -381,8 +381,8 @@ export default function AccountDetails({ ...@@ -381,8 +381,8 @@ export default function AccountDetails({
{!!pendingTransactions.length || !!confirmedTransactions.length ? ( {!!pendingTransactions.length || !!confirmedTransactions.length ? (
<LowerSection> <LowerSection>
<TYPE.body>Recent Transactions</TYPE.body> <TYPE.body>Recent Transactions</TYPE.body>
{renderTransactions(pendingTransactions, true)} {renderTransactions(pendingTransactions)}
{renderTransactions(confirmedTransactions, false)} {renderTransactions(confirmedTransactions)}
</LowerSection> </LowerSection>
) : ( ) : (
<LowerSection> <LowerSection>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment