fix(widgets): complete etherscan link and stop timer on tx inclusion (#3267)
* fix(widgets): complete etherscan link and stop timer on tx inclusion * use preexisting helper for etherscan link * use z's EtherscanLink component * pr review
This commit is contained in:
parent
88712b5065
commit
c5ea01ce19
@ -5,5 +5,6 @@
|
|||||||
"webpack": {
|
"webpack": {
|
||||||
"configPath": "react-scripts/config/webpack.config",
|
"configPath": "react-scripts/config/webpack.config",
|
||||||
"overridePath": "cosmos.override.js"
|
"overridePath": "cosmos.override.js"
|
||||||
}
|
},
|
||||||
|
"port": 5001
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ import { ExplorerDataType, getExplorerLink } from 'utils/getExplorerLink'
|
|||||||
import ExternalLink from './ExternalLink'
|
import ExternalLink from './ExternalLink'
|
||||||
|
|
||||||
const Link = styled(ExternalLink)<{ color: Color }>`
|
const Link = styled(ExternalLink)<{ color: Color }>`
|
||||||
color: ${({ theme, color }) => theme[color]}
|
color: ${({ theme, color }) => theme[color]};
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import { Trans } from '@lingui/macro'
|
import { Trans } from '@lingui/macro'
|
||||||
import ErrorDialog, { StatusHeader } from 'lib/components/Error/ErrorDialog'
|
import ErrorDialog, { StatusHeader } from 'lib/components/Error/ErrorDialog'
|
||||||
|
import EtherscanLink from 'lib/components/EtherscanLink'
|
||||||
import useInterval from 'lib/hooks/useInterval'
|
import useInterval from 'lib/hooks/useInterval'
|
||||||
import { CheckCircle, Clock, Spinner } from 'lib/icons'
|
import { CheckCircle, Clock, Spinner } from 'lib/icons'
|
||||||
import { SwapTransactionInfo, Transaction } from 'lib/state/transactions'
|
import { SwapTransactionInfo, Transaction } from 'lib/state/transactions'
|
||||||
import styled, { ThemedText } from 'lib/theme'
|
import styled, { ThemedText } from 'lib/theme'
|
||||||
|
import ms from 'ms.macro'
|
||||||
import { useCallback, useMemo, useState } from 'react'
|
import { useCallback, useMemo, useState } from 'react'
|
||||||
|
import { ExplorerDataType } from 'utils/getExplorerLink'
|
||||||
|
|
||||||
import ActionButton from '../../ActionButton'
|
import ActionButton from '../../ActionButton'
|
||||||
import Column from '../../Column'
|
import Column from '../../Column'
|
||||||
@ -25,16 +28,9 @@ const TransactionRow = styled(Row)`
|
|||||||
|
|
||||||
function ElapsedTime({ tx }: { tx: Transaction<SwapTransactionInfo> }) {
|
function ElapsedTime({ tx }: { tx: Transaction<SwapTransactionInfo> }) {
|
||||||
const [elapsedMs, setElapsedMs] = useState(0)
|
const [elapsedMs, setElapsedMs] = useState(0)
|
||||||
useInterval(
|
|
||||||
() => {
|
useInterval(() => setElapsedMs(Date.now() - tx.addedTime), tx.receipt ? null : ms`1s`)
|
||||||
if (tx.info.response.timestamp) {
|
|
||||||
setElapsedMs(tx.info.response.timestamp - tx.addedTime)
|
|
||||||
} else {
|
|
||||||
setElapsedMs(Date.now() - tx.addedTime)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
elapsedMs === tx.info.response.timestamp ? null : 1000
|
|
||||||
)
|
|
||||||
const toElapsedTime = useCallback((ms: number) => {
|
const toElapsedTime = useCallback((ms: number) => {
|
||||||
let sec = Math.floor(ms / 1000)
|
let sec = Math.floor(ms / 1000)
|
||||||
const min = Math.floor(sec / 60)
|
const min = Math.floor(sec / 60)
|
||||||
@ -57,11 +53,6 @@ function ElapsedTime({ tx }: { tx: Transaction<SwapTransactionInfo> }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const EtherscanA = styled.a`
|
|
||||||
color: ${({ theme }) => theme.accent};
|
|
||||||
text-decoration: none;
|
|
||||||
`
|
|
||||||
|
|
||||||
interface TransactionStatusProps {
|
interface TransactionStatusProps {
|
||||||
tx: Transaction<SwapTransactionInfo>
|
tx: Transaction<SwapTransactionInfo>
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
@ -74,6 +65,7 @@ function TransactionStatus({ tx, onClose }: TransactionStatusProps) {
|
|||||||
const heading = useMemo(() => {
|
const heading = useMemo(() => {
|
||||||
return tx.receipt?.status ? <Trans>Transaction submitted</Trans> : <Trans>Transaction pending</Trans>
|
return tx.receipt?.status ? <Trans>Transaction submitted</Trans> : <Trans>Transaction pending</Trans>
|
||||||
}, [tx.receipt?.status])
|
}, [tx.receipt?.status])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column flex padded gap={0.75} align="stretch" style={{ height: '100%' }}>
|
<Column flex padded gap={0.75} align="stretch" style={{ height: '100%' }}>
|
||||||
<StatusHeader icon={Icon} iconColor={tx.receipt?.status ? 'success' : undefined}>
|
<StatusHeader icon={Icon} iconColor={tx.receipt?.status ? 'success' : undefined}>
|
||||||
@ -82,9 +74,9 @@ function TransactionStatus({ tx, onClose }: TransactionStatusProps) {
|
|||||||
</StatusHeader>
|
</StatusHeader>
|
||||||
<TransactionRow flex>
|
<TransactionRow flex>
|
||||||
<ThemedText.ButtonSmall>
|
<ThemedText.ButtonSmall>
|
||||||
<EtherscanA href="//etherscan.io" target="_blank">
|
<EtherscanLink type={ExplorerDataType.TRANSACTION} data={tx.info.response.hash}>
|
||||||
<Trans>View on Etherscan</Trans>
|
<Trans>View on Etherscan</Trans>
|
||||||
</EtherscanA>
|
</EtherscanLink>
|
||||||
</ThemedText.ButtonSmall>
|
</ThemedText.ButtonSmall>
|
||||||
<ElapsedTime tx={tx} />
|
<ElapsedTime tx={tx} />
|
||||||
</TransactionRow>
|
</TransactionRow>
|
||||||
|
Loading…
Reference in New Issue
Block a user