Commit f4680014 authored by Clayton Lin's avatar Clayton Lin Committed by GitHub

style: build new error connect state (#3831)

* style: build new error connect state

* use usecallback for resetAcountView

* remove fontSize props
parent f26ec2ff
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { darken } from 'polished' import { ButtonEmpty, ButtonPrimary } from 'components/Button'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { ThemedText } from 'theme' import { ThemedText } from 'theme'
import { AbstractConnector } from 'web3-react-abstract-connector' import { AbstractConnector } from 'web3-react-abstract-connector'
...@@ -23,12 +23,11 @@ const LoaderContainer = styled.div` ...@@ -23,12 +23,11 @@ const LoaderContainer = styled.div`
justify-content: center; justify-content: center;
` `
const LoadingMessage = styled.div<{ error?: boolean }>` const LoadingMessage = styled.div`
${({ theme }) => theme.flexRowNoWrap}; ${({ theme }) => theme.flexRowNoWrap};
align-items: center; align-items: center;
justify-content: center; justify-content: center;
border-radius: 12px; border-radius: 12px;
color: ${({ theme, error }) => (error ? theme.red1 : 'inherit')};
& > * { & > * {
padding: 1rem; padding: 1rem;
...@@ -36,27 +35,11 @@ const LoadingMessage = styled.div<{ error?: boolean }>` ...@@ -36,27 +35,11 @@ const LoadingMessage = styled.div<{ error?: boolean }>`
` `
const ErrorGroup = styled.div` const ErrorGroup = styled.div`
${({ theme }) => theme.flexRowNoWrap}; ${({ theme }) => theme.flexColumnNoWrap};
align-items: center; align-items: center;
justify-content: flex-start; justify-content: flex-start;
` `
const ErrorButton = styled.div`
border-radius: 8px;
font-size: 12px;
color: ${({ theme }) => theme.text1};
background-color: ${({ theme }) => theme.bg4};
margin-left: 1rem;
padding: 0.5rem;
font-weight: 600;
user-select: none;
&:hover {
cursor: pointer;
background-color: ${({ theme }) => darken(0.1, theme.text4)};
}
`
const LoadingWrapper = styled.div` const LoadingWrapper = styled.div`
${({ theme }) => theme.flexColumnNoWrap}; ${({ theme }) => theme.flexColumnNoWrap};
align-items: center; align-items: center;
...@@ -68,29 +51,43 @@ export default function PendingView({ ...@@ -68,29 +51,43 @@ export default function PendingView({
error = false, error = false,
setPendingError, setPendingError,
tryActivation, tryActivation,
resetAccountView,
}: { }: {
connector?: AbstractConnector connector?: AbstractConnector
error?: boolean error?: boolean
setPendingError: (error: boolean) => void setPendingError: (error: boolean) => void
tryActivation: (connector: AbstractConnector) => void tryActivation: (connector: AbstractConnector) => void
resetAccountView: () => void
}) { }) {
return ( return (
<PendingSection> <PendingSection>
<LoadingMessage error={error}> <LoadingMessage>
<LoadingWrapper> <LoadingWrapper>
{error ? ( {error ? (
<ErrorGroup> <ErrorGroup>
<div> <ThemedText.MediumHeader marginBottom={12}>
<Trans>Error connecting</Trans> <Trans>Error connecting</Trans>
</div> </ThemedText.MediumHeader>
<ErrorButton <ThemedText.Small marginBottom={36} textAlign="center">
<Trans>
The connection attempt failed. Please click try again and follow the steps to connect in your wallet.
</Trans>
</ThemedText.Small>
<ButtonPrimary
$borderRadius="12px"
padding="12px"
onClick={() => { onClick={() => {
setPendingError(false) setPendingError(false)
connector && tryActivation(connector) connector && tryActivation(connector)
}} }}
> >
<Trans>Try Again</Trans> <Trans>Try Again</Trans>
</ErrorButton> </ButtonPrimary>
<ButtonEmpty width="fit-content" padding="0" marginTop={20}>
<ThemedText.Link fontSize={12} onClick={resetAccountView}>
<Trans>Back to wallet selection</Trans>
</ThemedText.Link>
</ButtonEmpty>
</ErrorGroup> </ErrorGroup>
) : ( ) : (
<> <>
......
...@@ -2,7 +2,7 @@ import { Trans } from '@lingui/macro' ...@@ -2,7 +2,7 @@ import { Trans } from '@lingui/macro'
import { AutoColumn } from 'components/Column' import { AutoColumn } from 'components/Column'
import { PrivacyPolicy } from 'components/PrivacyPolicy' import { PrivacyPolicy } from 'components/PrivacyPolicy'
import Row, { AutoRow, RowBetween } from 'components/Row' import Row, { AutoRow, RowBetween } from 'components/Row'
import { useEffect, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
import { ArrowLeft, ArrowRight, Info } from 'react-feather' import { ArrowLeft, ArrowRight, Info } from 'react-feather'
import ReactGA from 'react-ga4' import ReactGA from 'react-ga4'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
...@@ -150,6 +150,11 @@ export default function WalletModal({ ...@@ -150,6 +150,11 @@ export default function WalletModal({
const previousAccount = usePrevious(account) const previousAccount = usePrevious(account)
const resetAccountView = useCallback(() => {
setPendingError(false)
setWalletView(WALLET_VIEWS.ACCOUNT)
}, [setPendingError, setWalletView])
// close on connection, when logged out before // close on connection, when logged out before
useEffect(() => { useEffect(() => {
if (account && !previousAccount && walletModalOpen) { if (account && !previousAccount && walletModalOpen) {
...@@ -160,10 +165,9 @@ export default function WalletModal({ ...@@ -160,10 +165,9 @@ export default function WalletModal({
// always reset to account view // always reset to account view
useEffect(() => { useEffect(() => {
if (walletModalOpen) { if (walletModalOpen) {
setPendingError(false) resetAccountView()
setWalletView(WALLET_VIEWS.ACCOUNT)
} }
}, [walletModalOpen]) }, [walletModalOpen, resetAccountView])
// close modal when a connection is successful // close modal when a connection is successful
const activePrevious = usePrevious(active) const activePrevious = usePrevious(active)
...@@ -358,12 +362,7 @@ export default function WalletModal({ ...@@ -358,12 +362,7 @@ export default function WalletModal({
</CloseIcon> </CloseIcon>
{walletView !== WALLET_VIEWS.ACCOUNT ? ( {walletView !== WALLET_VIEWS.ACCOUNT ? (
<HeaderRow color="blue"> <HeaderRow color="blue">
<HoverText <HoverText onClick={resetAccountView}>
onClick={() => {
setPendingError(false)
setWalletView(WALLET_VIEWS.ACCOUNT)
}}
>
<ArrowLeft /> <ArrowLeft />
</HoverText> </HoverText>
</HeaderRow> </HeaderRow>
...@@ -383,20 +382,23 @@ export default function WalletModal({ ...@@ -383,20 +382,23 @@ export default function WalletModal({
error={pendingError} error={pendingError}
setPendingError={setPendingError} setPendingError={setPendingError}
tryActivation={tryActivation} tryActivation={tryActivation}
resetAccountView={resetAccountView}
/> />
)} )}
<LightCard> {!pendingError && (
<AutoRow style={{ flexWrap: 'nowrap' }}> <LightCard>
<ThemedText.Black fontSize={14}> <AutoRow style={{ flexWrap: 'nowrap' }}>
<Trans> <ThemedText.Black fontSize={14}>
By connecting a wallet, you agree to Uniswap Labs’{' '} <Trans>
<ExternalLink href="https://uniswap.org/terms-of-service/">Terms of Service</ExternalLink> and By connecting a wallet, you agree to Uniswap Labs’{' '}
acknowledge that you have read and understand the Uniswap{' '} <ExternalLink href="https://uniswap.org/terms-of-service/">Terms of Service</ExternalLink> and
<ExternalLink href="https://uniswap.org/disclaimer/">Protocol Disclaimer</ExternalLink>. acknowledge that you have read and understand the Uniswap{' '}
</Trans> <ExternalLink href="https://uniswap.org/disclaimer/">Protocol Disclaimer</ExternalLink>.
</ThemedText.Black> </Trans>
</AutoRow> </ThemedText.Black>
</LightCard> </AutoRow>
</LightCard>
)}
{walletView !== WALLET_VIEWS.PENDING && ( {walletView !== WALLET_VIEWS.PENDING && (
<> <>
<OptionGrid>{getOptions()}</OptionGrid> <OptionGrid>{getOptions()}</OptionGrid>
......
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