feat: Adding in remaining transactions to transaction history (#4455)
* adding in remaining transactions: Wrap, Collect Fees, Approval and claim rewards Co-authored-by: Alex Ball <alexball@UNISWAP-MAC-038.local>
This commit is contained in:
parent
a345cff614
commit
55c5f03004
@ -1,6 +1,9 @@
|
|||||||
|
import { useWeb3React } from '@web3-react/core'
|
||||||
|
import { UNI_ADDRESS } from 'constants/addresses'
|
||||||
import { TransactionInfo, TransactionType } from 'state/transactions/types'
|
import { TransactionInfo, TransactionType } from 'state/transactions/types'
|
||||||
import styled, { css } from 'styled-components/macro'
|
import styled, { css } from 'styled-components/macro'
|
||||||
|
|
||||||
|
import { nativeOnChain } from '../../constants/tokens'
|
||||||
import { useCurrency } from '../../hooks/Tokens'
|
import { useCurrency } from '../../hooks/Tokens'
|
||||||
import CurrencyLogo from '../CurrencyLogo'
|
import CurrencyLogo from '../CurrencyLogo'
|
||||||
|
|
||||||
@ -32,22 +35,38 @@ interface CurrencyPair {
|
|||||||
currencyId1: string | undefined
|
currencyId1: string | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCurrency = ({ info }: { info: TransactionInfo }): CurrencyPair => {
|
const getCurrency = ({ info, chainId }: { info: TransactionInfo; chainId: number | undefined }): CurrencyPair => {
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case TransactionType.ADD_LIQUIDITY_V3_POOL:
|
case TransactionType.ADD_LIQUIDITY_V3_POOL:
|
||||||
case TransactionType.REMOVE_LIQUIDITY_V3:
|
case TransactionType.REMOVE_LIQUIDITY_V3:
|
||||||
|
case TransactionType.CREATE_V3_POOL:
|
||||||
const { baseCurrencyId, quoteCurrencyId } = info
|
const { baseCurrencyId, quoteCurrencyId } = info
|
||||||
return { currencyId0: baseCurrencyId, currencyId1: quoteCurrencyId }
|
return { currencyId0: baseCurrencyId, currencyId1: quoteCurrencyId }
|
||||||
case TransactionType.SWAP:
|
case TransactionType.SWAP:
|
||||||
const { inputCurrencyId, outputCurrencyId } = info
|
const { inputCurrencyId, outputCurrencyId } = info
|
||||||
return { currencyId0: inputCurrencyId, currencyId1: outputCurrencyId }
|
return { currencyId0: inputCurrencyId, currencyId1: outputCurrencyId }
|
||||||
|
case TransactionType.WRAP:
|
||||||
|
const { unwrapped } = info
|
||||||
|
const native = info.chainId ? nativeOnChain(info.chainId) : undefined
|
||||||
|
const base = 'ETH'
|
||||||
|
const wrappedCurrency = native?.wrapped.address ?? 'WETH'
|
||||||
|
return { currencyId0: unwrapped ? wrappedCurrency : base, currencyId1: unwrapped ? base : wrappedCurrency }
|
||||||
|
case TransactionType.COLLECT_FEES:
|
||||||
|
const { currencyId0, currencyId1 } = info
|
||||||
|
return { currencyId0, currencyId1 }
|
||||||
|
case TransactionType.APPROVAL:
|
||||||
|
return { currencyId0: info.tokenAddress, currencyId1: undefined }
|
||||||
|
case TransactionType.CLAIM:
|
||||||
|
const uniAddress = chainId ? UNI_ADDRESS[chainId] : undefined
|
||||||
|
return { currencyId0: uniAddress, currencyId1: undefined }
|
||||||
default:
|
default:
|
||||||
return { currencyId0: undefined, currencyId1: undefined }
|
return { currencyId0: undefined, currencyId1: undefined }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LogoView = ({ info }: { info: TransactionInfo }) => {
|
const LogoView = ({ info }: { info: TransactionInfo }) => {
|
||||||
const { currencyId0, currencyId1 } = getCurrency({ info })
|
const { chainId } = useWeb3React()
|
||||||
|
const { currencyId0, currencyId1 } = getCurrency({ info, chainId })
|
||||||
const currency0 = useCurrency(currencyId0)
|
const currency0 = useCurrency(currencyId0)
|
||||||
const currency1 = useCurrency(currencyId1)
|
const currency1 = useCurrency(currencyId1)
|
||||||
const isCentered = !(currency0 && currency1)
|
const isCentered = !(currency0 && currency1)
|
||||||
|
@ -3,15 +3,22 @@ import { Fraction, TradeType } from '@uniswap/sdk-core'
|
|||||||
import JSBI from 'jsbi'
|
import JSBI from 'jsbi'
|
||||||
import {
|
import {
|
||||||
AddLiquidityV3PoolTransactionInfo,
|
AddLiquidityV3PoolTransactionInfo,
|
||||||
|
ApproveTransactionInfo,
|
||||||
|
ClaimTransactionInfo,
|
||||||
|
CollectFeesTransactionInfo,
|
||||||
ExactInputSwapTransactionInfo,
|
ExactInputSwapTransactionInfo,
|
||||||
ExactOutputSwapTransactionInfo,
|
ExactOutputSwapTransactionInfo,
|
||||||
RemoveLiquidityV3TransactionInfo,
|
RemoveLiquidityV3TransactionInfo,
|
||||||
TransactionInfo,
|
TransactionInfo,
|
||||||
TransactionType,
|
TransactionType,
|
||||||
|
WrapTransactionInfo,
|
||||||
} from 'state/transactions/types'
|
} from 'state/transactions/types'
|
||||||
import styled from 'styled-components/macro'
|
import styled from 'styled-components/macro'
|
||||||
|
|
||||||
import { useCurrency } from '../../hooks/Tokens'
|
import { nativeOnChain } from '../../constants/tokens'
|
||||||
|
import { useCurrency, useToken } from '../../hooks/Tokens'
|
||||||
|
import useENSName from '../../hooks/useENSName'
|
||||||
|
import { shortenAddress } from '../../utils'
|
||||||
import { TransactionState } from './index'
|
import { TransactionState } from './index'
|
||||||
|
|
||||||
const HighlightText = styled.span`
|
const HighlightText = styled.span`
|
||||||
@ -19,6 +26,10 @@ const HighlightText = styled.span`
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const BodyWrap = styled.div`
|
||||||
|
line-height: 20px;
|
||||||
|
`
|
||||||
|
|
||||||
interface ActionProps {
|
interface ActionProps {
|
||||||
pending: JSX.Element
|
pending: JSX.Element
|
||||||
success: JSX.Element
|
success: JSX.Element
|
||||||
@ -85,13 +96,13 @@ const SwapSummary = ({
|
|||||||
const { rawAmountFrom, rawAmountTo } = getRawAmounts(info)
|
const { rawAmountFrom, rawAmountTo } = getRawAmounts(info)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<BodyWrap>
|
||||||
<Action {...actionProps} />{' '}
|
<Action {...actionProps} />{' '}
|
||||||
<FormattedCurrencyAmount rawAmount={rawAmountFrom} currencyId={info.inputCurrencyId} sigFigs={2} />{' '}
|
<FormattedCurrencyAmount rawAmount={rawAmountFrom} currencyId={info.inputCurrencyId} sigFigs={2} />{' '}
|
||||||
<Trans>for </Trans>{' '}
|
<Trans>for </Trans>{' '}
|
||||||
<FormattedCurrencyAmount rawAmount={rawAmountTo} currencyId={info.outputCurrencyId} sigFigs={2} />{' '}
|
<FormattedCurrencyAmount rawAmount={rawAmountTo} currencyId={info.outputCurrencyId} sigFigs={2} />{' '}
|
||||||
<FailedText transactionState={transactionState} />
|
<FailedText transactionState={transactionState} />
|
||||||
</>
|
</BodyWrap>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +123,7 @@ const AddLiquidityV3PoolSummary = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<BodyWrap>
|
||||||
{createPool ? (
|
{createPool ? (
|
||||||
<CreateV3PoolSummary info={info} transactionState={transactionState} />
|
<CreateV3PoolSummary info={info} transactionState={transactionState} />
|
||||||
) : (
|
) : (
|
||||||
@ -124,7 +135,7 @@ const AddLiquidityV3PoolSummary = ({
|
|||||||
</>
|
</>
|
||||||
)}{' '}
|
)}{' '}
|
||||||
<FailedText transactionState={transactionState} />
|
<FailedText transactionState={transactionState} />
|
||||||
</>
|
</BodyWrap>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,13 +154,13 @@ const RemoveLiquidityV3Summary = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<BodyWrap>
|
||||||
<Action {...actionProps} />{' '}
|
<Action {...actionProps} />{' '}
|
||||||
<FormattedCurrencyAmount rawAmount={expectedAmountBaseRaw} currencyId={baseCurrencyId} sigFigs={2} />{' '}
|
<FormattedCurrencyAmount rawAmount={expectedAmountBaseRaw} currencyId={baseCurrencyId} sigFigs={2} />{' '}
|
||||||
<Trans>and</Trans>{' '}
|
<Trans>and</Trans>{' '}
|
||||||
<FormattedCurrencyAmount rawAmount={expectedAmountQuoteRaw} currencyId={quoteCurrencyId} sigFigs={2} />{' '}
|
<FormattedCurrencyAmount rawAmount={expectedAmountQuoteRaw} currencyId={quoteCurrencyId} sigFigs={2} />{' '}
|
||||||
<FailedText transactionState={transactionState} />
|
<FailedText transactionState={transactionState} />
|
||||||
</>
|
</BodyWrap>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,13 +181,135 @@ const CreateV3PoolSummary = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<BodyWrap>
|
||||||
<Action {...actionProps} />{' '}
|
<Action {...actionProps} />{' '}
|
||||||
<HighlightText>
|
<HighlightText>
|
||||||
{baseCurrency?.symbol}/{quoteCurrency?.symbol}{' '}
|
{baseCurrency?.symbol}/{quoteCurrency?.symbol}{' '}
|
||||||
</HighlightText>
|
</HighlightText>
|
||||||
<Trans>Pool</Trans> <FailedText transactionState={transactionState} />
|
<Trans>Pool</Trans> <FailedText transactionState={transactionState} />
|
||||||
</>
|
</BodyWrap>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const CollectFeesSummary = ({
|
||||||
|
info,
|
||||||
|
transactionState,
|
||||||
|
}: {
|
||||||
|
info: CollectFeesTransactionInfo
|
||||||
|
transactionState: TransactionState
|
||||||
|
}) => {
|
||||||
|
const { currencyId0, expectedCurrencyOwed0 = '0', expectedCurrencyOwed1 = '0', currencyId1 } = info
|
||||||
|
const actionProps = {
|
||||||
|
transactionState,
|
||||||
|
pending: <Trans>Collecting</Trans>,
|
||||||
|
success: <Trans>Collected</Trans>,
|
||||||
|
failed: <Trans>Collect</Trans>,
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BodyWrap>
|
||||||
|
<Action {...actionProps} />{' '}
|
||||||
|
<FormattedCurrencyAmount rawAmount={expectedCurrencyOwed0} currencyId={currencyId0} sigFigs={2} />{' '}
|
||||||
|
<Trans>and</Trans>{' '}
|
||||||
|
<FormattedCurrencyAmount rawAmount={expectedCurrencyOwed1} currencyId={currencyId1} sigFigs={2} />{' '}
|
||||||
|
<Trans>fees</Trans> <FailedText transactionState={transactionState} />
|
||||||
|
</BodyWrap>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ApprovalSummary = ({
|
||||||
|
info,
|
||||||
|
transactionState,
|
||||||
|
}: {
|
||||||
|
info: ApproveTransactionInfo
|
||||||
|
transactionState: TransactionState
|
||||||
|
}) => {
|
||||||
|
const token = useToken(info.tokenAddress)
|
||||||
|
const actionProps = {
|
||||||
|
transactionState,
|
||||||
|
pending: <Trans>Approving</Trans>,
|
||||||
|
success: <Trans>Approved</Trans>,
|
||||||
|
failed: <Trans>Approve</Trans>,
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BodyWrap>
|
||||||
|
<Action {...actionProps} /> <HighlightText>{token?.symbol}</HighlightText>{' '}
|
||||||
|
<FailedText transactionState={transactionState} />
|
||||||
|
</BodyWrap>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ClaimSummary = ({
|
||||||
|
info: { recipient, uniAmountRaw },
|
||||||
|
transactionState,
|
||||||
|
}: {
|
||||||
|
info: ClaimTransactionInfo
|
||||||
|
transactionState: TransactionState
|
||||||
|
}) => {
|
||||||
|
const { ENSName } = useENSName()
|
||||||
|
const actionProps = {
|
||||||
|
transactionState,
|
||||||
|
pending: <Trans>Claiming</Trans>,
|
||||||
|
success: <Trans>Claimed</Trans>,
|
||||||
|
failed: <Trans>Claim</Trans>,
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BodyWrap>
|
||||||
|
{uniAmountRaw && (
|
||||||
|
<>
|
||||||
|
<Action {...actionProps} />{' '}
|
||||||
|
<HighlightText>
|
||||||
|
{formatAmount(uniAmountRaw, 18, 4)}
|
||||||
|
<Trans>UNI</Trans>{' '}
|
||||||
|
</HighlightText>{' '}
|
||||||
|
<Trans>for</Trans> <HighlightText>{ENSName ?? shortenAddress(recipient)}</HighlightText>
|
||||||
|
</>
|
||||||
|
)}{' '}
|
||||||
|
<FailedText transactionState={transactionState} />
|
||||||
|
</BodyWrap>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const WrapSummary = ({
|
||||||
|
info: { chainId, currencyAmountRaw, unwrapped },
|
||||||
|
transactionState,
|
||||||
|
}: {
|
||||||
|
info: WrapTransactionInfo
|
||||||
|
transactionState: TransactionState
|
||||||
|
}) => {
|
||||||
|
const native = chainId ? nativeOnChain(chainId) : undefined
|
||||||
|
const from = unwrapped ? native?.wrapped.symbol ?? 'WETH' : native?.symbol ?? 'ETH'
|
||||||
|
const to = unwrapped ? native?.symbol ?? 'ETH' : native?.wrapped.symbol ?? 'WETH'
|
||||||
|
|
||||||
|
const amount = formatAmount(currencyAmountRaw, 18, 6)
|
||||||
|
const actionProps = unwrapped
|
||||||
|
? {
|
||||||
|
transactionState,
|
||||||
|
pending: <Trans>Unwrapping</Trans>,
|
||||||
|
success: <Trans>Unwrapped</Trans>,
|
||||||
|
failed: <Trans>Unwrap</Trans>,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
transactionState,
|
||||||
|
pending: <Trans>Wrapping</Trans>,
|
||||||
|
success: <Trans>Wrapped</Trans>,
|
||||||
|
failed: <Trans>Wrap</Trans>,
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BodyWrap>
|
||||||
|
<Action {...actionProps} />{' '}
|
||||||
|
<HighlightText>
|
||||||
|
{amount} {from}
|
||||||
|
</HighlightText>{' '}
|
||||||
|
<Trans>to</Trans>{' '}
|
||||||
|
<HighlightText>
|
||||||
|
{amount} {to}
|
||||||
|
</HighlightText>{' '}
|
||||||
|
<FailedText transactionState={transactionState} />
|
||||||
|
</BodyWrap>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +321,14 @@ const TransactionBody = ({ info, transactionState }: { info: TransactionInfo; tr
|
|||||||
return <AddLiquidityV3PoolSummary info={info} transactionState={transactionState} />
|
return <AddLiquidityV3PoolSummary info={info} transactionState={transactionState} />
|
||||||
case TransactionType.REMOVE_LIQUIDITY_V3:
|
case TransactionType.REMOVE_LIQUIDITY_V3:
|
||||||
return <RemoveLiquidityV3Summary info={info} transactionState={transactionState} />
|
return <RemoveLiquidityV3Summary info={info} transactionState={transactionState} />
|
||||||
|
case TransactionType.WRAP:
|
||||||
|
return <WrapSummary info={info} transactionState={transactionState} />
|
||||||
|
case TransactionType.COLLECT_FEES:
|
||||||
|
return <CollectFeesSummary info={info} transactionState={transactionState} />
|
||||||
|
case TransactionType.APPROVAL:
|
||||||
|
return <ApprovalSummary info={info} transactionState={transactionState} />
|
||||||
|
case TransactionType.CLAIM:
|
||||||
|
return <ClaimSummary info={info} transactionState={transactionState} />
|
||||||
default:
|
default:
|
||||||
return <span />
|
return <span />
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { NavBarVariant, useNavBarFlag } from 'featureFlags/flags/navBar'
|
||||||
import { useCallback, useEffect } from 'react'
|
import { useCallback, useEffect } from 'react'
|
||||||
import { X } from 'react-feather'
|
import { X } from 'react-feather'
|
||||||
import { animated } from 'react-spring'
|
import { animated } from 'react-spring'
|
||||||
@ -57,6 +58,7 @@ export default function PopupItem({
|
|||||||
popKey: string
|
popKey: string
|
||||||
}) {
|
}) {
|
||||||
const removePopup = useRemovePopup()
|
const removePopup = useRemovePopup()
|
||||||
|
const navbarFlag = useNavBarFlag()
|
||||||
const removeThisPopup = useCallback(() => removePopup(popKey), [popKey, removePopup])
|
const removeThisPopup = useCallback(() => removePopup(popKey), [popKey, removePopup])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (removeAfterMs === null) return undefined
|
if (removeAfterMs === null) return undefined
|
||||||
@ -71,23 +73,24 @@ export default function PopupItem({
|
|||||||
}, [removeAfterMs, removeThisPopup])
|
}, [removeAfterMs, removeThisPopup])
|
||||||
|
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
|
const faderStyle = useSpring({
|
||||||
|
from: { width: '100%' },
|
||||||
|
to: { width: '0%' },
|
||||||
|
config: { duration: removeAfterMs ?? undefined },
|
||||||
|
})
|
||||||
|
|
||||||
let popupContent
|
let popupContent
|
||||||
if ('txn' in content) {
|
if ('txn' in content) {
|
||||||
const {
|
const {
|
||||||
txn: { hash },
|
txn: { hash },
|
||||||
} = content
|
} = content
|
||||||
|
if (navbarFlag === NavBarVariant.Enabled) return null
|
||||||
|
|
||||||
popupContent = <TransactionPopup hash={hash} />
|
popupContent = <TransactionPopup hash={hash} />
|
||||||
} else if ('failedSwitchNetwork' in content) {
|
} else if ('failedSwitchNetwork' in content) {
|
||||||
popupContent = <FailedNetworkSwitchPopup chainId={content.failedSwitchNetwork} />
|
popupContent = <FailedNetworkSwitchPopup chainId={content.failedSwitchNetwork} />
|
||||||
}
|
}
|
||||||
|
|
||||||
const faderStyle = useSpring({
|
|
||||||
from: { width: '100%' },
|
|
||||||
to: { width: '0%' },
|
|
||||||
config: { duration: removeAfterMs ?? undefined },
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popup>
|
<Popup>
|
||||||
<StyledClose color={theme.deprecated_text2} onClick={removeThisPopup} />
|
<StyledClose color={theme.deprecated_text2} onClick={removeThisPopup} />
|
||||||
|
@ -48,6 +48,7 @@ const BackSection = styled.div`
|
|||||||
cursor: default;
|
cursor: default;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
z-index: 1;
|
||||||
`
|
`
|
||||||
|
|
||||||
const BackSectionContainer = styled.div`
|
const BackSectionContainer = styled.div`
|
||||||
|
Loading…
Reference in New Issue
Block a user