-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathBasic.tsx
More file actions
103 lines (93 loc) · 2.76 KB
/
Basic.tsx
File metadata and controls
103 lines (93 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { useEffect } from 'react'
import { useErrorBoundary, withErrorBoundary } from 'react-use-error-boundary'
import styled, { css } from 'styled-components'
import { useAccount, useSwitchChain } from 'wagmi'
import ErrorScreen from '@app/components/@atoms/ErrorScreen'
import { getSupportedChainById } from '@app/constants/chains'
import { useSetupIntercom } from '@app/hooks/useSetupIntercom'
import { Navigation } from './Navigation'
const Container = styled.div(
({ theme }) => css`
--padding-size: ${theme.space['4']};
padding: var(--padding-size);
display: flex;
flex-gap: ${theme.space['4']};
gap: ${theme.space['4']};
flex-direction: column;
align-items: stretch;
@supports (-webkit-touch-callout: none) {
/*
hack for iOS/iPadOS Safari
width should always be 100% - total padding
*/
width: calc(100% - calc(var(--padding-size) * 2));
box-sizing: content-box;
}
@media (min-width: ${theme.breakpoints.sm}px) {
--padding-size: ${theme.space['8']};
gap: ${theme.space['6']};
flex-gap: ${theme.space['6']};
}
`,
)
const ContentWrapper = styled.div(
({ theme }) => css`
max-width: ${theme.space['192']};
width: 100%;
align-self: center;
flex-grow: 1;
display: flex;
flex-direction: column;
gap: ${theme.space['4']};
flex-gap: ${theme.space['4']};
`,
)
const BottomPlaceholder = styled.div(
({ theme }) => css`
height: ${theme.space['14']};
@media (min-width: ${theme.breakpoints.sm}px) {
height: ${theme.space['12']};
}
`,
)
const shouldSwitchChain = ({
isConnected,
hasProgrammaticChainSwitching,
isPending,
isError,
chainId,
}: {
isConnected: boolean
hasProgrammaticChainSwitching: boolean
isPending: boolean
isError: boolean
chainId?: number
}) =>
isConnected &&
hasProgrammaticChainSwitching &&
!isPending &&
!isError &&
!getSupportedChainById(chainId)
export const Basic = withErrorBoundary(({ children }: { children: React.ReactNode }) => {
const { chainId, connector, isConnected } = useAccount()
const hasProgrammaticChainSwitching = Boolean(connector?.switchChain)
const { switchChain, isPending, isError } = useSwitchChain()
useSetupIntercom()
const [error] = useErrorBoundary()
useEffect(() => {
if (
shouldSwitchChain({ isConnected, hasProgrammaticChainSwitching, isPending, isError, chainId })
) {
switchChain({ chainId: 1 })
}
}, [isConnected, hasProgrammaticChainSwitching, isPending, isError, chainId, switchChain])
return (
<Container className="min-safe">
<Navigation />
<ContentWrapper>
{error ? <ErrorScreen errorType="application-error" /> : children}
</ContentWrapper>
<BottomPlaceholder />
</Container>
)
})