2021-07-07 05:38:47 +03:00
|
|
|
import { useActiveWeb3React } from 'hooks/web3'
|
2021-06-29 03:34:35 +03:00
|
|
|
import { useEffect } from 'react'
|
2021-07-07 05:38:47 +03:00
|
|
|
import { useDarkModeManager } from 'state/user/hooks'
|
2021-09-22 02:21:28 +03:00
|
|
|
|
2021-06-29 03:34:35 +03:00
|
|
|
import { SupportedChainId } from '../constants/chains'
|
2021-07-07 05:38:47 +03:00
|
|
|
|
|
|
|
const initialStyles = {
|
|
|
|
width: '200vw',
|
|
|
|
height: '200vh',
|
|
|
|
transform: 'translate(-50vw, -100vh)',
|
|
|
|
}
|
|
|
|
const backgroundResetStyles = {
|
|
|
|
width: '100vw',
|
|
|
|
height: '100vh',
|
|
|
|
transform: 'unset',
|
|
|
|
}
|
|
|
|
|
|
|
|
type TargetBackgroundStyles = typeof initialStyles | typeof backgroundResetStyles
|
2021-06-29 03:34:35 +03:00
|
|
|
|
|
|
|
const backgroundRadialGradientElement = document.getElementById('background-radial-gradient')
|
2021-07-07 05:38:47 +03:00
|
|
|
const setBackground = (newValues: TargetBackgroundStyles) =>
|
|
|
|
Object.entries(newValues).forEach(([key, value]) => {
|
|
|
|
if (backgroundRadialGradientElement) {
|
|
|
|
backgroundRadialGradientElement.style[key as keyof typeof backgroundResetStyles] = value
|
|
|
|
}
|
|
|
|
})
|
2021-06-29 03:34:35 +03:00
|
|
|
export default function RadialGradientByChainUpdater(): null {
|
|
|
|
const { chainId } = useActiveWeb3React()
|
2021-07-07 05:38:47 +03:00
|
|
|
const [darkMode] = useDarkModeManager()
|
2021-06-29 03:34:35 +03:00
|
|
|
// manage background color
|
|
|
|
useEffect(() => {
|
|
|
|
if (!backgroundRadialGradientElement) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-07 05:38:47 +03:00
|
|
|
switch (chainId) {
|
|
|
|
case SupportedChainId.ARBITRUM_ONE:
|
2021-07-12 18:44:05 +03:00
|
|
|
case SupportedChainId.ARBITRUM_RINKEBY:
|
2021-07-07 05:38:47 +03:00
|
|
|
setBackground(backgroundResetStyles)
|
|
|
|
const arbitrumLightGradient = 'radial-gradient(150% 100% at 50% 0%, #CDE8FB 0%, #FCF3F9 50%, #FFFFFF 100%)'
|
|
|
|
const arbitrumDarkGradient = 'radial-gradient(150% 100% at 50% 0%, #0A294B 0%, #221E30 50%, #1F2128 100%)'
|
|
|
|
backgroundRadialGradientElement.style.background = darkMode ? arbitrumDarkGradient : arbitrumLightGradient
|
|
|
|
break
|
|
|
|
case SupportedChainId.OPTIMISM:
|
2021-07-12 18:44:05 +03:00
|
|
|
case SupportedChainId.OPTIMISTIC_KOVAN:
|
2021-07-07 05:38:47 +03:00
|
|
|
setBackground(backgroundResetStyles)
|
|
|
|
const optimismLightGradient = 'radial-gradient(150% 100% at 50% 0%, #FFFBF2 2%, #FFF4F9 53%, #FFFFFF 100%)'
|
|
|
|
const optimismDarkGradient = 'radial-gradient(150% 100% at 50% 0%, #3E2E38 2%, #2C1F2D 53%, #1F2128 100%)'
|
|
|
|
backgroundRadialGradientElement.style.background = darkMode ? optimismDarkGradient : optimismLightGradient
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
setBackground(initialStyles)
|
|
|
|
backgroundRadialGradientElement.style.background = ''
|
2021-06-29 03:34:35 +03:00
|
|
|
}
|
2021-07-07 05:38:47 +03:00
|
|
|
}, [darkMode, chainId])
|
2021-06-29 03:34:35 +03:00
|
|
|
return null
|
|
|
|
}
|