-
Notifications
You must be signed in to change notification settings - Fork 45
feat: Pool alert banner #1741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Pool alert banner #1741
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e154477
feat: pool alert banner
0xPearce a8f73ab
refactor: replace monad banner alert with pool alert banner
0xPearce 0855012
Merge branch 'warning-phishing-banner' into pool-alert-banner
0xPearce be53538
Merge branch 'main' into pool-alert-banner
0xPearce a4bc1be
feat: implement portal for PoolAlertBanner and update GlobalLayout fo…
0xPearce a4a52c0
refactor: pool alerts splitted into pool banner maessage and user act…
0xPearce d1fa633
fix: ensure pool alerts display messages only when present
0xPearce 9ec9dfd
Revert "fix: ensure pool alerts display messages only when present"
0xPearce fda0c3a
fix: ensure AlertBox display messages only when present
0xPearce d9d755e
refactor: update PoolAlertBanner to use useMemo for portal target and…
0xPearce 14a622e
refactor: rename MessageWrapper to PoolAlertMessage and update usage …
0xPearce 1acfd5d
fix: re-render pool alert banner on breakpoint change
0xPearce da52f40
Merge branch 'main' into pool-alert-banner
0xPearce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { useMemo } from 'react' | ||
| import { createPortal } from 'react-dom' | ||
| import { useIsDesktop } from '@ui-kit/hooks/useBreakpoints' | ||
| import { useDismissBanner } from '@ui-kit/hooks/useLocalStorage' | ||
| import { Banner, BannerProps } from '@ui-kit/shared/ui/Banner' | ||
| import { AlertType, PoolAlert } from '../types/main.types' | ||
|
|
||
| const ONE_DAY_MS = 24 * 60 * 60 * 1000 // 24 hours in milliseconds | ||
|
|
||
| /** Maps AlertType to BannerSeverity */ | ||
| const alertTypeToBannerSeverity: Record<AlertType, BannerProps['severity']> = { | ||
| error: 'alert', | ||
| danger: 'alert', | ||
| warning: 'warning', | ||
| info: 'info', | ||
| '': 'info', | ||
| } | ||
|
|
||
| export const PoolAlertBanner = ({ | ||
| banner, | ||
| poolAlertBannerKey, | ||
| alertType, | ||
| }: { | ||
| banner: NonNullable<PoolAlert['banner']> | ||
| poolAlertBannerKey: string | ||
| alertType: AlertType | ||
| }) => { | ||
| const { shouldShowBanner, dismissBanner } = useDismissBanner(poolAlertBannerKey, ONE_DAY_MS) | ||
| const isDesktop = useIsDesktop() | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps -- isDesktop triggers re-query when header changes (desktop ↔ mobile) | ||
0xPearce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const portalTarget = useMemo(() => document.getElementsByTagName('header')[0], [isDesktop]) | ||
| const severity = alertTypeToBannerSeverity[alertType] | ||
|
|
||
| return ( | ||
| shouldShowBanner && | ||
| portalTarget && | ||
0xPearce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| createPortal( | ||
| <Banner subtitle={banner.subtitle} severity={severity} onClick={dismissBanner} learnMoreUrl={banner.learnMoreUrl}> | ||
| {banner.title} | ||
| </Banner>, | ||
| portalTarget, | ||
| ) | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import Button from '@mui/material/Button' | ||
| import Link from '@mui/material/Link' | ||
| import Stack from '@mui/material/Stack' | ||
| import { ArrowTopRightIcon } from '@ui-kit/shared/icons/ArrowTopRightIcon' | ||
| import { RouterLink } from '@ui-kit/shared/ui/RouterLink' | ||
| import { SizesAndSpaces } from '@ui-kit/themes/design/1_sizes_spaces' | ||
|
|
||
| const { Spacing } = SizesAndSpaces | ||
|
|
||
| export const PoolAlertMessage = ({ children }: { children: React.ReactNode }) => ( | ||
| <Stack | ||
| alignItems="flex-start" | ||
| spacing={Spacing.sm} | ||
| sx={{ | ||
| '& a': { | ||
| wordBreak: 'break-word', | ||
| }, | ||
| }} | ||
| > | ||
| {children} | ||
| </Stack> | ||
| ) | ||
|
|
||
| export const ExternalLink = ({ href, children }: { href: string; children: React.ReactNode }) => ( | ||
0xPearce marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Button | ||
| color="ghost" | ||
| size="extraSmall" | ||
| component={Link} | ||
| sx={{ color: 'currentColor', textUnderlineOffset: '2px', '&:hover': { textDecoration: 'underline' } }} | ||
| endIcon={<ArrowTopRightIcon fontSize={'small'} />} | ||
| href={href} | ||
| target="_blank" | ||
| rel="noreferrer noopener" | ||
| > | ||
| {children} | ||
| </Button> | ||
| ) | ||
|
|
||
| export const InternalLink = ({ href, children }: { href: string; children: React.ReactNode }) => ( | ||
| <Button | ||
| color="ghost" | ||
| size="extraSmall" | ||
| component={RouterLink} | ||
| href={href} | ||
| sx={{ color: 'currentColor', textUnderlineOffset: '2px', '&:hover': { textDecoration: 'underline' } }} | ||
| > | ||
| {children} | ||
| </Button> | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.