Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Error page improvements. #1259

Merged
merged 14 commits into from
Aug 26, 2021
Binary file added src/custom/assets/cow-swap/CowError.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 99 additions & 32 deletions src/custom/components/ErrorBoundary/ErrorBoundaryMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,109 @@ import { Trans } from '@lingui/macro'
import React, { ErrorInfo } from 'react'
import store, { AppState } from 'state/index'
import { ExternalLink, TYPE } from 'theme/index'
import Page, { Title } from 'components/Page'
import { AutoColumn } from 'components/Column'
import styled from 'styled-components/macro'
import ReactGA from 'react-ga'
import { getUserAgent } from 'utils/getUserAgent'
import { AutoRow } from 'components/Row'
import { MEDIA_WIDTHS } from '@src/theme'
import CowError from 'assets/cow-swap/CowError.png'

const FallbackWrapper = styled.div`
const AppWrapper = styled.div`
display: flex;
flex-direction: column;
width: 100%;
flex-flow: column;
align-items: center;
z-index: 1;
min-height: 100vh;
overflow-x: hidden;
`

const Wrapper = styled(Page)`
display: flex;
flex-direction: column;
width: 100vw;
max-width: 60vw;
margin: 120px 0;

@media screen and (max-width: ${MEDIA_WIDTHS.upToSmall}px) {
max-width: 95vw;
margin: 0 0 80px;
}
`

const BodyWrapper = styled.div<{ margin?: string }>`
padding: 1rem;
const StyledTitle = styled(Title)`
@media screen and (max-width: ${MEDIA_WIDTHS.upToSmall}px) {
text-align: center;
}
`

const FlexContainer = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem 0 0.5rem 0;

@media screen and (max-width: ${MEDIA_WIDTHS.upToMedium}px) {
flex-direction: column;
align-items: center;
}
`
const HeaderWrapper = styled.div`
${({ theme }) => theme.flexRowNoWrap}
width: 100%;
white-space: pre;
justify-content: space-between;
position: fixed;
top: 0;
z-index: 2;
@media screen and (max-width: ${MEDIA_WIDTHS.upToSmall}px) {
position: relative;
}
`

export const LogoImage = styled.img.attrs((props) => ({
src: props.theme.logo.src,
alt: props.theme.logo.alt,
width: props.theme.logo.width,
height: props.theme.logo.height,
}))`
object-fit: contain;

${({ theme }) => theme.mediaWidth.upToSmall`
width: 150px;
`};
`

const CowLogo = styled.div`
display: flex;
margin: 1rem;
transition: transform 0.3s ease;

&:hover {
transform: rotate(-5deg);
}
`
const CodeBlockWrapper = styled.div`
background: ${({ theme }) => theme.bg1};
background: ${({ theme }) => theme.bg4};
overflow: auto;
white-space: pre;
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.01), 0px 4px 8px rgba(0, 0, 0, 0.04), 0px 16px 24px rgba(0, 0, 0, 0.04),
0px 24px 32px rgba(0, 0, 0, 0.01);
border-radius: 24px;
padding: 50px;
border-radius: 16px;
padding: 16px;
color: ${({ theme }) => theme.text2};

${({ theme }) => theme.mediaWidth.upToSmall`
padding: 12px;
width: auto;
`};
`

const LinkWrapper = styled.div`
color: ${({ theme }) => theme.blue1};
padding: 6px 24px;
const StyledParagraph = styled.p`
overflow-x: auto;
`

const SomethingWentWrongWrapper = styled.div`
const LinkWrapper = styled.div`
color: ${({ theme }) => theme.blue1};
padding: 6px 24px;
`

Expand Down Expand Up @@ -69,32 +135,34 @@ export default class ErrorBoundary extends React.Component<unknown, ErrorBoundar
if (error !== null) {
const encodedBody = encodeURIComponent(issueBody(error))
return (
<FallbackWrapper>
<BodyWrapper>
<AppWrapper>
<HeaderWrapper>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anxolin As you anticipated, I have some problems with the header links. Maybe because the header is inside the ErrorBoundary.
Can we try to fix that or maybe we can show only the CowSwap logo to go back to the home.

Copy link
Contributor

@anxolin anxolin Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simplify as u suggest. An alternative header, with just a Logo suffices.

The less logic we add there, the less chances we break it. So I would add only HTML Markup, not logics that can fail

<a href=".">
<CowLogo>
<LogoImage />
</CowLogo>
</a>
</HeaderWrapper>
<Wrapper>
<FlexContainer>
<StyledTitle>
<Trans> Something went wrong</Trans>
</StyledTitle>
<img src={CowError} alt="CowSwap Error" height="125" />
</FlexContainer>
<AutoColumn gap={'md'}>
<SomethingWentWrongWrapper>
<TYPE.label fontSize={24} fontWeight={600}>
<Trans>
<span role="img" aria-label="cow-exclamation">
🐮❕
</span>{' '}
Something went wrong
</Trans>
</TYPE.label>
</SomethingWentWrongWrapper>
<CodeBlockWrapper>
<code>
<TYPE.main fontSize={10} color={'text1'}>
{error.stack}
<StyledParagraph>{error.stack}</StyledParagraph>
</TYPE.main>
Copy link
Contributor Author

@alongoni alongoni Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a review along with @matextrem, we came to the conclusion that it is not a CSS problem.
It is related how the error is interpreted and rendered on iOS (Safari and Chrome). The complete message is not stored directly in the error, as it happens in other platforms and devices.

For example on Safari we get:

GI@https://pr1259--gpswapui.review.gnosisdev.com/static/js/main.1856fc78.chunk.js:1:585424 ro@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2473681 Js@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2526140 Su@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2513314 Eu@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2513242 Tu@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2513105 mu@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2510071 mu@[native code] https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2459449 https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2536868 Gi@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2459395 Ji@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2459330 fu@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2507440 Oo@https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:2479007 Oo@[native code] https://pr1259--gpswapui.review.gnosisdev.com/static/js/4.262e7757.chunk.js:2:281441 promiseReactionJob@[native code]

image

Instead of:

Error: This cow is dropping some serious milk 🥛!!
    at CowGamePage (http://localhost:3000/static/js/main.chunk.js:43233:11)
    at renderWithHooks (http://localhost:3000/static/js/vendors~main.chunk.js:236075:22)
    at mountIndeterminateComponent (http://localhost:3000/static/js/vendors~main.chunk.js:238837:17)
    at beginWork (http://localhost:3000/static/js/vendors~main.chunk.js:240036:20)
    at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/vendors~main.chunk.js:225025:18)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/vendors~main.chunk.js:225074:20)
    at invokeGuardedCallback (http://localhost:3000/static/js/vendors~main.chunk.js:225134:35)
    at beginWork$1 (http://localhost:3000/static/js/vendors~main.chunk.js:244876:11)
    at performUnitOfWork (http://localhost:3000/static/js/vendors~main.chunk.js:243712:16)
    at workLoopSync (http://localhost:3000/static/js/vendors~main.chunk.js:243649:9)
    at renderRootSync (http://localhost:3000/static/js/vendors~main.chunk.js:243615:11)
    at performSyncWorkOnRoot (http://localhost:3000/static/js/vendors~main.chunk.js:243232:22)
    at http://localhost:3000/static/js/vendors~main.chunk.js:232485:30
    at unstable_runWithPriority (http://localhost:3000/static/js/vendors~main.chunk.js:307490:16)
    at runWithPriority$1 (http://localhost:3000/static/js/vendors~main.chunk.js:232431:14)
    at flushSyncCallbackQueueImpl (http://localhost:3000/static/js/vendors~main.chunk.js:232480:13)
    at flushSyncCallbackQueue (http://localhost:3000/static/js/vendors~main.chunk.js:232468:7)
    at discreteUpdates$1 (http://localhost:3000/static/js/vendors~main.chunk.js:243360:13)
    at discreteUpdates (http://localhost:3000/static/js/vendors~main.chunk.js:224835:16)
    at dispatchDiscreteEvent (http://localhost:3000/static/js/vendors~main.chunk.js:227017:7)

</code>
</CodeBlockWrapper>
<AutoRow>
<LinkWrapper>
<ExternalLink
id="create-github-issue-link"
// href={`https://github.com/Uniswap/uniswap-interface/issues/new?assignees=&labels=bug&body=${encodedBody}&title=${encodeURIComponent(
href={`https://github.com/gnosis/cowswap/issues/new?assignees=&labels=bug&body=${encodedBody}&title=${encodeURIComponent(
href={`https://github.com/gnosis/cowswap/issues/new?assignees=&labels=🐞 Bug,🔥 Critical&body=${encodedBody}&title=${encodeURIComponent(
henrypalacios marked this conversation as resolved.
Show resolved Hide resolved
`Crash report: \`${error.name}${error.message && `: ${error.message}`}\``
)}`}
target="_blank"
Expand All @@ -106,7 +174,6 @@ export default class ErrorBoundary extends React.Component<unknown, ErrorBoundar
</ExternalLink>
</LinkWrapper>
<LinkWrapper>
{/* <ExternalLink id="get-support-on-discord" href="https://discord.gg/FCfyBSbCU5" target="_blank"> */}
<ExternalLink id="get-support-on-discord" href="https://chat.cowswap.exchange/" target="_blank">
<TYPE.link fontSize={16}>
<Trans>Get support on Discord</Trans>
Expand All @@ -116,8 +183,8 @@ export default class ErrorBoundary extends React.Component<unknown, ErrorBoundar
</LinkWrapper>
</AutoRow>
</AutoColumn>
</BodyWrapper>
</FallbackWrapper>
</Wrapper>
</AppWrapper>
)
}
return this.props.children
Expand Down