From 5a3d0a07f696449390177cacbfc67e6ec3d363a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Podsiad=C5=82y?= <67391475+sdlyy@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:16:22 +0100 Subject: [PATCH] Two sub-section risk summary (#5695) --- .../get-da-project-risk-summary-section.ts | 40 ++++++--- .../[layer]/_utils/get-project-details.tsx | 7 +- .../components/projects/project-details.tsx | 9 ++ .../da-risk-summary-section.stories.tsx | 62 ++++++++++++++ .../sections/da-risk-summary-section.tsx | 82 +++++++++++++++++++ .../sections/risk-summary-section.tsx | 60 +++++++------- .../src/components/projects/sections/types.ts | 7 ++ 7 files changed, 226 insertions(+), 41 deletions(-) create mode 100644 packages/frontend/src/components/projects/sections/da-risk-summary-section.stories.tsx create mode 100644 packages/frontend/src/components/projects/sections/da-risk-summary-section.tsx diff --git a/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-da-project-risk-summary-section.ts b/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-da-project-risk-summary-section.ts index 9864877dc8b..284585b35f5 100644 --- a/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-da-project-risk-summary-section.ts +++ b/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-da-project-risk-summary-section.ts @@ -3,7 +3,7 @@ import { type DaLayer, type ScalingProjectRisk, } from '@l2beat/config' -import { type RiskSummarySectionProps } from '~/components/projects/sections/risk-summary-section' +import { type DaRiskSummarySectionProps } from '~/components/projects/sections/da-risk-summary-section' import { type ProjectSectionProps } from '~/components/projects/sections/types' import { groupRisks } from '~/utils/project/risk-summary/group-risks' @@ -11,8 +11,8 @@ export function getDaProjectRiskSummarySection( layer: DaLayer, bridge: DaBridge, isVerified: boolean, -): Omit { - const sections = [ +): Omit { + const bridgeSections = [ { id: 'contracts', value: @@ -20,26 +20,44 @@ export function getDaProjectRiskSummarySection( ? bridge.contracts : { risks: [] }, }, - { - id: 'da-layer-technology', - value: layer.technology, - }, { id: 'da-bridge-technology', value: bridge.technology, }, ] - const risks: (ScalingProjectRisk & { referencedId: string })[] = [] + const layerSections = [ + { + id: 'da-layer-technology', + value: layer.technology, + }, + ] - for (const { id, value } of sections) { + const layerRisks: (ScalingProjectRisk & { referencedId: string })[] = [] + + for (const { id, value } of layerSections) { + if (value.risks) { + layerRisks.push(...value.risks.map((x) => ({ ...x, referencedId: id }))) + } + } + + const bridgeRisks: (ScalingProjectRisk & { referencedId: string })[] = [] + + for (const { id, value } of bridgeSections) { if (value.risks) { - risks.push(...value.risks.map((x) => ({ ...x, referencedId: id }))) + bridgeRisks.push(...value.risks.map((x) => ({ ...x, referencedId: id }))) } } return { - riskGroups: groupRisks(risks), + layer: { + name: layer.display.name, + risks: groupRisks(layerRisks), + }, + bridge: { + name: bridge.display.name, + risks: groupRisks(bridgeRisks), + }, warning: bridge.display.warning, isVerified, redWarning: undefined, diff --git a/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-project-details.tsx b/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-project-details.tsx index a855040cf15..858c0ec4380 100644 --- a/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-project-details.tsx +++ b/packages/frontend/src/app/(top-nav)/data-availability/projects/[layer]/_utils/get-project-details.tsx @@ -158,9 +158,12 @@ export function getProjectDetails({ const items: ProjectDetailsSection[] = [] - if (riskSummarySection.riskGroups.length > 0) { + if ( + riskSummarySection.layer.risks.concat(riskSummarySection.bridge.risks) + .length > 0 + ) { items.push({ - type: 'RiskSummarySection', + type: 'DaRiskSummarySection', props: { id: 'risk-summary', title: 'Risk summary', diff --git a/packages/frontend/src/components/projects/project-details.tsx b/packages/frontend/src/components/projects/project-details.tsx index 7871894b756..e8fb9d52a5d 100644 --- a/packages/frontend/src/components/projects/project-details.tsx +++ b/packages/frontend/src/components/projects/project-details.tsx @@ -4,6 +4,7 @@ import { cn } from '~/utils/cn' import { ChartSection } from './sections/chart-section' import { ContractsSection } from './sections/contracts/contracts-section' import { MultiChainContractsSection } from './sections/contracts/multichain-contracts-section' +import { DaRiskSummarySection } from './sections/da-risk-summary-section' import { DetailedDescriptionSection } from './sections/detailed-description-section' import { GrissiniRiskAnalysisSection } from './sections/grissini-risk-analysis-section' import { GroupSection } from './sections/group-section' @@ -71,6 +72,14 @@ export function ProjectDetails(props: ProjectDetailsProps) { {...item.props} /> ) + case 'DaRiskSummarySection': + return ( + + ) case 'RiskAnalysisSection': return ( +export default meta + +type Story = StoryObj + +const risks: RiskGroup[] = [ + { + name: 'Funds can be stolen if', + start: 1, + items: [ + { + text: "a dishonest supermajority of Celestia validators finalizes an unavailable block, and there aren't light nodes on the network verifying data availability, or they fail at social signaling unavailable data.", + isCritical: true, + referencedId: '', + }, + { + text: "a dishonest supermajority of Celestia validators finalizes an unavailable block, and there aren't light nodes on the network verifying data availability, or they fail at social signaling unavailable data.", + isCritical: true, + referencedId: '', + }, + ], + }, + { + name: 'Funds can be frozen if', + start: 3, + items: [ + { + text: 'the centralized validator goes down. Users cannot produce blocks themselves and exiting the system requires new block production.', + isCritical: true, + referencedId: '', + }, + ], + }, +] as const + +export const Default: Story = { + args: { + layer: { + name: 'DA Layer', + risks, + }, + bridge: { + name: 'Bridge', + risks, + }, + }, +} diff --git a/packages/frontend/src/components/projects/sections/da-risk-summary-section.tsx b/packages/frontend/src/components/projects/sections/da-risk-summary-section.tsx new file mode 100644 index 00000000000..baf1dbc4763 --- /dev/null +++ b/packages/frontend/src/components/projects/sections/da-risk-summary-section.tsx @@ -0,0 +1,82 @@ +import { HorizontalSeparator } from '~/components/core/horizontal-separator' +import { WarningBar } from '~/components/warning-bar' +import { ShieldIcon } from '~/icons/shield' +import { UnverifiedIcon } from '~/icons/unverified' +import { ProjectSection } from './project-section' +import { EnumeratedRisks, type RiskGroup } from './risk-summary-section' +import { type ProjectSectionProps } from './types' + +export interface DaRiskSummarySectionProps extends ProjectSectionProps { + layer: { + risks: RiskGroup[] + name: string + } + bridge: { + risks: RiskGroup[] + name: string + } + warning: string | undefined + isVerified: boolean | undefined + redWarning: string | undefined +} + +export function DaRiskSummarySection({ + layer, + bridge, + isVerified, + redWarning, + warning, + ...sectionProps +}: DaRiskSummarySectionProps) { + if (layer.risks.concat(bridge.risks).length === 0) { + return null + } + return ( + + {isVerified === false && ( + + )} + {redWarning && ( + + )} + {warning && ( + + )} + {layer.risks.length > 0 && ( +
+ + {layer.name} risks + + +
+ )} + {layer.risks.length > 0 && bridge.risks.length > 0 && ( + + )} + {bridge.risks.length > 0 && ( +
+ + {bridge.name} risks + + +
+ )} +
+ ) +} diff --git a/packages/frontend/src/components/projects/sections/risk-summary-section.tsx b/packages/frontend/src/components/projects/sections/risk-summary-section.tsx index 6e0f9ae705b..e0d676b7c0b 100644 --- a/packages/frontend/src/components/projects/sections/risk-summary-section.tsx +++ b/packages/frontend/src/components/projects/sections/risk-summary-section.tsx @@ -6,6 +6,7 @@ import { import { WarningBar } from '~/components/warning-bar' import { ShieldIcon } from '~/icons/shield' import { UnverifiedIcon } from '~/icons/unverified' +import { cn } from '~/utils/cn' import { ProjectSection } from './project-section' import { type ProjectSectionProps } from './types' @@ -68,34 +69,37 @@ export function RiskSummarySection({ className="mt-4" /> )} - {riskGroups.map((group, i) => ( - - ))} +
+ +
) } + +export function EnumeratedRisks({ risks }: { risks: RiskGroup[] }) { + return risks.map((group, i) => ( +
0 && 'mt-4 md:mt-6')} key={i}> +

{group.name}

+
    + {group.items.map((item, i) => ( +
  1. + + {item.isCritical ? ( + <> + {item.text.slice(0, -1)}{' '} + (CRITICAL) + {item.text.slice(-1)} + + ) : ( + item.text + )} + +
  2. + ))} +
+
+ )) +} diff --git a/packages/frontend/src/components/projects/sections/types.ts b/packages/frontend/src/components/projects/sections/types.ts index 7ccb6a4e42d..a56f199def3 100644 --- a/packages/frontend/src/components/projects/sections/types.ts +++ b/packages/frontend/src/components/projects/sections/types.ts @@ -1,6 +1,7 @@ import { type ChartSectionProps } from './chart-section' import { type ContractsSectionProps } from './contracts/contracts-section' import { type MultiChainContractsSectionProps } from './contracts/multichain-contracts-section' +import { type DaRiskSummarySectionProps } from './da-risk-summary-section' import { type DetailedDescriptionSectionProps } from './detailed-description-section' import { type GrissiniRiskAnalysisSectionProps } from './grissini-risk-analysis-section' import { type GroupSectionProps } from './group-section' @@ -70,6 +71,11 @@ export interface ProjectDetailsRiskSummarySection { props: ProjectDetailsProps } +export interface ProjectDetailsDaRiskSummarySection { + type: 'DaRiskSummarySection' + props: ProjectDetailsProps +} + export interface ProjectDetailsRiskAnalysisSection { type: 'RiskAnalysisSection' props: ProjectDetailsProps @@ -152,6 +158,7 @@ export type ProjectDetailsSection = { | ProjectDetailsDetailedDescriptionSection | ProjectDetailsMilestonesAndIncidentsSection | ProjectDetailsRiskSummarySection + | ProjectDetailsDaRiskSummarySection | ProjectDetailsRiskAnalysisSection | L3ProjectDetailsRiskAnalysisSection | ProjectDetailsStageSection