Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 897cade

Browse files
authored
Feat: new app banner with redirect (#4108)
1 parent 5bf0906 commit 897cade

3 files changed

Lines changed: 71 additions & 112 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { ReactElement, useEffect, useState } from 'react'
2+
3+
const Countdown = ({
4+
children,
5+
seconds,
6+
onEnd,
7+
}: {
8+
children: (count: ReactElement) => ReactElement
9+
seconds: number
10+
onEnd: () => void
11+
}): ReactElement | null => {
12+
const [countdown, setCountdown] = useState<number>(seconds)
13+
const [cancel, setCancel] = useState<boolean>(false)
14+
15+
useEffect(() => {
16+
if (cancel) return
17+
18+
const interval = setInterval(() => {
19+
if (cancel) {
20+
clearInterval(interval)
21+
return
22+
}
23+
24+
setCountdown((prevCountdown) => {
25+
if (prevCountdown === 1) {
26+
clearInterval(interval)
27+
onEnd()
28+
}
29+
30+
return prevCountdown - 1
31+
})
32+
}, 1000)
33+
34+
return () => clearInterval(interval)
35+
}, [onEnd, cancel])
36+
37+
return cancel ? null : (
38+
<>
39+
{children(<span style={{ display: 'inline-block', width: '1em' }}>{countdown}</span>)}{' '}
40+
<a onClick={() => setCancel(true)}>Cancel</a>
41+
</>
42+
)
43+
}
44+
45+
export default Countdown

src/components/PsaBanner/index.module.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212

1313
.banner a {
1414
color: inherit;
15+
font-weight: bold;
16+
text-decoration: none;
17+
}
18+
19+
.banner a:hover {
20+
text-decoration: underline;
21+
}
22+
23+
.banner a:not([href]) {
24+
text-decoration: underline;
25+
cursor: pointer;
1526
}
1627

1728
.wrapper {

src/components/PsaBanner/index.tsx

Lines changed: 15 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -6,120 +6,23 @@ import { currentChainId } from 'src/logic/config/store/selectors'
66
import { hasFeature } from 'src/logic/safe/utils/safeVersion'
77
import useCachedState from 'src/utils/storage/useCachedState'
88
import styles from './index.module.scss'
9+
import Countdown from './Countdown'
910

10-
const BANNERS = {
11-
'4': <>🚨 Rinkeby will be deprecated by the end of October 2022. Please migrate to Görli. 🚨</>,
11+
const NEW_URL = 'https://app.safe.global'
1212

13-
'1313161554': (
14-
<>
15-
🚨 On <b>17.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on Aurora, during which the
16-
functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
17-
<a
18-
target="_blank"
19-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
20-
rel="noreferrer"
21-
>
22-
More information
23-
</a>{' '}
24-
🚨
25-
</>
26-
),
27-
'42161': (
28-
<>
29-
🚨 On <b>17.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on Arbitrum, during which the
30-
functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
31-
<a
32-
target="_blank"
33-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
34-
rel="noreferrer"
35-
>
36-
More information
37-
</a>{' '}
38-
🚨
39-
</>
40-
),
41-
'43114': (
42-
<>
43-
🚨 On <b>17.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on Avalanche, during which the
44-
functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
45-
<a
46-
target="_blank"
47-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
48-
rel="noreferrer"
49-
>
50-
More information
51-
</a>{' '}
52-
🚨
53-
</>
54-
),
55-
'10': (
56-
<>
57-
🚨 On <b>17.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on Optimism, during which the
58-
functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
59-
<a
60-
target="_blank"
61-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
62-
rel="noreferrer"
63-
>
64-
More information
65-
</a>{' '}
66-
🚨
67-
</>
68-
),
69-
'137': (
70-
<>
71-
🚨 On <b>18.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on Polygon, during which the
72-
functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
73-
<a
74-
target="_blank"
75-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
76-
rel="noreferrer"
77-
>
78-
More information
79-
</a>{' '}
80-
🚨
81-
</>
82-
),
83-
'56': (
84-
<>
85-
🚨 On <b>18.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on BNB Smart Chain, during which the
86-
functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
87-
<a
88-
target="_blank"
89-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
90-
rel="noreferrer"
91-
>
92-
More information
93-
</a>{' '}
94-
🚨
95-
</>
96-
),
97-
'100': (
98-
<>
99-
🚨 On <b>20.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on Gnosis Chain, during which the
100-
functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
101-
<a
102-
target="_blank"
103-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
104-
rel="noreferrer"
105-
>
106-
More information
107-
</a>{' '}
108-
🚨
109-
</>
110-
),
111-
'1': (
13+
const redirectToNewApp = (): void => {
14+
const path = window.location.pathname.replace(/^\/app/, '')
15+
window.location.replace(NEW_URL + path)
16+
}
17+
18+
const BANNERS: Record<string, ReactElement | string> = {
19+
'*': (
11220
<>
113-
🚨 On <b>24.10.2022 @ 9am CEST</b> we will be undertaking indexer maintenance on Ethereum mainnet, during which
114-
the functionality of this application might be restricted. Please expect downtime of 2-3 hours.{' '}
115-
<a
116-
target="_blank"
117-
href="https://forum.gnosis-safe.io/t/transaction-service-migration-october-2022/1550"
118-
rel="noreferrer"
119-
>
120-
More information
121-
</a>{' '}
122-
🚨
21+
⚠️ Safe&apos;s new official URL is <a href={NEW_URL}>app.safe.global</a>.<br />
22+
Please update your bookmarks.{' '}
23+
<Countdown seconds={10} onEnd={redirectToNewApp}>
24+
{(count) => <>Redirecting in {count} seconds...</>}
25+
</Countdown>
12326
</>
12427
),
12528
}
@@ -128,7 +31,7 @@ const WARNING_BANNER = 'WARNING_BANNER'
12831

12932
const PsaBanner = (): ReactElement | null => {
13033
const chainId = useSelector(currentChainId)
131-
const banner = BANNERS[chainId]
34+
const banner = BANNERS[chainId] || BANNERS['*']
13235
const isEnabled = hasFeature(WARNING_BANNER as FEATURES)
13336
const [closed = false, setClosed] = useCachedState<boolean>(`${WARNING_BANNER}_${chainId}_closed`, true)
13437

0 commit comments

Comments
 (0)