Skip to content

Commit 951c51d

Browse files
committed
fix: code smells
1 parent 8ca6536 commit 951c51d

File tree

4 files changed

+49
-42
lines changed

4 files changed

+49
-42
lines changed

web/src/pages/Cases/CaseDetails/Appeal/Classic/Fund.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { isUndefined } from "utils/index";
1717
import { DEFAULT_CHAIN } from "consts/chains";
1818

19-
const Fund: React.FC = () => {
19+
const useNeedFund = () => {
2020
const loserSideCountdown = useLoserSideCountdownContext();
2121
const { fundedChoices, winningChoice } = useFundingContext();
2222
const needFund =
@@ -25,25 +25,43 @@ const Fund: React.FC = () => {
2525
!isUndefined(winningChoice) &&
2626
fundedChoices.length > 0 &&
2727
!fundedChoices.includes(winningChoice));
28+
29+
return needFund;
30+
};
31+
32+
const useFundAppeal = (parsedAmount) => {
2833
const { id } = useParams();
34+
const { selectedOption } = useSelectedOptionContext();
35+
const { config: fundAppealConfig } = usePrepareDisputeKitClassicFundAppeal({
36+
enabled: !isUndefined(id) && !isUndefined(selectedOption),
37+
args: [BigInt(id ?? 0), BigInt(selectedOption ?? 0)],
38+
value: parsedAmount,
39+
});
40+
41+
const { writeAsync: fundAppeal } = useDisputeKitClassicFundAppeal(fundAppealConfig);
42+
43+
return fundAppeal;
44+
};
45+
46+
const Fund: React.FC = () => {
47+
const needFund = useNeedFund();
2948
const { address, isDisconnected } = useAccount();
3049
const { data: balance } = useBalance({
3150
address,
3251
watch: true,
3352
});
53+
3454
const [amount, setAmount] = useState("");
3555
const [debouncedAmount, setDebouncedAmount] = useState("");
3656
useDebounce(() => setDebouncedAmount(amount), 500, [amount]);
57+
3758
const parsedAmount = useParsedAmount(debouncedAmount);
59+
3860
const [isSending, setIsSending] = useState(false);
39-
const { selectedOption } = useSelectedOptionContext();
61+
const fundAppeal = useFundAppeal(parsedAmount);
62+
4063
const { chain } = useNetwork();
41-
const { config: fundAppealConfig } = usePrepareDisputeKitClassicFundAppeal({
42-
enabled: !isUndefined(id) && !isUndefined(selectedOption),
43-
args: [BigInt(id ?? 0), BigInt(selectedOption ?? 0)],
44-
value: parsedAmount,
45-
});
46-
const { writeAsync: fundAppeal } = useDisputeKitClassicFundAppeal(fundAppealConfig);
64+
4765
return needFund ? (
4866
<div>
4967
<label>How much ETH do you want to contribute?</label>
@@ -63,7 +81,7 @@ const Fund: React.FC = () => {
6381
onClick={() => {
6482
if (fundAppeal) {
6583
setIsSending(true);
66-
wrapWithToast(fundAppeal!())
84+
wrapWithToast(fundAppeal())
6785
.then(() => {
6886
setAmount("");
6987
close();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const Evidence: React.FC<{ arbitrable?: string }> = ({ arbitrable }) => {
4848
<ConnectButton />
4949
)}
5050
{data &&
51-
data.evidences.map(({ evidence, sender }, i) => (
52-
<EvidenceCard key={i} index={i + 1} sender={sender?.id} {...{ evidence }} />
51+
data.evidences.map(({ id, evidence, sender }, i) => (
52+
<EvidenceCard key={id} index={i + 1} sender={sender?.id} {...{ evidence }} />
5353
))}
5454
</Container>
5555
);

web/src/pages/Cases/CaseDetails/Voting/Binary.tsx

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
2020
const { data: walletClient } = useWalletClient();
2121
const { chain } = useNetwork();
2222

23+
const handleVote = async (voteOption: number) => {
24+
setIsSending(true);
25+
setChosenOption(voteOption);
26+
const { request } = await prepareWriteDisputeKitClassic({
27+
functionName: "castVote",
28+
args: [parsedDisputeID, parsedVoteIDs, BigInt(voteOption), 0n, justification],
29+
});
30+
if (walletClient) {
31+
wrapWithToast(walletClient.writeContract(request)).finally(() => {
32+
setChosenOption(-1);
33+
setIsSending(false);
34+
});
35+
}
36+
};
37+
2338
return id ? (
2439
<Container>
2540
<MainContainer>
@@ -35,26 +50,13 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
3550
/>
3651
<OptionsContainer>
3752
{metaEvidence?.rulingOptions?.titles?.map((answer: string, i: number) => {
38-
chain && chain.id === DEFAULT_CHAIN ? (
53+
return chain && chain.id === DEFAULT_CHAIN ? (
3954
<Button
4055
key={i}
4156
text={answer}
4257
disabled={isSending}
4358
isLoading={chosenOption === i + 1}
44-
onClick={async () => {
45-
setIsSending(true);
46-
setChosenOption(i + 1);
47-
const { request } = await prepareWriteDisputeKitClassic({
48-
functionName: "castVote",
49-
args: [parsedDisputeID, parsedVoteIDs, BigInt(i + 1), 0n, justification],
50-
});
51-
if (walletClient) {
52-
wrapWithToast(walletClient?.writeContract(request)).finally(() => {
53-
setChosenOption(-1);
54-
setIsSending(false);
55-
});
56-
}
57-
}}
59+
onClick={() => handleVote(i + 1)}
5860
/>
5961
) : (
6062
<ConnectButton />
@@ -69,20 +71,7 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
6971
text="Refuse to Arbitrate"
7072
disabled={isSending}
7173
isLoading={chosenOption === 0}
72-
onClick={async () => {
73-
setIsSending(true);
74-
setChosenOption(0);
75-
const { request } = await prepareWriteDisputeKitClassic({
76-
functionName: "castVote",
77-
args: [parsedDisputeID, parsedVoteIDs, 0n, 0n, justification],
78-
});
79-
if (walletClient) {
80-
wrapWithToast(walletClient.writeContract(request)).finally(() => {
81-
setChosenOption(-1);
82-
setIsSending(false);
83-
});
84-
}
85-
}}
74+
onClick={() => handleVote(0)}
8675
/>
8776
) : (
8877
<ConnectButton />
@@ -93,6 +82,7 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
9382
<></>
9483
);
9584
};
85+
9686
const Container = styled.div`
9787
width: 100%;
9888
height: auto;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styled from "styled-components";
33
import { useParams } from "react-router-dom";
44
import { formatEther } from "viem";
55
import { useDebounce } from "react-use";
6-
import { useAccount, useNetwork } from "wagmi";
6+
import { useAccount } from "wagmi";
77
import { Field } from "@kleros/ui-components-library";
88

99
import { useParsedAmount } from "hooks/useParsedAmount";
@@ -26,7 +26,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({ action, isSending, setIsSending
2626

2727
const { id } = useParams();
2828
const { address } = useAccount();
29-
const { chain } = useNetwork();
3029
const { data: balance } = usePNKBalance(address);
3130
const parsedBalance = formatEther(balance ?? 0n);
3231
const { data: jurorBalance } = useJurorBalance(address, id);

0 commit comments

Comments
 (0)