Skip to content

Commit 2861d39

Browse files
authored
Merge pull request #825 from kleros/feat(web)/add-function-return-types
feat: add return types for functions
2 parents 2739c3e + 2e7547d commit 2861d39

19 files changed

+52
-109
lines changed

web/src/components/DisputeCard/DisputeInfo.tsx

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
22
import styled from "styled-components";
33
import { Periods } from "consts/periods";
4-
import LawBalanceIcon from "svgs/icons/law-balance.svg";
54
import BookmarkIcon from "svgs/icons/bookmark.svg";
6-
import PileCoinsIcon from "svgs/icons/pile-coins.svg";
75
import CalendarIcon from "svgs/icons/calendar.svg";
6+
import LawBalanceIcon from "svgs/icons/law-balance.svg";
7+
import PileCoinsIcon from "svgs/icons/pile-coins.svg";
88
import Field from "../Field";
99

1010
const Container = styled.div`
@@ -13,7 +13,7 @@ const Container = styled.div`
1313
gap: 8px;
1414
`;
1515

16-
const getPeriodPhrase = (period: Periods) => {
16+
const getPeriodPhrase = (period: Periods): string => {
1717
switch (period) {
1818
case Periods.evidence:
1919
return "Voting Starts";
@@ -35,36 +35,14 @@ export interface IDisputeInfo {
3535
date?: number;
3636
}
3737

38-
const DisputeInfo: React.FC<IDisputeInfo> = ({
39-
courtId,
40-
court,
41-
category,
42-
rewards,
43-
period,
44-
date,
45-
}) => {
38+
const DisputeInfo: React.FC<IDisputeInfo> = ({ courtId, court, category, rewards, period, date }) => {
4639
return (
4740
<Container>
48-
{category && (
49-
<Field icon={BookmarkIcon} name="Category" value={category} />
50-
)}
51-
{court && courtId && (
52-
<Field
53-
icon={LawBalanceIcon}
54-
name="Court"
55-
value={court}
56-
link={`/courts/${courtId}`}
57-
/>
58-
)}
59-
{rewards && (
60-
<Field icon={PileCoinsIcon} name="Juror Rewards" value={rewards} />
61-
)}
41+
{category && <Field icon={BookmarkIcon} name="Category" value={category} />}
42+
{court && courtId && <Field icon={LawBalanceIcon} name="Court" value={court} link={`/courts/${courtId}`} />}
43+
{rewards && <Field icon={PileCoinsIcon} name="Juror Rewards" value={rewards} />}
6244
{typeof period !== "undefined" && date && (
63-
<Field
64-
icon={CalendarIcon}
65-
name={getPeriodPhrase(period)}
66-
value={new Date(date * 1000).toLocaleString()}
67-
/>
45+
<Field icon={CalendarIcon} name={getPeriodPhrase(period)} value={new Date(date * 1000).toLocaleString()} />
6846
)}
6947
</Container>
7048
);

web/src/components/DisputeCard/PeriodBanner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const Container = styled.div<Omit<IPeriodBanner, "id">>`
5454
}};
5555
`;
5656

57-
const getPeriodLabel = (period: Periods) => {
57+
const getPeriodLabel = (period: Periods): string => {
5858
switch (period) {
5959
case Periods.appeal:
6060
return "Crowdfunding Appeal";

web/src/hooks/queries/useCasesQuery.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ export type { CasesPageQuery };
55

66
const casesQuery = gql`
77
query CasesPage($skip: Int) {
8-
disputes(
9-
first: 3
10-
skip: $skip
11-
orderBy: lastPeriodChange
12-
orderDirection: desc
13-
) {
8+
disputes(first: 3, skip: $skip, orderBy: lastPeriodChange, orderDirection: desc) {
149
id
1510
arbitrated {
1611
id
@@ -30,7 +25,7 @@ const casesQuery = gql`
3025
}
3126
`;
3227

33-
export const useCasesQuery = (skip: number) => {
28+
export const useCasesQuery = (skip: number): { data: typeof result; error: any; isValidating: boolean } => {
3429
const { data, error, isValidating } = useSWR({
3530
query: casesQuery,
3631
variables: { skip: skip },

web/src/hooks/queries/useClassicAppealQuery.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ const classicAppealQuery = gql`
2929
}
3030
`;
3131

32-
export const useClassicAppealQuery = (id?: string | number) => {
32+
export const useClassicAppealQuery = (
33+
id?: string | number
34+
): { data: typeof result; error: any; isValidating: boolean } => {
3335
const { data, error, isValidating } = useSWR(() =>
3436
typeof id !== "undefined"
3537
? {

web/src/hooks/queries/useCourtDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const courtDetailsQuery = gql`
1818
}
1919
`;
2020

21-
export const useCourtDetails = (id?: string) => {
21+
export const useCourtDetails = (id?: string): { data: typeof result; error: any; isValidating: boolean } => {
2222
const { data, error, isValidating } = useSWR(
2323
id
2424
? {

web/src/hooks/queries/useCourtPolicyURI.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const courtPolicyURIQuery = gql`
1111
}
1212
`;
1313

14-
export const useCourtPolicyURI = (id?: string | number) => {
14+
export const useCourtPolicyURI = (id?: string | number): { data: typeof result; error: any; isValidating: boolean } => {
1515
const { data, error, isValidating } = useSWRImmutable(() =>
1616
typeof id !== "undefined"
1717
? {
@@ -20,8 +20,6 @@ export const useCourtPolicyURI = (id?: string | number) => {
2020
}
2121
: false
2222
);
23-
const result = data
24-
? (data.court.policy as CourtPolicyUriQuery.court.policy)
25-
: undefined;
23+
const result = data ? (data.court.policy as CourtPolicyUriQuery.court.policy) : undefined;
2624
return { data: result, error, isValidating };
2725
};

web/src/hooks/queries/useCourtTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const courtTreeQuery = gql`
3232
}
3333
`;
3434

35-
export const useCourtTree = () => {
35+
export const useCourtTree = (): { data: typeof result; error: any; isValidating: boolean } => {
3636
const { data, error, isValidating } = useSWR({
3737
query: courtTreeQuery,
3838
});

web/src/hooks/queries/useDisputeDetailsQuery.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const disputeDetailsQuery = gql`
2222
}
2323
`;
2424

25-
export const useDisputeDetailsQuery = (id?: string | number) => {
25+
export const useDisputeDetailsQuery = (
26+
id?: string | number
27+
): { data: typeof result; error: any; isValidating: boolean } => {
2628
const { data, error, isValidating } = useSWR(() =>
2729
typeof id !== "undefined"
2830
? {

web/src/hooks/queries/useDisputeKitClassicMultipliers.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ export const useDisputeKitClassicMultipliers = () => {
88
() => (disputeKitClassic ? `Multipliers` : false),
99
async () => {
1010
if (!disputeKitClassic) return;
11-
const winner_stake_multiplier =
12-
await disputeKitClassic.WINNER_STAKE_MULTIPLIER();
13-
const loser_stake_multiplier =
14-
await disputeKitClassic.LOSER_STAKE_MULTIPLIER();
15-
const loser_appeal_period_multiplier =
16-
await disputeKitClassic.LOSER_APPEAL_PERIOD_MULTIPLIER();
11+
const winner_stake_multiplier = await disputeKitClassic.WINNER_STAKE_MULTIPLIER();
12+
const loser_stake_multiplier = await disputeKitClassic.LOSER_STAKE_MULTIPLIER();
13+
const loser_appeal_period_multiplier = await disputeKitClassic.LOSER_APPEAL_PERIOD_MULTIPLIER();
1714
return {
1815
winner_stake_multiplier,
1916
loser_stake_multiplier,

web/src/hooks/queries/useDrawQuery.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const drawQuery = gql`
1111
}
1212
`;
1313

14-
export const useDrawQuery = (address?: string | null, disputeID?: string) => {
14+
export const useDrawQuery = (
15+
address?: string | null,
16+
disputeID?: string
17+
): { data: typeof result; error: any; isValidating: boolean } => {
1518
const { data, error, isValidating } = useSWR({
1619
query: drawQuery,
1720
variables: { address, disputeID },

web/src/hooks/queries/useEvidences.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ export type { EvidencesQuery };
55

66
const evidencesQuery = gql`
77
query Evidences($evidenceGroup: String) {
8-
evidences(
9-
where: { evidenceGroup: $evidenceGroup }
10-
orderBy: id
11-
orderDirection: asc
12-
) {
8+
evidences(where: { evidenceGroup: $evidenceGroup }, orderBy: id, orderDirection: asc) {
139
id
1410
evidence
1511
sender {
@@ -19,7 +15,7 @@ const evidencesQuery = gql`
1915
}
2016
`;
2117

22-
export const useEvidences = (evidenceGroup?: string) => {
18+
export const useEvidences = (evidenceGroup?: string): { data: typeof result; error: any; isValidating: boolean } => {
2319
const { data, error, isValidating } = useSWR(() =>
2420
typeof evidenceGroup !== "undefined"
2521
? {

web/src/hooks/queries/useHomePageQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const homePageQuery = gql`
1919
}
2020
`;
2121

22-
export const useHomePageQuery = (timeframe: number) => {
22+
export const useHomePageQuery = (timeframe: number): { data: typeof result; error: any; isValidating: boolean } => {
2323
const { data, error, isValidating } = useSWR({
2424
query: homePageQuery,
2525
variables: { timeframe: timeframe.toString() },

web/src/hooks/queries/useJurorBalance.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ import useSWR from "swr";
22
import { KlerosCore } from "@kleros/kleros-v2-contracts/typechain-types/src/arbitration/KlerosCore";
33
import { useConnectedContract } from "../useConnectedContract";
44

5-
export const useJurorBalance = (
6-
user?: string | null,
7-
courtId?: string | undefined
8-
) => {
5+
export const useJurorBalance = (user?: string | null, courtId?: string | undefined) => {
96
const klerosCore = useConnectedContract("KlerosCore") as KlerosCore;
107
return useSWR(
11-
() =>
12-
klerosCore && user && courtId ? `JurorBalance{address}{courtId}` : false,
8+
() => (klerosCore && user && courtId ? `JurorBalance${user}${courtId}` : false),
139
async () => {
1410
if (klerosCore && user && courtId) {
1511
return await klerosCore.getJurorBalance(user, courtId);

web/src/hooks/queries/usePNKAllowance.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import { CONTRACTS } from "utils/getContract";
66
export const usePNKAllowance = (user?: string | null) => {
77
const pnkContract = useConnectedContract("PNK") as PNK;
88
return useSWR(
9-
() => (pnkContract && user ? `PNKAllowance{user}` : false),
9+
() => (pnkContract && user ? `PNKAllowance${user}` : false),
1010
async () => {
1111
if (pnkContract && user) {
12-
return await pnkContract.allowance(
13-
user,
14-
CONTRACTS["KlerosCore"].address
15-
);
12+
return await pnkContract.allowance(user, CONTRACTS["KlerosCore"].address);
1613
} else {
1714
return undefined;
1815
}

web/src/hooks/queries/useVotingHistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const votingHistoryQuery = gql`
3131
}
3232
`;
3333

34-
export const useVotingHistory = (disputeID?: string) => {
34+
export const useVotingHistory = (disputeID?: string): { data: typeof result; error: any; isValidating: boolean } => {
3535
const { data, error, isValidating } = useSWR(() =>
3636
typeof disputeID !== "undefined"
3737
? {

web/src/hooks/useParsedAmount.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { useMemo } from "react";
22
import { BigNumber, utils } from "ethers";
33

4-
export function useParsedAmount(amount: string) {
5-
return useMemo(
6-
() => (amount === "" ? BigNumber.from(0) : utils.parseUnits(amount, 18)),
7-
[amount]
8-
);
4+
export function useParsedAmount(amount: string): BigNumber {
5+
return useMemo(() => (amount === "" ? BigNumber.from(0) : utils.parseUnits(amount, 18)), [amount]);
96
}

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useState } from "react";
22
import styled from "styled-components";
33
import Modal from "react-modal";
4-
import { Textarea, Button } from "@kleros/ui-components-library";
5-
import { DisputeKitClassic } from "@kleros/kleros-v2-contracts/typechain-types/src/arbitration/dispute-kits/DisputeKitClassic";
64
import { wrapWithToast } from "utils/wrapWithToast";
5+
import { Button, Textarea } from "@kleros/ui-components-library";
6+
import { DisputeKitClassic } from "@kleros/kleros-v2-contracts/typechain-types/src/arbitration/dispute-kits/DisputeKitClassic";
77
import { useConnectedContract } from "hooks/useConnectedContract";
88
import { uploadFormDataToIPFS } from "utils/uploadFormDataToIPFS";
99

@@ -12,26 +12,15 @@ const SubmitEvidenceModal: React.FC<{
1212
evidenceGroup: string;
1313
close: () => void;
1414
}> = ({ isOpen, evidenceGroup, close }) => {
15-
const disputeKit = useConnectedContract(
16-
"DisputeKitClassic"
17-
) as DisputeKitClassic;
15+
const disputeKit = useConnectedContract("DisputeKitClassic") as DisputeKitClassic;
1816
const [isSending, setIsSending] = useState(false);
1917
const [message, setMessage] = useState("");
2018
return (
2119
<StyledModal {...{ isOpen }}>
2220
<h1>Submit New Evidence</h1>
23-
<StyledTextArea
24-
value={message}
25-
onChange={(e) => setMessage(e.target.value)}
26-
placeholder="Your Arguments"
27-
/>
21+
<StyledTextArea value={message} onChange={(e) => setMessage(e.target.value)} placeholder="Your Arguments" />
2822
<ButtonArea>
29-
<Button
30-
variant="secondary"
31-
disabled={isSending}
32-
text="Return"
33-
onClick={close}
34-
/>
23+
<Button variant="secondary" disabled={isSending} text="Return" onClick={close} />
3524
<Button
3625
text="Submit"
3726
isLoading={isSending}
@@ -44,9 +33,7 @@ const SubmitEvidenceModal: React.FC<{
4433
const response = await res.json();
4534
if (res.status === 200) {
4635
const cid = "/ipfs/" + response["cid"];
47-
await wrapWithToast(
48-
disputeKit.submitEvidence(evidenceGroup, cid)
49-
).then(() => {
36+
await wrapWithToast(disputeKit.submitEvidence(evidenceGroup, cid)).then(() => {
5037
setMessage("");
5138
close();
5239
});
@@ -61,13 +48,11 @@ const SubmitEvidenceModal: React.FC<{
6148
);
6249
};
6350

64-
const constructEvidence = (msg: string) => {
51+
const constructEvidence = (msg: string): FormData => {
6552
const formData = new FormData();
66-
const file = new File(
67-
[JSON.stringify({ name: "Evidence", description: msg })],
68-
"evidence.json",
69-
{ type: "text/plain" }
70-
);
53+
const file = new File([JSON.stringify({ name: "Evidence", description: msg })], "evidence.json", {
54+
type: "text/plain",
55+
});
7156
formData.append("data", file, file.name);
7257
return formData;
7358
};

web/src/pages/Courts/CourtDetails/StakePanel/JurorStakeDisplay.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ import React from "react";
22
import styled from "styled-components";
33
import { useParams } from "react-router-dom";
44
import { BigNumber, utils } from "ethers";
5-
65
import { useJurorBalance } from "queries/useJurorBalance";
76
import { useWeb3 } from "hooks/useWeb3";
8-
97
import Field from "components/Field";
10-
import PNKIcon from "svgs/icons/pnk.svg";
11-
import LockerIcon from "svgs/icons/locker.svg";
128
import DiceIcon from "svgs/icons/dice.svg";
9+
import LockerIcon from "svgs/icons/locker.svg";
10+
import PNKIcon from "svgs/icons/pnk.svg";
1311

14-
const format = (value: BigNumber | undefined) =>
15-
value !== undefined ? utils.formatEther(value) : "0";
12+
const format = (value: BigNumber | undefined): string => (value !== undefined ? utils.formatEther(value) : "0");
1613

1714
const JurorBalanceDisplay = () => {
1815
const { id } = useParams();

web/src/utils/date.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function getCurrentTime() {
1+
export function getCurrentTime(): number {
22
return Math.floor(Date.now() / 1000);
33
}
44

0 commit comments

Comments
 (0)