-
Notifications
You must be signed in to change notification settings - Fork 9
feat(dashboard): add the latest finding ticker to the panel #2124
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
62208a6
feat(dashboard): add the latest finding ticker to the panel
brunod-e 7f38063
fix(dashboard): track the ticker label at the design's 0.78px
brunod-e c93d98b
refactor(dashboard): use the named tracking token on the ticker label
brunod-e d1f299d
feat(dashboard): read the panel ticker from the live Paragraph feed
brunod-e 17f0064
fix(dashboard): put a deadline on the Paragraph feed request
brunod-e 93617d0
fix(dashboard): hold the latest finding strip to one line on desktop
brunod-e 4b31090
docs(dashboard): describe the live Paragraph feed in the ticker chang…
brunod-e 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 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,5 @@ | ||
| --- | ||
| "@anticapture/dashboard": minor | ||
| --- | ||
|
|
||
| Add the "Latest finding" ticker between the panel hero and the Monitored DAOs table. The strip shows the newest post on the blockful Paragraph publication, read server-side from its RSS feed and revalidated hourly, and links out to that post. If the feed is unreachable it falls back to the publication index, so the ticker always renders. |
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
27 changes: 27 additions & 0 deletions
27
apps/dashboard/features/panel/components/LatestFindingTicker.tsx
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,27 @@ | ||
| import { ChevronRight } from "lucide-react"; | ||
|
|
||
| import { DefaultLink } from "@/shared/components/design-system/links/default-link/DefaultLink"; | ||
| import { getLatestParagraphPost } from "@/shared/services/paragraph/latestPost"; | ||
|
|
||
| export const LatestFindingTicker = async () => { | ||
| const { title: finding, url: caseUrl } = await getLatestParagraphPost(); | ||
|
|
||
| return ( | ||
| <div className="bg-surface-default flex flex-col gap-2 px-4 py-3 lg:flex-row lg:items-center lg:gap-3.5"> | ||
| <div className="flex flex-1 flex-col gap-1 lg:min-w-0 lg:flex-row lg:items-center lg:gap-3.5"> | ||
| <h2 className="text-primary text-alternative-sm tracking-alternative-sm shrink-0 font-mono font-medium uppercase leading-5"> | ||
| Latest finding | ||
| </h2> | ||
| {/* Post titles come from the feed and run long; the design draws this | ||
| * strip as a single line on desktop, and wraps it on mobile. */} | ||
| <p className="text-secondary text-sm font-normal leading-5 lg:min-w-0 lg:truncate"> | ||
| {finding} | ||
| </p> | ||
| </div> | ||
| <DefaultLink href={caseUrl} variant="highlight" size="sm" openInNewTab> | ||
| Read the case | ||
| <ChevronRight className="size-4" /> | ||
| </DefaultLink> | ||
| </div> | ||
| ); | ||
| }; |
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from "@/features/panel/components/PanelTable"; | ||
| export * from "@/features/panel/components/PanelHero"; | ||
| export * from "@/features/panel/components/LatestFindingTicker"; | ||
| export * from "@/features/panel/components/DaoProtectionLevels"; | ||
| export * from "@/features/panel/components/TooltipCell"; |
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,83 @@ | ||
| // Reader for the blockful publication on Paragraph. Paragraph exposes no JSON | ||
| // API for a blog's posts, so the newest publication is taken from the public | ||
| // RSS 2.0 feed. Server-only: the feed host rejects browser origins. | ||
|
|
||
| const FEED_URL = "https://api.paragraph.com/blogs/rss/@blockful"; | ||
|
|
||
| /** Revalidate window for the feed, in seconds. Posts ship a few times a month. */ | ||
| const REVALIDATE_SECONDS = 3600; | ||
|
|
||
| /** | ||
| * Deadline for the feed request. The ticker is awaited while the homepage | ||
| * renders, so a Paragraph host that accepts the connection and then stalls | ||
| * would hold the whole page open until the transport gives up. Capped so the | ||
| * publication fallback is reached in about the time a reader would wait. | ||
| */ | ||
| const FEED_TIMEOUT_MS = 3000; | ||
|
|
||
| export type ParagraphPost = { | ||
| title: string; | ||
| url: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Rendered when the feed is unreachable so the ticker never ships an empty | ||
| * strip. Points at the publication index, which always resolves. | ||
| */ | ||
| export const PARAGRAPH_PUBLICATION: ParagraphPost = { | ||
| title: "Research that maps DAO governance risks and capture vectors", | ||
| url: "https://paragraph.com/@blockful", | ||
| }; | ||
|
|
||
| const HTML_ENTITIES: Record<string, string> = { | ||
| "&": "&", | ||
| "<": "<", | ||
| ">": ">", | ||
| """: '"', | ||
| "'": "'", | ||
| "'": "'", | ||
| }; | ||
|
|
||
| const decode = (value: string) => | ||
| value | ||
| .replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, "$1") | ||
| .replace( | ||
| /&(?:amp|lt|gt|quot|apos|#39);/g, | ||
| (entity) => HTML_ENTITIES[entity], | ||
| ) | ||
| .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code))) | ||
| .trim(); | ||
|
|
||
| const readTag = (item: string, tag: string) => { | ||
| const match = item.match(new RegExp(`<${tag}[^>]*>([\\s\\S]*?)</${tag}>`)); | ||
| return match ? decode(match[1]) : ""; | ||
| }; | ||
|
|
||
| /** | ||
| * Newest post on the blockful publication. Falls back to the publication index | ||
| * on any transport, timeout, status or parse failure — the panel ticker must | ||
| * render. | ||
| */ | ||
| export const getLatestParagraphPost = async (): Promise<ParagraphPost> => { | ||
| try { | ||
| const response = await fetch(FEED_URL, { | ||
| next: { revalidate: REVALIDATE_SECONDS }, | ||
| signal: AbortSignal.timeout(FEED_TIMEOUT_MS), | ||
| }); | ||
|
|
||
| if (!response.ok) return PARAGRAPH_PUBLICATION; | ||
|
|
||
| const feed = await response.text(); | ||
| const [item] = feed.match(/<item[^>]*>[\s\S]*?<\/item>/) ?? []; | ||
| if (!item) return PARAGRAPH_PUBLICATION; | ||
|
|
||
| const title = readTag(item, "title"); | ||
| const url = readTag(item, "link") || readTag(item, "guid"); | ||
|
|
||
| return title && url.startsWith("http") | ||
| ? { title, url } | ||
| : PARAGRAPH_PUBLICATION; | ||
| } catch { | ||
| return PARAGRAPH_PUBLICATION; | ||
| } | ||
| }; | ||
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.