-
Notifications
You must be signed in to change notification settings - Fork 13
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 #551 from hats-finance/feature/submissions-in-audits
[Feature] New submissions section on VaultDetailsPage
- Loading branch information
Showing
19 changed files
with
351 additions
and
28 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
...etailsPage/Sections/VaultSubmissionsSection/PublicSubmissionCard/PublicSubmissionCard.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { IVault, IVulnerabilitySeverity } from "@hats-finance/shared"; | ||
import MDEditor from "@uiw/react-md-editor"; | ||
import { Pill } from "components"; | ||
import { allowedElementsMarkdown } from "constants/constants"; | ||
import { getSeveritiesColorsArray } from "hooks/severities/useSeverityRewardInfo"; | ||
import moment from "moment"; | ||
import { IGithubIssue } from "pages/Honeypots/VaultDetailsPage/types"; | ||
import { useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { StyledPublicSubmissionCard } from "./styles"; | ||
|
||
type PublicSubmissionCardProps = { | ||
vault: IVault; | ||
submission: IGithubIssue; | ||
}; | ||
|
||
function PublicSubmissionCard({ vault, submission }: PublicSubmissionCardProps) { | ||
const { t } = useTranslation(); | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const severityColors = getSeveritiesColorsArray(vault); | ||
const severityIndex = | ||
submission.severity && | ||
vault?.description?.severities.findIndex((sev: IVulnerabilitySeverity) => | ||
sev.name.toLowerCase().includes(submission.severity ?? "") | ||
); | ||
|
||
return ( | ||
<StyledPublicSubmissionCard isOpen={isOpen}> | ||
<div className="card-header" onClick={() => setIsOpen((prev) => !prev)}> | ||
<div className="severity"> | ||
<Pill textColor={severityColors[severityIndex ?? 0]} isSeverity text={submission.severity ?? t("noSeverity")} /> | ||
</div> | ||
<p className="date">{moment(submission.createdAt).format("Do MMM YYYY - hh:mma")}</p> | ||
<p className="submission-title">{submission.issueData.issueTitle}</p> | ||
</div> | ||
|
||
<div className="card-content"> | ||
<MDEditor.Markdown | ||
allowedElements={allowedElementsMarkdown} | ||
className="submission-content" | ||
source={submission.issueData.issueDescription | ||
.replace("\n**Submission hash", "\\\n**Submission hash") | ||
.replace("\n**Severity:**", "\\\n**Severity:**")} | ||
/> | ||
</div> | ||
</StyledPublicSubmissionCard> | ||
); | ||
} | ||
|
||
export default PublicSubmissionCard; |
56 changes: 56 additions & 0 deletions
56
...oneypots/VaultDetailsPage/Sections/VaultSubmissionsSection/PublicSubmissionCard/styles.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,56 @@ | ||
import styled, { css } from "styled-components"; | ||
import { getSpacing } from "styles"; | ||
|
||
export const StyledPublicSubmissionCard = styled.div<{ isOpen: boolean }>( | ||
({ isOpen }) => css` | ||
position: relative; | ||
.card-header { | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${getSpacing(1.5)}; | ||
border: 1px solid var(--primary-light); | ||
padding: ${getSpacing(3)} ${getSpacing(4)}; | ||
background: var(--background-2); | ||
cursor: pointer; | ||
transition: 0.2s; | ||
&:hover { | ||
border-color: var(--primary); | ||
} | ||
.date { | ||
position: absolute; | ||
top: ${getSpacing(3)}; | ||
right: ${getSpacing(4)}; | ||
} | ||
.submission-title { | ||
font-size: var(--small); | ||
padding-left: ${getSpacing(1)}; | ||
font-weight: 700; | ||
} | ||
} | ||
.card-content { | ||
overflow: hidden; | ||
height: 0; | ||
${isOpen && | ||
css` | ||
height: auto; | ||
`} | ||
.submission-content { | ||
white-space: normal; | ||
font-size: var(--xsmall); | ||
background: var(--background-3); | ||
padding: ${getSpacing(3)} ${getSpacing(4)}; | ||
color: var(--white); | ||
border: 1px solid var(--primary-light); | ||
border-top: none; | ||
} | ||
} | ||
` | ||
); |
68 changes: 68 additions & 0 deletions
68
...s/Honeypots/VaultDetailsPage/Sections/VaultSubmissionsSection/VaultSubmissionsSection.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { IVault } from "@hats-finance/shared"; | ||
import OpenIcon from "@mui/icons-material/OpenInNewOutlined"; | ||
import { Alert, Button, HatSpinner } from "components"; | ||
import useConfirm from "hooks/useConfirm"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useSavedSubmissions, useVaultRepoName } from "../../hooks"; | ||
import PublicSubmissionCard from "./PublicSubmissionCard/PublicSubmissionCard"; | ||
import { StyledSubmissionsSection } from "./styles"; | ||
|
||
type VaultSubmissionsSectionProps = { | ||
vault: IVault; | ||
noDeployed?: boolean; | ||
}; | ||
|
||
export const VaultSubmissionsSection = ({ vault }: VaultSubmissionsSectionProps) => { | ||
const { t } = useTranslation(); | ||
const confirm = useConfirm(); | ||
|
||
const { data: savedSubmissions, isLoading } = useSavedSubmissions(vault); | ||
const { data: repoName } = useVaultRepoName(vault); | ||
|
||
const goToGithubIssues = async () => { | ||
if (!repoName) return; | ||
|
||
const githubLink = `https://github.com/hats-finance/${repoName}/issues`; | ||
|
||
const wantToGo = await confirm({ | ||
title: t("openGithub"), | ||
titleIcon: <OpenIcon className="mr-2" fontSize="large" />, | ||
description: t("doYouWantToSeeSubmissionsOnGithub"), | ||
cancelText: t("no"), | ||
confirmText: t("yesGo"), | ||
}); | ||
|
||
if (!wantToGo) return; | ||
window.open(githubLink, "_blank"); | ||
}; | ||
|
||
return ( | ||
<StyledSubmissionsSection> | ||
<h2> | ||
{t("submissions")} | ||
|
||
{repoName && ( | ||
<Button className="ml-3" styleType="text" textColor="secondary" onClick={goToGithubIssues}> | ||
{t("seeSubmissionsOnGithub")} | ||
</Button> | ||
)} | ||
</h2> | ||
|
||
{savedSubmissions?.length === 0 && ( | ||
<Alert className="mt-5 mb-5" type="info"> | ||
{t("thereIsNoPublicSubmission")} | ||
</Alert> | ||
)} | ||
|
||
{isLoading && <HatSpinner text={`${t("gettingSubmissions")}...`} />} | ||
|
||
{savedSubmissions && savedSubmissions?.length > 0 && ( | ||
<div className="public-submissions"> | ||
{savedSubmissions.map((submission) => ( | ||
<PublicSubmissionCard key={submission._id} vault={vault} submission={submission} /> | ||
))} | ||
</div> | ||
)} | ||
</StyledSubmissionsSection> | ||
); | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/VaultSubmissionsSection/styles.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,13 @@ | ||
import styled from "styled-components"; | ||
import { getSpacing } from "styles"; | ||
|
||
export const StyledSubmissionsSection = styled.div` | ||
padding-bottom: ${getSpacing(10)}; | ||
.public-submissions { | ||
margin-top: ${getSpacing(3)}; | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${getSpacing(3)}; | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
packages/web/src/pages/Honeypots/VaultDetailsPage/Sections/index.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { VaultRewardsSection } from "./VaultRewardsSection/VaultRewardsSection"; | ||
export { VaultScopeSection } from "./VaultScopeSection/VaultScopeSection"; | ||
export { VaultDepositsSection } from "./VaultDepositsSection/VaultDepositsSection"; | ||
export { VaultSubmissionsSection } from "./VaultSubmissionsSection/VaultSubmissionsSection"; |
Oops, something went wrong.