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 { darken } from 'polished'
import { ButtonEmpty, ButtonPrimary } from 'components/Button'
import styled from 'styled-components/macro'
import { ThemedText } from 'theme'
import { AbstractConnector } from 'web3-react-abstract-connector'
......@@ -23,12 +23,11 @@ const LoaderContainer = styled.div`
justify-content: center;
`
const LoadingMessage = styled.div<{ error?: boolean }>`
const LoadingMessage = styled.div`
${({ theme }) => theme.flexRowNoWrap};
align-items: center;
justify-content: center;
border-radius: 12px;
color: ${({ theme, error }) => (error ? theme.red1 : 'inherit')};
& > * {
padding: 1rem;
......@@ -36,27 +35,11 @@ const LoadingMessage = styled.div<{ error?: boolean }>`
`
const ErrorGroup = styled.div`
${({ theme }) => theme.flexRowNoWrap};
${({ theme }) => theme.flexColumnNoWrap};
align-items: center;
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`
${({ theme }) => theme.flexColumnNoWrap};
align-items: center;
......@@ -68,29 +51,43 @@ export default function PendingView({
error = false,
setPendingError,
tryActivation,
resetAccountView,
}: {
connector?: AbstractConnector
error?: boolean
setPendingError: (error: boolean) => void
tryActivation: (connector: AbstractConnector) => void
resetAccountView: () => void
}) {
return (
<PendingSection>
<LoadingMessage error={error}>
<LoadingMessage>
<LoadingWrapper>
{error ? (
<ErrorGroup>
<div>
<ThemedText.MediumHeader marginBottom={12}>
<Trans>Error connecting</Trans>
</div>
<ErrorButton
</ThemedText.MediumHeader>
<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={() => {
setPendingError(false)
connector && tryActivation(connector)
}}
>
<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>
) : (
<>
......
......@@ -2,7 +2,7 @@ import { Trans } from '@lingui/macro'
import { AutoColumn } from 'components/Column'
import { PrivacyPolicy } from 'components/PrivacyPolicy'
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 ReactGA from 'react-ga4'
import styled from 'styled-components/macro'
......@@ -150,6 +150,11 @@ export default function WalletModal({
const previousAccount = usePrevious(account)
const resetAccountView = useCallback(() => {
setPendingError(false)
setWalletView(WALLET_VIEWS.ACCOUNT)
}, [setPendingError, setWalletView])
// close on connection, when logged out before
useEffect(() => {
if (account && !previousAccount && walletModalOpen) {
......@@ -160,10 +165,9 @@ export default function WalletModal({
// always reset to account view
useEffect(() => {
if (walletModalOpen) {
setPendingError(false)
setWalletView(WALLET_VIEWS.ACCOUNT)
resetAccountView()
}
}, [walletModalOpen])
}, [walletModalOpen, resetAccountView])
// close modal when a connection is successful
const activePrevious = usePrevious(active)
......@@ -358,12 +362,7 @@ export default function WalletModal({
</CloseIcon>
{walletView !== WALLET_VIEWS.ACCOUNT ? (
<HeaderRow color="blue">
<HoverText
onClick={() => {
setPendingError(false)
setWalletView(WALLET_VIEWS.ACCOUNT)
}}
>
<HoverText onClick={resetAccountView}>
<ArrowLeft />
</HoverText>
</HeaderRow>
......@@ -383,8 +382,10 @@ export default function WalletModal({
error={pendingError}
setPendingError={setPendingError}
tryActivation={tryActivation}
resetAccountView={resetAccountView}
/>
)}
{!pendingError && (
<LightCard>
<AutoRow style={{ flexWrap: 'nowrap' }}>
<ThemedText.Black fontSize={14}>
......@@ -397,6 +398,7 @@ export default function WalletModal({
</ThemedText.Black>
</AutoRow>
</LightCard>
)}
{walletView !== WALLET_VIEWS.PENDING && (
<>
<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