Skip to content

Commit

Permalink
Merge pull request #554 from hats-finance/develop
Browse files Browse the repository at this point in the history
[Feature] Submissions page on vault details + fixed max rewards
  • Loading branch information
fonstack authored Oct 2, 2023
2 parents 1ece132 + 8aca204 commit 4058721
Show file tree
Hide file tree
Showing 75 changed files with 1,287 additions and 266 deletions.
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hats-finance/shared",
"version": "1.1.22",
"version": "1.1.28",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./mdAllowedElements";
49 changes: 49 additions & 0 deletions packages/shared/src/constants/mdAllowedElements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export const allowedElementsMarkdown = [
"a",
"article",
"b",
"blockquote",
"br",
"caption",
"code",
"del",
"details",
"div",
"em",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"hr",
"i",
"img",
"ins",
"kbd",
"li",
"main",
"ol",
"p",
"pre",
"section",
"span",
"strike",
"strong",
"sub",
"summary",
"sup",
"table",
"tbody",
"td",
"th",
"thead",
"tr",
"u",
"ul",
];

export const allowedAttributesMarkdown = {
a: ["href", "name", "class"],
img: ["src", "alt", "class"],
};
1 change: 1 addition & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./severities";
export * from "./abis";
export * from "./config";
export * from "./utils";
export * from "./constants";
2 changes: 2 additions & 0 deletions packages/shared/src/types/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export interface IBaseEditedVaultDescription {
name: string;
tokenIcon: string;
type?: IVaultType;
isPrivateAudit?: boolean;
whitelist: { address: string }[];
endtime?: number;
starttime?: number;
emails: IEditedCommunicationEmail[];
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./types";
export * from "./editor";
export * from "./payout";
export * from "./safe";
export * from "./submissions";
6 changes: 6 additions & 0 deletions packages/shared/src/types/submissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type ISubmissionMessageObject = {
ref?: string;
isEncryptedByHats?: boolean;
decrypted: string | undefined;
encrypted: string;
};
6 changes: 5 additions & 1 deletion packages/shared/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ISubmissionMessageObject } from "./submissions";

export interface IVaultInfo {
version: IVault["version"];
address: string;
Expand Down Expand Up @@ -120,6 +122,8 @@ interface IBaseVaultDescription {
name: string;
tokenIcon: string;
type?: IVaultType;
isPrivateAudit?: boolean;
whitelist: { address: string }[];
endtime?: number;
starttime?: number;
oneLiner?: string;
Expand Down Expand Up @@ -274,7 +278,7 @@ export interface ISubmittedSubmission {
subId: string;
submissionIdx: number;
submissionHash: string;
submissionData?: string;
submissionData?: ISubmissionMessageObject;
submissionDecrypted?: string;
linkedVault?: IVault;
submissionDataStructure?: {
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/src/utils/vaults.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isAddressAMultisigMember } from "./gnosis.utils";
import { isValidIpfsHash } from "./ipfs.utils";
import { fixObject } from "./vaultEditor.utils";

export type IVaultInfoWithCommittee = IVaultInfo & { committee: string };
export type IVaultInfoWithCommittee = IVaultInfo & { committee: string; registered: boolean };

export const getAllVaultsInfoWithCommittee = async (): Promise<IVaultInfoWithCommittee[]> => {
try {
Expand All @@ -14,6 +14,7 @@ export const getAllVaultsInfoWithCommittee = async (): Promise<IVaultInfoWithCom
vaults {
id
pid
registered
version
committee
master {
Expand Down Expand Up @@ -54,6 +55,7 @@ export const getAllVaultsInfoWithCommittee = async (): Promise<IVaultInfoWithCom
pid: vault.pid,
version: vault.version,
committee: vault.committee,
registered: vault.registered,
});
}
}
Expand All @@ -76,6 +78,7 @@ export const getVaultInfoWithCommittee = async (
vaults(where: {id: $vaultId}) {
id
pid
registered
version
committee
master {
Expand Down Expand Up @@ -109,6 +112,7 @@ export const getVaultInfoWithCommittee = async (
pid: vault.pid,
version: vault.version,
committee: vault.committee,
registered: vault.registered,
};
} catch (error) {
return undefined;
Expand Down
7 changes: 4 additions & 3 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"downloadjs": "^1.4.7",
"ethers": "5.7.2",
"fs": "^0.0.1-security",
"graphql": "^16.5.0",
"graphql": "^16.8.1",
"https-browserify": "^1.0.0",
"humanize-duration": "^3.27.0",
"i18next": "^21.8.4",
Expand All @@ -57,7 +57,7 @@
"react-app-rewired": "^2.2.1",
"react-confetti": "^6.1.0",
"react-dom": "^18.1.0",
"react-hook-form": "^7.42.1",
"react-hook-form": "^7.46.2",
"react-https-redirect": "^1.1.0",
"react-i18next": "^11.16.9",
"react-minimal-pie-chart": "^8.4.0",
Expand Down Expand Up @@ -115,7 +115,8 @@
"react-content-loader": "^6.2.1",
"react-helmet": "^6.1.0",
"react-identicons": "^1.2.5",
"sanitize-markdown": "^2.6.7",
"siwe": "^1.1.6",
"uuid-by-string": "^4.0.0"
}
}
}
23 changes: 13 additions & 10 deletions packages/web/sitemap-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ const buildSitemap = async () => {
});
});

const subgraphResults = (await Promise.all(subgraphPromises)
.then((responses) => responses.map((res) => res.data))
.catch((error) => {
console.error("Error fetching subgraph data:", error);
}))
const subgraphResults = (
await Promise.all(subgraphPromises)
.then((responses) => responses.map((res) => res.data))
.catch((error) => {
console.error("Error fetching subgraph data:", error);
})
)
.filter((res) => res != null)
.map((res) => res.data.vaults)
.flat()
Expand All @@ -71,7 +73,8 @@ const buildSitemap = async () => {
const descriptionsData = await Promise.all(descriptionsResults.map((res) => res.data));
const descriptionsDataWithHash = descriptionsData.map((d) => ({ ...d, hash: descriptionHashes[descriptionsData.indexOf(d)] }));
const descriptions = descriptionsDataWithHash.filter((d) => !(d instanceof Error));
const vaultsRoutes = descriptions.map((d) => {
const descriptionsNoPrivateAudits = descriptions.filter((d) => !d["project-metadata"]?.isPrivateAudit);
const vaultsRoutes = descriptionsNoPrivateAudits.map((d) => {
const vaultId = subgraphResults.find((vault) => vault.descriptionHash === d.hash).id;
const vaultSlug = slugify(d["project-metadata"]?.name ?? d["Project-metadata"]?.name ?? "");
const isAudit =
Expand All @@ -93,15 +96,15 @@ const buildSitemap = async () => {

const vaultsRoutesXml = vaultsRoutes.reduce(
(acc, route) => `${acc}
${appendPathAndGenerateUrl(route, 'rewards')}
${appendPathAndGenerateUrl(route, 'deposits')}
${appendPathAndGenerateUrl(route, 'scope')}`,
${appendPathAndGenerateUrl(route, "rewards")}
${appendPathAndGenerateUrl(route, "deposits")}
${appendPathAndGenerateUrl(route, "scope")}`,
""
);

const routesXml = routes.reduce(
(acc, route) => `${acc}
${appendPathAndGenerateUrl(route, '')}`,
${appendPathAndGenerateUrl(route, "")}`,
""
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type FormInputProps = {
copyable?: boolean;
disabled?: boolean;
removable?: boolean;
flexExpand?: boolean;
colorable?: boolean;
isDirty?: boolean;
noMargin?: boolean;
Expand All @@ -35,6 +36,7 @@ function FormInputComponent(
pastable = false,
copyable = false,
removable = false,
flexExpand = false,
noErrorLabel = false,
type = "text",
colorable = false,
Expand Down Expand Up @@ -220,6 +222,7 @@ function FormInputComponent(
colorable={colorable}
readOnly={readOnly}
className={className}
flexExpand={flexExpand}
>
<div className="main-container">
{label !== undefined && (
Expand Down
5 changes: 4 additions & 1 deletion packages/web/src/components/FormControls/FormInput/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type StyledFormInputProps = {
colorable?: boolean;
readOnly?: boolean;
disabled?: boolean;
flexExpand?: boolean;
type?: FormInputType;
};

Expand All @@ -31,11 +32,13 @@ export const StyledFormInput = styled.div<StyledFormInputProps>(
disabled,
colorable,
readOnly,
flexExpand,
}) => css`
position: relative;
overflow: hidden;
margin-bottom: ${noMargin ? 0 : getSpacing(3)};
width: 100%;
width: ${flexExpand ? "unset" : "100%"};
flex: ${flexExpand ? 1 : "unset"};
.main-container {
position: relative;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { allowedElementsMarkdown } from "@hats-finance/shared";
import MDEditor, { PreviewType } from "@uiw/react-md-editor";
import { disallowedElementsMarkdown } from "constants/constants";
import { forwardRef } from "react";
import { parseIsDirty } from "../utils";
import { StyledFormMDEditor } from "./styles";
Expand Down Expand Up @@ -37,7 +37,7 @@ export const FormMDEditorComponent = (
>
<MDEditor
value={value}
previewOptions={{ disallowedElements: disallowedElementsMarkdown }}
previewOptions={{ allowedElements: allowedElementsMarkdown }}
onChange={(value) => (disabled ? undefined : onChange(value ?? ""))}
minHeight={200}
height={400}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface FormSelectInputProps {
disabled?: boolean;
noMargin?: boolean;
readOnly?: boolean;
flexExpand?: boolean;
isDirty?: boolean | boolean[];
value: string | string[];
onChange?: (data: string | string[]) => void;
Expand All @@ -43,6 +44,7 @@ export function FormSelectInputComponent(
disabled = false,
isDirty = false,
readOnly = false,
flexExpand = false,
noMargin = false,
emptyState,
error,
Expand Down Expand Up @@ -85,7 +87,7 @@ export function FormSelectInputComponent(
};

return (
<StyledFormSelectInput ref={menuRef} noMargin={noMargin}>
<StyledFormSelectInput ref={menuRef} noMargin={noMargin} flexExpand={flexExpand}>
{label && <label className="input-label">{label}</label>}

<SelectButton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import styled, { css } from "styled-components";
import { getSpacing } from "styles";

export const StyledFormSelectInput = styled.div<{ noMargin: boolean }>(
({ noMargin }) => css`
export const StyledFormSelectInput = styled.div<{ noMargin: boolean; flexExpand: boolean }>(
({ noMargin, flexExpand }) => css`
position: relative;
margin-bottom: ${noMargin ? 0 : getSpacing(3)};
width: 100%;
width: ${flexExpand ? "unset" : "100%"};
flex: ${flexExpand ? 1 : "unset"};
label.input-label {
display: block;
Expand Down
26 changes: 26 additions & 0 deletions packages/web/src/components/Sidebar/NavLinks/NavLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function NavLinks() {
const { chain } = useNetwork();
const { address } = useAccount();

const [isInvitedToPrivateAudits, setIsInvitedToPrivateAudits] = useState(false);
const [isCommitteeAddress, setIsCommitteeAddress] = useState(false);
const [showCommitteeToolsSubroutes, setshowCommitteeToolsSubroutes] = useState(false);
const committeeToolsSubrouteRef = useRef<HTMLDivElement>(null);
Expand All @@ -37,6 +38,21 @@ export default function NavLinks() {
setshowCommitteeToolsSubroutes(false);
};

useEffect(() => {
if (!allVaultsOnEnv || !address) return setIsInvitedToPrivateAudits(false);

const isInvited =
allVaultsOnEnv.some(
(vault) =>
vault.description?.["project-metadata"].isPrivateAudit &&
vault.description?.["project-metadata"].whitelist.some(
(whiteAddress) => whiteAddress.address.toLowerCase() === address.toLowerCase()
)
) ?? false;

setIsInvitedToPrivateAudits(isInvited);
}, [allVaultsOnEnv, address]);

useEffect(() => {
const verifyIfCommitteeAddress = async () => {
try {
Expand Down Expand Up @@ -69,6 +85,16 @@ export default function NavLinks() {
<p className="normal">{t("auditCompetitions")}</p>
<p className="collapsed">{t("competitions")}</p>
</StyledNavLink>
<StyledNavLink
hidden={!isInvitedToPrivateAudits}
className="audits"
to={`${HoneypotsRoutePaths.privateAudits}`}
onClick={handleClick}
>
<AuditsIcon />
<p className="normal">{t("privateAuditCompetitions")}</p>
<p className="collapsed">{t("privateCompetitions")}</p>
</StyledNavLink>
{/* <StyledNavLink className="vulnerability" to={RoutePaths.vulnerability} onClick={handleClick}>
<SubmissionsIcon />
<p className="normal">{t("submitVulnerability")}</p>
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/VaultCard/VaultCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const VaultCard = ({
? millify(totalPaidOutOnAudit?.usd ?? 0)
: showIntended
? millify(vault.amountsInfo?.competitionIntendedAmount?.deposited.usd ?? 0)
: millify(vault.amountsInfo?.depositedAmount.usd ?? 0)}
: millify(vault.amountsInfo?.maxRewardAmount.usd ?? 0)}
</h3>
</WithTooltip>
<div className="sub-value">
Expand Down
Loading

0 comments on commit 4058721

Please sign in to comment.