Commit 730af2ee authored by Ian Lapham's avatar Ian Lapham Committed by GitHub

fix: dismiss txn confirmation modal if on L2 (#2022)

* dismiss txn confirmation modal if on l2

* line up far right margin;

* remove submitted view on txns if on L2

* remove uneeded chainid

* wrap dismissal in useEffect

* update variable names
parent c625d15f
...@@ -19,8 +19,8 @@ const BaseWrapper = css` ...@@ -19,8 +19,8 @@ const BaseWrapper = css`
position: relative; position: relative;
${StopOverflowQuery} { ${StopOverflowQuery} {
position: absolute; position: absolute;
top: 80px; top: 66px;
right: 20px; right: 16px;
} }
${({ theme }) => theme.mediaWidth.upToMedium` ${({ theme }) => theme.mediaWidth.upToMedium`
margin-left: 12px; margin-left: 12px;
......
...@@ -4,6 +4,9 @@ import { AutoColumn } from '../Column' ...@@ -4,6 +4,9 @@ import { AutoColumn } from '../Column'
import PopupItem from './PopupItem' import PopupItem from './PopupItem'
import ClaimPopup from './ClaimPopup' import ClaimPopup from './ClaimPopup'
import { useURLWarningVisible } from '../../state/user/hooks' import { useURLWarningVisible } from '../../state/user/hooks'
import { useActiveWeb3React } from 'hooks/web3'
import { SupportedChainId } from 'constants/chains'
import { MEDIA_WIDTHS } from 'theme'
const MobilePopupWrapper = styled.div<{ height: string | number }>` const MobilePopupWrapper = styled.div<{ height: string | number }>`
position: relative; position: relative;
...@@ -30,7 +33,11 @@ const MobilePopupInner = styled.div` ...@@ -30,7 +33,11 @@ const MobilePopupInner = styled.div`
} }
` `
const FixedPopupColumn = styled(AutoColumn)<{ extraPadding: boolean }>` const StopOverflowQuery = `@media screen and (min-width: ${MEDIA_WIDTHS.upToMedium + 1}px) and (max-width: ${
MEDIA_WIDTHS.upToMedium + 500
}px)`
const FixedPopupColumn = styled(AutoColumn)<{ extraPadding: boolean; xlPadding: boolean }>`
position: fixed; position: fixed;
top: ${({ extraPadding }) => (extraPadding ? '80px' : '88px')}; top: ${({ extraPadding }) => (extraPadding ? '80px' : '88px')};
right: 1rem; right: 1rem;
...@@ -41,6 +48,10 @@ const FixedPopupColumn = styled(AutoColumn)<{ extraPadding: boolean }>` ...@@ -41,6 +48,10 @@ const FixedPopupColumn = styled(AutoColumn)<{ extraPadding: boolean }>`
${({ theme }) => theme.mediaWidth.upToSmall` ${({ theme }) => theme.mediaWidth.upToSmall`
display: none; display: none;
`}; `};
${StopOverflowQuery} {
top: ${({ extraPadding, xlPadding }) => (xlPadding ? '112px' : extraPadding ? '80px' : '88px')};
}
` `
export default function Popups() { export default function Popups() {
...@@ -49,9 +60,13 @@ export default function Popups() { ...@@ -49,9 +60,13 @@ export default function Popups() {
const urlWarningActive = useURLWarningVisible() const urlWarningActive = useURLWarningVisible()
// need extra padding if network is not L1 Ethereum
const { chainId } = useActiveWeb3React()
const isNotOnMainnet = Boolean(chainId && chainId !== SupportedChainId.MAINNET)
return ( return (
<> <>
<FixedPopupColumn gap="20px" extraPadding={urlWarningActive}> <FixedPopupColumn gap="20px" extraPadding={urlWarningActive} xlPadding={isNotOnMainnet}>
<ClaimPopup /> <ClaimPopup />
{activePopups.map((item) => ( {activePopups.map((item) => (
<PopupItem key={item.key} content={item.content} popKey={item.key} removeAfterMs={item.removeAfterMs} /> <PopupItem key={item.key} content={item.content} popKey={item.key} removeAfterMs={item.removeAfterMs} />
......
import { Currency } from '@uniswap/sdk-core' import { Currency } from '@uniswap/sdk-core'
import { ReactNode, useContext } from 'react' import { ReactNode, useContext, useEffect } from 'react'
import styled, { ThemeContext } from 'styled-components/macro' import styled, { ThemeContext } from 'styled-components/macro'
import { getExplorerLink, ExplorerDataType } from '../../utils/getExplorerLink' import { getExplorerLink, ExplorerDataType } from '../../utils/getExplorerLink'
import Modal from '../Modal' import Modal from '../Modal'
...@@ -15,6 +15,7 @@ import MetaMaskLogo from '../../assets/images/metamask.png' ...@@ -15,6 +15,7 @@ import MetaMaskLogo from '../../assets/images/metamask.png'
import { useActiveWeb3React } from '../../hooks/web3' import { useActiveWeb3React } from '../../hooks/web3'
import useAddTokenToMetamask from 'hooks/useAddTokenToMetamask' import useAddTokenToMetamask from 'hooks/useAddTokenToMetamask'
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { L2_CHAIN_IDS } from 'constants/chains'
const Wrapper = styled.div` const Wrapper = styled.div`
width: 100%; width: 100%;
...@@ -227,12 +228,21 @@ export default function TransactionConfirmationModal({ ...@@ -227,12 +228,21 @@ export default function TransactionConfirmationModal({
}: ConfirmationModalProps) { }: ConfirmationModalProps) {
const { chainId } = useActiveWeb3React() const { chainId } = useActiveWeb3React()
// if on L2 and txn is submitted, close automatically (if open)
useEffect(() => {
if (isOpen && chainId && L2_CHAIN_IDS.includes(chainId) && hash) {
onDismiss()
}
}, [chainId, hash, isOpen, onDismiss])
if (!chainId) return null if (!chainId) return null
// confirmation screen // confirmation screen
// if on L2 and submitted dont render content, as should auto dismiss
// need this to skip submitted view during state update ^^
return ( return (
<Modal isOpen={isOpen} onDismiss={onDismiss} maxHeight={90}> <Modal isOpen={isOpen} onDismiss={onDismiss} maxHeight={90}>
{attemptingTxn ? ( {L2_CHAIN_IDS.includes(chainId) && hash ? null : attemptingTxn ? (
<ConfirmationPendingContent onDismiss={onDismiss} pendingText={pendingText} /> <ConfirmationPendingContent onDismiss={onDismiss} pendingText={pendingText} />
) : hash ? ( ) : hash ? (
<TransactionSubmittedContent <TransactionSubmittedContent
......
...@@ -235,7 +235,6 @@ export default function AddLiquidity({ ...@@ -235,7 +235,6 @@ export default function AddLiquidity({
...txn, ...txn,
gasLimit: calculateGasMargin(chainId, estimate), gasLimit: calculateGasMargin(chainId, estimate),
} }
return library return library
.getSigner() .getSigner()
.sendTransaction(newTxn) .sendTransaction(newTxn)
......
...@@ -252,7 +252,6 @@ export default function Swap({ history }: RouteComponentProps) { ...@@ -252,7 +252,6 @@ export default function Swap({ history }: RouteComponentProps) {
swapCallback() swapCallback()
.then((hash) => { .then((hash) => {
setSwapState({ attemptingTxn: false, tradeToConfirm, showConfirm, swapErrorMessage: undefined, txHash: hash }) setSwapState({ attemptingTxn: false, tradeToConfirm, showConfirm, swapErrorMessage: undefined, txHash: hash })
ReactGA.event({ ReactGA.event({
category: 'Swap', category: 'Swap',
action: action:
...@@ -279,8 +278,8 @@ export default function Swap({ history }: RouteComponentProps) { ...@@ -279,8 +278,8 @@ export default function Swap({ history }: RouteComponentProps) {
}) })
}) })
}, [ }, [
priceImpact,
swapCallback, swapCallback,
priceImpact,
tradeToConfirm, tradeToConfirm,
showConfirm, showConfirm,
recipient, recipient,
......
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