Commit 176c275a authored by lynn's avatar lynn Committed by GitHub

feat: Web 640 eng transaction states redesign (#4389)

* init

* pending and failed states

* simplify

* init

* modals

* fix drop shadow logic

* fixes for kaylee comments
parent ae2b4b16
...@@ -26,7 +26,7 @@ const StyledDialogOverlay = styled(AnimatedDialogOverlay)<{ redesignFlag?: boole ...@@ -26,7 +26,7 @@ const StyledDialogOverlay = styled(AnimatedDialogOverlay)<{ redesignFlag?: boole
const AnimatedDialogContent = animated(DialogContent) const AnimatedDialogContent = animated(DialogContent)
// destructure to not pass custom props to Dialog DOM element // destructure to not pass custom props to Dialog DOM element
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const StyledDialogContent = styled(({ minHeight, maxHeight, mobile, isOpen, ...rest }) => ( const StyledDialogContent = styled(({ minHeight, maxHeight, mobile, isOpen, redesignFlag, ...rest }) => (
<AnimatedDialogContent {...rest} /> <AnimatedDialogContent {...rest} />
)).attrs({ )).attrs({
'aria-label': 'dialog', 'aria-label': 'dialog',
...@@ -37,7 +37,8 @@ const StyledDialogContent = styled(({ minHeight, maxHeight, mobile, isOpen, ...r ...@@ -37,7 +37,8 @@ const StyledDialogContent = styled(({ minHeight, maxHeight, mobile, isOpen, ...r
margin: 0 0 2rem 0; margin: 0 0 2rem 0;
background-color: ${({ theme }) => theme.deprecated_bg0}; background-color: ${({ theme }) => theme.deprecated_bg0};
border: 1px solid ${({ theme }) => theme.deprecated_bg1}; border: 1px solid ${({ theme }) => theme.deprecated_bg1};
box-shadow: 0 4px 8px 0 ${({ theme }) => transparentize(0.95, theme.shadow1)}; box-shadow: ${({ theme, redesignFlag }) =>
redesignFlag ? theme.deepShadow : `0 4px 8px 0 ${transparentize(0.95, theme.shadow1)}`};
padding: 0px; padding: 0px;
width: 50vw; width: 50vw;
overflow-y: auto; overflow-y: auto;
...@@ -139,6 +140,7 @@ export default function Modal({ ...@@ -139,6 +140,7 @@ export default function Modal({
minHeight={minHeight} minHeight={minHeight}
maxHeight={maxHeight} maxHeight={maxHeight}
mobile={isMobile} mobile={isMobile}
redesignFlag={redesignFlag}
> >
{/* prevents the automatic focusing of inputs on mobile by the reach dialog */} {/* prevents the automatic focusing of inputs on mobile by the reach dialog */}
{!initialFocusRef && isMobile ? <div tabIndex={1} /> : null} {!initialFocusRef && isMobile ? <div tabIndex={1} /> : null}
......
...@@ -4,6 +4,7 @@ import { useWeb3React } from '@web3-react/core' ...@@ -4,6 +4,7 @@ import { useWeb3React } from '@web3-react/core'
import Badge from 'components/Badge' import Badge from 'components/Badge'
import { getChainInfo } from 'constants/chainInfo' import { getChainInfo } from 'constants/chainInfo'
import { SupportedL2ChainId } from 'constants/chains' import { SupportedL2ChainId } from 'constants/chains'
import { RedesignVariant, useRedesignFlag } from 'featureFlags/flags/redesign'
import useCurrencyLogoURIs from 'lib/hooks/useCurrencyLogoURIs' import useCurrencyLogoURIs from 'lib/hooks/useCurrencyLogoURIs'
import { ReactNode, useCallback, useState } from 'react' import { ReactNode, useCallback, useState } from 'react'
import { AlertCircle, AlertTriangle, ArrowUpCircle, CheckCircle } from 'react-feather' import { AlertCircle, AlertTriangle, ArrowUpCircle, CheckCircle } from 'react-feather'
...@@ -13,7 +14,7 @@ import styled, { useTheme } from 'styled-components/macro' ...@@ -13,7 +14,7 @@ import styled, { useTheme } from 'styled-components/macro'
import { isL2ChainId } from 'utils/chains' import { isL2ChainId } from 'utils/chains'
import Circle from '../../assets/images/blue-loader.svg' import Circle from '../../assets/images/blue-loader.svg'
import { ExternalLink } from '../../theme' import { ExternalLink, ThemedText } from '../../theme'
import { CloseIcon, CustomLightSpinner } from '../../theme' import { CloseIcon, CustomLightSpinner } from '../../theme'
import { ExplorerDataType, getExplorerLink } from '../../utils/getExplorerLink' import { ExplorerDataType, getExplorerLink } from '../../utils/getExplorerLink'
import { TransactionSummary } from '../AccountDetails/TransactionSummary' import { TransactionSummary } from '../AccountDetails/TransactionSummary'
...@@ -23,7 +24,9 @@ import Modal from '../Modal' ...@@ -23,7 +24,9 @@ import Modal from '../Modal'
import { RowBetween, RowFixed } from '../Row' import { RowBetween, RowFixed } from '../Row'
import AnimatedConfirmation from './AnimatedConfirmation' import AnimatedConfirmation from './AnimatedConfirmation'
const Wrapper = styled.div` const Wrapper = styled.div<{ redesignFlag?: boolean }>`
background-color: ${({ redesignFlag, theme }) => redesignFlag && theme.backgroundSurface};
outline: ${({ redesignFlag, theme }) => redesignFlag && `1px solid ${theme.backgroundOutline}`};
width: 100%; width: 100%;
padding: 1rem; padding: 1rem;
` `
...@@ -34,6 +37,7 @@ const Section = styled(AutoColumn)<{ inline?: boolean }>` ...@@ -34,6 +37,7 @@ const Section = styled(AutoColumn)<{ inline?: boolean }>`
const BottomSection = styled(Section)` const BottomSection = styled(Section)`
border-bottom-left-radius: 20px; border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px; border-bottom-right-radius: 20px;
padding-bottom: 10px;
` `
const ConfirmedIcon = styled(ColumnCenter)<{ inline?: boolean }>` const ConfirmedIcon = styled(ColumnCenter)<{ inline?: boolean }>`
...@@ -55,7 +59,36 @@ function ConfirmationPendingContent({ ...@@ -55,7 +59,36 @@ function ConfirmationPendingContent({
pendingText: ReactNode pendingText: ReactNode
inline?: boolean // not in modal inline?: boolean // not in modal
}) { }) {
return ( const redesignFlag = useRedesignFlag()
const redesignFlagEnabled = redesignFlag === RedesignVariant.Enabled
const theme = useTheme()
return redesignFlagEnabled ? (
<Wrapper>
<AutoColumn gap="md">
{!inline && (
<RowBetween>
<div />
<CloseIcon onClick={onDismiss} />
</RowBetween>
)}
<ConfirmedIcon inline={inline}>
<CustomLightSpinner src={Circle} alt="loader" size={inline ? '40px' : '90px'} />
</ConfirmedIcon>
<AutoColumn gap="12px" justify={'center'}>
<Text fontWeight={500} fontSize={20} color={theme.textPrimary} textAlign="center">
<Trans>Waiting for confirmation</Trans>
</Text>
<Text fontWeight={600} fontSize={16} color={theme.textPrimary} textAlign="center">
{pendingText}
</Text>
<Text fontWeight={400} fontSize={12} color={theme.textSecondary} textAlign="center" marginBottom="12px">
<Trans>Confirm this transaction in your wallet</Trans>
</Text>
</AutoColumn>
</AutoColumn>
</Wrapper>
) : (
<Wrapper> <Wrapper>
<AutoColumn gap="md"> <AutoColumn gap="md">
{!inline && ( {!inline && (
...@@ -102,6 +135,9 @@ function TransactionSubmittedContent({ ...@@ -102,6 +135,9 @@ function TransactionSubmittedContent({
const token = currencyToAdd?.wrapped const token = currencyToAdd?.wrapped
const logoURL = useCurrencyLogoURIs(token)[0] const logoURL = useCurrencyLogoURIs(token)[0]
const redesignFlag = useRedesignFlag()
const redesignFlagEnabled = redesignFlag === RedesignVariant.Enabled
const [success, setSuccess] = useState<boolean | undefined>() const [success, setSuccess] = useState<boolean | undefined>()
const addToken = useCallback(() => { const addToken = useCallback(() => {
...@@ -117,7 +153,52 @@ function TransactionSubmittedContent({ ...@@ -117,7 +153,52 @@ function TransactionSubmittedContent({
.catch(() => setSuccess(false)) .catch(() => setSuccess(false))
}, [connector, logoURL, token]) }, [connector, logoURL, token])
return ( return redesignFlagEnabled ? (
<Wrapper>
<Section inline={inline}>
{!inline && (
<RowBetween>
<div />
<CloseIcon onClick={onDismiss} />
</RowBetween>
)}
<ConfirmedIcon inline={inline}>
<ArrowUpCircle strokeWidth={1} size={inline ? '40px' : '75px'} color={theme.accentActive} />
</ConfirmedIcon>
<AutoColumn gap="12px" justify={'center'} style={{ paddingBottom: '12px' }}>
<ThemedText.MediumHeader textAlign="center">
<Trans>Transaction submitted</Trans>
</ThemedText.MediumHeader>
{currencyToAdd && connector.watchAsset && (
<ButtonLight mt="12px" padding="6px 12px" width="fit-content" onClick={addToken}>
{!success ? (
<RowFixed>
<Trans>Add {currencyToAdd.symbol}</Trans>
</RowFixed>
) : (
<RowFixed>
<Trans>Added {currencyToAdd.symbol} </Trans>
<CheckCircle size={'16px'} stroke={theme.deprecated_green1} style={{ marginLeft: '6px' }} />
</RowFixed>
)}
</ButtonLight>
)}
<ButtonPrimary onClick={onDismiss} style={{ margin: '20px 0 0 0' }}>
<Text fontWeight={600} fontSize={20} color={theme.accentTextLightPrimary}>
{inline ? <Trans>Return</Trans> : <Trans>Close</Trans>}
</Text>
</ButtonPrimary>
{chainId && hash && (
<ExternalLink href={getExplorerLink(chainId, hash, ExplorerDataType.TRANSACTION)}>
<Text fontWeight={600} fontSize={14} color={theme.accentAction}>
<Trans>View on Etherscan</Trans>
</Text>
</ExternalLink>
)}
</AutoColumn>
</Section>
</Wrapper>
) : (
<Wrapper> <Wrapper>
<Section inline={inline}> <Section inline={inline}>
{!inline && ( {!inline && (
...@@ -193,8 +274,30 @@ export function ConfirmationModalContent({ ...@@ -193,8 +274,30 @@ export function ConfirmationModalContent({
} }
export function TransactionErrorContent({ message, onDismiss }: { message: ReactNode; onDismiss: () => void }) { export function TransactionErrorContent({ message, onDismiss }: { message: ReactNode; onDismiss: () => void }) {
const redesignFlag = useRedesignFlag()
const redesignFlagEnabled = redesignFlag === RedesignVariant.Enabled
const theme = useTheme() const theme = useTheme()
return ( return redesignFlagEnabled ? (
<Wrapper redesignFlag={true}>
<Section>
<RowBetween>
<Text fontWeight={600} fontSize={16}>
<Trans>Error</Trans>
</Text>
<CloseIcon onClick={onDismiss} redesignFlag={true} />
</RowBetween>
<AutoColumn style={{ marginTop: 20, padding: '2rem 0' }} gap="24px" justify="center">
<AlertTriangle color={theme.accentCritical} style={{ strokeWidth: 1 }} size={90} />
<ThemedText.MediumHeader textAlign="center">{message}</ThemedText.MediumHeader>
</AutoColumn>
</Section>
<BottomSection gap="12px">
<ButtonPrimary onClick={onDismiss} redesignFlag={true}>
<Trans>Dismiss</Trans>
</ButtonPrimary>
</BottomSection>
</Wrapper>
) : (
<Wrapper> <Wrapper>
<Section> <Section>
<RowBetween> <RowBetween>
...@@ -344,12 +447,14 @@ export default function TransactionConfirmationModal({ ...@@ -344,12 +447,14 @@ export default function TransactionConfirmationModal({
currencyToAdd, currencyToAdd,
}: ConfirmationModalProps) { }: ConfirmationModalProps) {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const redesignFlag = useRedesignFlag()
const redesignFlagEnabled = redesignFlag === RedesignVariant.Enabled
if (!chainId) return null if (!chainId) return null
// confirmation screen // confirmation screen
return ( return (
<Modal isOpen={isOpen} onDismiss={onDismiss} maxHeight={90}> <Modal isOpen={isOpen} onDismiss={onDismiss} maxHeight={90} redesignFlag={redesignFlagEnabled}>
{isL2ChainId(chainId) && (hash || attemptingTxn) ? ( {isL2ChainId(chainId) && (hash || attemptingTxn) ? (
<L2Content chainId={chainId} hash={hash} onDismiss={onDismiss} pendingText={pendingText} /> <L2Content chainId={chainId} hash={hash} onDismiss={onDismiss} pendingText={pendingText} />
) : attemptingTxn ? ( ) : attemptingTxn ? (
......
...@@ -119,7 +119,7 @@ export default function useSendSwapTransaction( ...@@ -119,7 +119,7 @@ export default function useSendSwapTransaction(
.catch((error) => { .catch((error) => {
// if the user rejected the tx, pass this along // if the user rejected the tx, pass this along
if (error?.code === 4001) { if (error?.code === 4001) {
throw new Error(t`Transaction rejected.`) throw new Error(t`Transaction rejected`)
} else { } else {
// otherwise, the error was unexpected and we need to convey that // otherwise, the error was unexpected and we need to convey that
console.error(`Swap failed`, error, address, calldata, value) console.error(`Swap failed`, error, address, calldata, value)
......
...@@ -21,7 +21,8 @@ import { Color } from './styled' ...@@ -21,7 +21,8 @@ import { Color } from './styled'
// TODO: Break this file into a components folder // TODO: Break this file into a components folder
export const CloseIcon = styled(X)<{ onClick: () => void }>` export const CloseIcon = styled(X)<{ onClick: () => void; redesignFlag?: boolean }>`
color: ${({ redesignFlag, theme }) => redesignFlag && theme.textSecondary};
cursor: pointer; cursor: pointer;
` `
......
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