Skip to content

feat: add return types for functions #825

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

Merged
merged 5 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 8 additions & 30 deletions web/src/components/DisputeCard/DisputeInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import styled from "styled-components";
import { Periods } from "consts/periods";
import LawBalanceIcon from "svgs/icons/law-balance.svg";
import BookmarkIcon from "svgs/icons/bookmark.svg";
import PileCoinsIcon from "svgs/icons/pile-coins.svg";
import CalendarIcon from "svgs/icons/calendar.svg";
import LawBalanceIcon from "svgs/icons/law-balance.svg";
import PileCoinsIcon from "svgs/icons/pile-coins.svg";
import Field from "../Field";

const Container = styled.div`
Expand All @@ -13,7 +13,7 @@ const Container = styled.div`
gap: 8px;
`;

const getPeriodPhrase = (period: Periods) => {
const getPeriodPhrase = (period: Periods): string => {
switch (period) {
case Periods.evidence:
return "Voting Starts";
Expand All @@ -35,36 +35,14 @@ export interface IDisputeInfo {
date?: number;
}

const DisputeInfo: React.FC<IDisputeInfo> = ({
courtId,
court,
category,
rewards,
period,
date,
}) => {
const DisputeInfo: React.FC<IDisputeInfo> = ({ courtId, court, category, rewards, period, date }) => {
return (
<Container>
{category && (
<Field icon={BookmarkIcon} name="Category" value={category} />
)}
{court && courtId && (
<Field
icon={LawBalanceIcon}
name="Court"
value={court}
link={`/courts/${courtId}`}
/>
)}
{rewards && (
<Field icon={PileCoinsIcon} name="Juror Rewards" value={rewards} />
)}
{category && <Field icon={BookmarkIcon} name="Category" value={category} />}
{court && courtId && <Field icon={LawBalanceIcon} name="Court" value={court} link={`/courts/${courtId}`} />}
{rewards && <Field icon={PileCoinsIcon} name="Juror Rewards" value={rewards} />}
{typeof period !== "undefined" && date && (
<Field
icon={CalendarIcon}
name={getPeriodPhrase(period)}
value={new Date(date * 1000).toLocaleString()}
/>
<Field icon={CalendarIcon} name={getPeriodPhrase(period)} value={new Date(date * 1000).toLocaleString()} />
)}
</Container>
);
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/DisputeCard/PeriodBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Container = styled.div<Omit<IPeriodBanner, "id">>`
}};
`;

const getPeriodLabel = (period: Periods) => {
const getPeriodLabel = (period: Periods): string => {
switch (period) {
case Periods.appeal:
return "Crowdfunding Appeal";
Expand Down
9 changes: 2 additions & 7 deletions web/src/hooks/queries/useCasesQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ export type { CasesPageQuery };

const casesQuery = gql`
query CasesPage($skip: Int) {
disputes(
first: 3
skip: $skip
orderBy: lastPeriodChange
orderDirection: desc
) {
disputes(first: 3, skip: $skip, orderBy: lastPeriodChange, orderDirection: desc) {
id
arbitrated {
id
Expand All @@ -30,7 +25,7 @@ const casesQuery = gql`
}
`;

export const useCasesQuery = (skip: number) => {
export const useCasesQuery = (skip: number): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR({
query: casesQuery,
variables: { skip: skip },
Expand Down
4 changes: 3 additions & 1 deletion web/src/hooks/queries/useClassicAppealQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const classicAppealQuery = gql`
}
`;

export const useClassicAppealQuery = (id?: string | number) => {
export const useClassicAppealQuery = (
id?: string | number
): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR(() =>
typeof id !== "undefined"
? {
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/queries/useCourtDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const courtDetailsQuery = gql`
}
`;

export const useCourtDetails = (id?: string) => {
export const useCourtDetails = (id?: string): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR(
id
? {
Expand Down
6 changes: 2 additions & 4 deletions web/src/hooks/queries/useCourtPolicyURI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const courtPolicyURIQuery = gql`
}
`;

export const useCourtPolicyURI = (id?: string | number) => {
export const useCourtPolicyURI = (id?: string | number): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWRImmutable(() =>
typeof id !== "undefined"
? {
Expand All @@ -20,8 +20,6 @@ export const useCourtPolicyURI = (id?: string | number) => {
}
: false
);
const result = data
? (data.court.policy as CourtPolicyUriQuery.court.policy)
: undefined;
const result = data ? (data.court.policy as CourtPolicyUriQuery.court.policy) : undefined;
return { data: result, error, isValidating };
};
2 changes: 1 addition & 1 deletion web/src/hooks/queries/useCourtTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const courtTreeQuery = gql`
}
`;

export const useCourtTree = () => {
export const useCourtTree = (): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR({
query: courtTreeQuery,
});
Expand Down
4 changes: 3 additions & 1 deletion web/src/hooks/queries/useDisputeDetailsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const disputeDetailsQuery = gql`
}
`;

export const useDisputeDetailsQuery = (id?: string | number) => {
export const useDisputeDetailsQuery = (
id?: string | number
): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR(() =>
typeof id !== "undefined"
? {
Expand Down
9 changes: 3 additions & 6 deletions web/src/hooks/queries/useDisputeKitClassicMultipliers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ export const useDisputeKitClassicMultipliers = () => {
() => (disputeKitClassic ? `Multipliers` : false),
async () => {
if (!disputeKitClassic) return;
const winner_stake_multiplier =
await disputeKitClassic.WINNER_STAKE_MULTIPLIER();
const loser_stake_multiplier =
await disputeKitClassic.LOSER_STAKE_MULTIPLIER();
const loser_appeal_period_multiplier =
await disputeKitClassic.LOSER_APPEAL_PERIOD_MULTIPLIER();
const winner_stake_multiplier = await disputeKitClassic.WINNER_STAKE_MULTIPLIER();
const loser_stake_multiplier = await disputeKitClassic.LOSER_STAKE_MULTIPLIER();
const loser_appeal_period_multiplier = await disputeKitClassic.LOSER_APPEAL_PERIOD_MULTIPLIER();
return {
winner_stake_multiplier,
loser_stake_multiplier,
Expand Down
5 changes: 4 additions & 1 deletion web/src/hooks/queries/useDrawQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const drawQuery = gql`
}
`;

export const useDrawQuery = (address?: string | null, disputeID?: string) => {
export const useDrawQuery = (
address?: string | null,
disputeID?: string
): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR({
query: drawQuery,
variables: { address, disputeID },
Expand Down
8 changes: 2 additions & 6 deletions web/src/hooks/queries/useEvidences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export type { EvidencesQuery };

const evidencesQuery = gql`
query Evidences($evidenceGroup: String) {
evidences(
where: { evidenceGroup: $evidenceGroup }
orderBy: id
orderDirection: asc
) {
evidences(where: { evidenceGroup: $evidenceGroup }, orderBy: id, orderDirection: asc) {
id
evidence
sender {
Expand All @@ -19,7 +15,7 @@ const evidencesQuery = gql`
}
`;

export const useEvidences = (evidenceGroup?: string) => {
export const useEvidences = (evidenceGroup?: string): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR(() =>
typeof evidenceGroup !== "undefined"
? {
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/queries/useHomePageQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const homePageQuery = gql`
}
`;

export const useHomePageQuery = (timeframe: number) => {
export const useHomePageQuery = (timeframe: number): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR({
query: homePageQuery,
variables: { timeframe: timeframe.toString() },
Expand Down
8 changes: 2 additions & 6 deletions web/src/hooks/queries/useJurorBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import useSWR from "swr";
import { KlerosCore } from "@kleros/kleros-v2-contracts/typechain-types/src/arbitration/KlerosCore";
import { useConnectedContract } from "../useConnectedContract";

export const useJurorBalance = (
user?: string | null,
courtId?: string | undefined
) => {
export const useJurorBalance = (user?: string | null, courtId?: string | undefined) => {
const klerosCore = useConnectedContract("KlerosCore") as KlerosCore;
return useSWR(
() =>
klerosCore && user && courtId ? `JurorBalance{address}{courtId}` : false,
() => (klerosCore && user && courtId ? `JurorBalance${user}${courtId}` : false),
async () => {
if (klerosCore && user && courtId) {
return await klerosCore.getJurorBalance(user, courtId);
Expand Down
7 changes: 2 additions & 5 deletions web/src/hooks/queries/usePNKAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import { CONTRACTS } from "utils/getContract";
export const usePNKAllowance = (user?: string | null) => {
const pnkContract = useConnectedContract("PNK") as PNK;
return useSWR(
() => (pnkContract && user ? `PNKAllowance{user}` : false),
() => (pnkContract && user ? `PNKAllowance${user}` : false),
async () => {
if (pnkContract && user) {
return await pnkContract.allowance(
user,
CONTRACTS["KlerosCore"].address
);
return await pnkContract.allowance(user, CONTRACTS["KlerosCore"].address);
} else {
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/queries/useVotingHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const votingHistoryQuery = gql`
}
`;

export const useVotingHistory = (disputeID?: string) => {
export const useVotingHistory = (disputeID?: string): { data: typeof result; error: any; isValidating: boolean } => {
const { data, error, isValidating } = useSWR(() =>
typeof disputeID !== "undefined"
? {
Expand Down
7 changes: 2 additions & 5 deletions web/src/hooks/useParsedAmount.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { useMemo } from "react";
import { BigNumber, utils } from "ethers";

export function useParsedAmount(amount: string) {
return useMemo(
() => (amount === "" ? BigNumber.from(0) : utils.parseUnits(amount, 18)),
[amount]
);
export function useParsedAmount(amount: string): BigNumber {
return useMemo(() => (amount === "" ? BigNumber.from(0) : utils.parseUnits(amount, 18)), [amount]);
}
35 changes: 10 additions & 25 deletions web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState } from "react";
import styled from "styled-components";
import Modal from "react-modal";
import { Textarea, Button } from "@kleros/ui-components-library";
import { DisputeKitClassic } from "@kleros/kleros-v2-contracts/typechain-types/src/arbitration/dispute-kits/DisputeKitClassic";
import { wrapWithToast } from "utils/wrapWithToast";
import { Button, Textarea } from "@kleros/ui-components-library";
import { DisputeKitClassic } from "@kleros/kleros-v2-contracts/typechain-types/src/arbitration/dispute-kits/DisputeKitClassic";
import { useConnectedContract } from "hooks/useConnectedContract";
import { uploadFormDataToIPFS } from "utils/uploadFormDataToIPFS";

Expand All @@ -12,26 +12,15 @@ const SubmitEvidenceModal: React.FC<{
evidenceGroup: string;
close: () => void;
}> = ({ isOpen, evidenceGroup, close }) => {
const disputeKit = useConnectedContract(
"DisputeKitClassic"
) as DisputeKitClassic;
const disputeKit = useConnectedContract("DisputeKitClassic") as DisputeKitClassic;
const [isSending, setIsSending] = useState(false);
const [message, setMessage] = useState("");
return (
<StyledModal {...{ isOpen }}>
<h1>Submit New Evidence</h1>
<StyledTextArea
value={message}
onChange={(e) => setMessage(e.target.value)}
placeholder="Your Arguments"
/>
<StyledTextArea value={message} onChange={(e) => setMessage(e.target.value)} placeholder="Your Arguments" />
<ButtonArea>
<Button
variant="secondary"
disabled={isSending}
text="Return"
onClick={close}
/>
<Button variant="secondary" disabled={isSending} text="Return" onClick={close} />
<Button
text="Submit"
isLoading={isSending}
Expand All @@ -44,9 +33,7 @@ const SubmitEvidenceModal: React.FC<{
const response = await res.json();
if (res.status === 200) {
const cid = "/ipfs/" + response["cid"];
await wrapWithToast(
disputeKit.submitEvidence(evidenceGroup, cid)
).then(() => {
await wrapWithToast(disputeKit.submitEvidence(evidenceGroup, cid)).then(() => {
setMessage("");
close();
});
Expand All @@ -61,13 +48,11 @@ const SubmitEvidenceModal: React.FC<{
);
};

const constructEvidence = (msg: string) => {
const constructEvidence = (msg: string): FormData => {
const formData = new FormData();
const file = new File(
[JSON.stringify({ name: "Evidence", description: msg })],
"evidence.json",
{ type: "text/plain" }
);
const file = new File([JSON.stringify({ name: "Evidence", description: msg })], "evidence.json", {
type: "text/plain",
});
formData.append("data", file, file.name);
return formData;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import React from "react";
import styled from "styled-components";
import { useParams } from "react-router-dom";
import { BigNumber, utils } from "ethers";

import { useJurorBalance } from "queries/useJurorBalance";
import { useWeb3 } from "hooks/useWeb3";

import Field from "components/Field";
import PNKIcon from "svgs/icons/pnk.svg";
import LockerIcon from "svgs/icons/locker.svg";
import DiceIcon from "svgs/icons/dice.svg";
import LockerIcon from "svgs/icons/locker.svg";
import PNKIcon from "svgs/icons/pnk.svg";

const format = (value: BigNumber | undefined) =>
value !== undefined ? utils.formatEther(value) : "0";
const format = (value: BigNumber | undefined): string => (value !== undefined ? utils.formatEther(value) : "0");

const JurorBalanceDisplay = () => {
const { id } = useParams();
Expand Down
2 changes: 1 addition & 1 deletion web/src/utils/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getCurrentTime() {
export function getCurrentTime(): number {
return Math.floor(Date.now() / 1000);
}

Expand Down