-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5224 from cowprotocol/release/2024-12-17
Release/2024 12 17
- Loading branch information
Showing
67 changed files
with
847 additions
and
380 deletions.
There are no files selected for viewing
Binary file not shown.
61 changes: 61 additions & 0 deletions
61
apps/cowswap-frontend/src/common/hooks/useAnnouncements.ts
This file contains 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,61 @@ | ||
import { useAtomValue } from 'jotai' | ||
import { useMemo } from 'react' | ||
|
||
import { isProdLike } from '@cowprotocol/common-utils' | ||
import { Announcement, Announcements, announcementsAtom } from '@cowprotocol/core' | ||
import { CowEnv, SupportedChainId } from '@cowprotocol/cow-sdk' | ||
|
||
function getAnnouncementSpecificity(chainId: SupportedChainId, env: CowEnv, announcement: Announcement): number { | ||
let specificity = 0 | ||
|
||
const matchesChain = announcement.chainIds.some((announcementChain) => announcementChain === chainId) | ||
const matchesEnv = announcement.envs.some((announcementEnv) => announcementEnv === env) | ||
const matchesEveryChain = announcement.chainIds.length === 0 | ||
const matchesEveryEnv = announcement.envs.length === 0 | ||
|
||
if (matchesChain) specificity += 2 | ||
if (matchesEnv) specificity += 2 | ||
if (matchesEveryChain) specificity += 1 | ||
if (matchesEveryEnv) specificity += 1 | ||
|
||
return specificity | ||
} | ||
|
||
function useAnnouncements(chainId: SupportedChainId): Announcements { | ||
const allAnnouncements = useAtomValue(announcementsAtom) | ||
|
||
return useMemo(() => { | ||
const env = isProdLike ? 'prod' : 'staging' | ||
|
||
const filtered = allAnnouncements | ||
.filter((announcement) => { | ||
const showForEveryChain = announcement.chainIds.length === 0 | ||
const showForEveryEnv = announcement.envs.length === 0 | ||
|
||
const matchesChainId = announcement.chainIds.some((announcementChain) => announcementChain === chainId) | ||
const matchesEnv = announcement.envs.some((announcementEnv) => announcementEnv === env) | ||
|
||
return (showForEveryChain || matchesChainId) && (showForEveryEnv || matchesEnv) | ||
}) | ||
.sort((a, b) => { | ||
const specificityA = getAnnouncementSpecificity(chainId, env, a) | ||
const specificityB = getAnnouncementSpecificity(chainId, env, b) | ||
|
||
return specificityB - specificityA | ||
}) | ||
|
||
return filtered | ||
}, [chainId, allAnnouncements]) | ||
} | ||
|
||
export function useCriticalAnnouncements(chainId: SupportedChainId): Announcements { | ||
const announcements = useAnnouncements(chainId) | ||
|
||
return announcements.filter(({ isCritical }) => isCritical) | ||
} | ||
|
||
export function useNonCriticalAnnouncements(chainId: SupportedChainId): Announcements { | ||
const announcements = useAnnouncements(chainId) | ||
|
||
return announcements.filter(({ isCritical }) => !isCritical) | ||
} |
19 changes: 19 additions & 0 deletions
19
apps/cowswap-frontend/src/common/hooks/useCmsAnnouncements.ts
This file contains 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,19 @@ | ||
import { CmsAnnouncements, getAnnouncements } from '@cowprotocol/core' | ||
|
||
import ms from 'ms.macro' | ||
import useSWR, { SWRConfiguration } from 'swr' | ||
|
||
const ANNOUNCEMENTS_SWR_CONFIG: SWRConfiguration = { | ||
refreshInterval: ms`5min`, // we do need to show this sort of ASAP | ||
refreshWhenHidden: false, | ||
refreshWhenOffline: false, | ||
revalidateOnFocus: false, | ||
} | ||
|
||
const EMPTY_VALUE: CmsAnnouncements = [] | ||
|
||
export function useCmsAnnouncements() { | ||
const { data } = useSWR<CmsAnnouncements, Error, string>('/announcements', getAnnouncements, ANNOUNCEMENTS_SWR_CONFIG) | ||
|
||
return data || EMPTY_VALUE | ||
} |
This file contains 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
20 changes: 20 additions & 0 deletions
20
apps/cowswap-frontend/src/common/updaters/AnnouncementsUpdater.ts
This file contains 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,20 @@ | ||
import { useSetAtom } from 'jotai' | ||
import { useEffect } from 'react' | ||
|
||
import { announcementsAtom, mapCmsAnnouncementsToAnnouncements } from '@cowprotocol/core' | ||
|
||
import { useCmsAnnouncements } from 'common/hooks/useCmsAnnouncements' | ||
|
||
export function AnnouncementsUpdater() { | ||
const setAnnouncements = useSetAtom(announcementsAtom) | ||
|
||
const cmsAnnouncements = useCmsAnnouncements() | ||
|
||
useEffect(() => { | ||
const announcements = mapCmsAnnouncementsToAnnouncements(cmsAnnouncements) | ||
|
||
announcements && setAnnouncements(announcements) | ||
}, [cmsAnnouncements, setAnnouncements]) | ||
|
||
return null | ||
} |
43 changes: 15 additions & 28 deletions
43
apps/cowswap-frontend/src/legacy/components/Header/URLWarning/index.tsx
This file contains 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 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 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 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 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
Oops, something went wrong.