Skip to content

Commit 8ca6536

Browse files
committed
refactor: wrong chain button display
1 parent e764a1c commit 8ca6536

File tree

8 files changed

+167
-136
lines changed

8 files changed

+167
-136
lines changed

web/src/layout/Header/navbar/Menu/Settings/SendMeNotifications/FormNotifs/index.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ const FormEmailContainer = styled.div`
2525
position: relative;
2626
`;
2727

28-
const EmailErrorContainer = styled.div`
29-
position: absolute;
30-
color: ${({ theme }) => theme.error};
31-
font-size: 12px;
32-
padding-top: 4px;
33-
padding-left: 16px;
34-
`;
35-
3628
const OPTIONS = [{ label: "When x." }, { label: "When y." }, { label: "When z." }, { label: "When w." }];
3729

3830
const FormNotifs: React.FC = () => {

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useState } from "react";
22
import styled from "styled-components";
33
import { useParams } from "react-router-dom";
4-
import { useAccount, useBalance } from "wagmi";
4+
import { useAccount, useBalance, useNetwork } from "wagmi";
55
import { useDebounce } from "react-use";
66
import { Field, Button } from "@kleros/ui-components-library";
7+
import ConnectButton from "components/ConnectButton";
78
import { usePrepareDisputeKitClassicFundAppeal, useDisputeKitClassicFundAppeal } from "hooks/contracts/generated";
89
import { wrapWithToast } from "utils/wrapWithToast";
910
import { useParsedAmount } from "hooks/useParsedAmount";
@@ -13,6 +14,7 @@ import {
1314
useFundingContext,
1415
} from "hooks/useClassicAppealContext";
1516
import { isUndefined } from "utils/index";
17+
import { DEFAULT_CHAIN } from "consts/chains";
1618

1719
const Fund: React.FC = () => {
1820
const loserSideCountdown = useLoserSideCountdownContext();
@@ -35,6 +37,7 @@ const Fund: React.FC = () => {
3537
const parsedAmount = useParsedAmount(debouncedAmount);
3638
const [isSending, setIsSending] = useState(false);
3739
const { selectedOption } = useSelectedOptionContext();
40+
const { chain } = useNetwork();
3841
const { config: fundAppealConfig } = usePrepareDisputeKitClassicFundAppeal({
3942
enabled: !isUndefined(id) && !isUndefined(selectedOption),
4043
args: [BigInt(id ?? 0), BigInt(selectedOption ?? 0)],
@@ -53,21 +56,25 @@ const Fund: React.FC = () => {
5356
}}
5457
placeholder="Amount to fund"
5558
/>
56-
<StyledButton
57-
disabled={isDisconnected || isSending || !balance || parsedAmount > balance.value}
58-
text={isDisconnected ? "Connect to Fund" : "Fund"}
59-
onClick={() => {
60-
if (fundAppeal) {
61-
setIsSending(true);
62-
wrapWithToast(fundAppeal!())
63-
.then(() => {
64-
setAmount("");
65-
close();
66-
})
67-
.finally(() => setIsSending(false));
68-
}
69-
}}
70-
/>
59+
{chain && chain.id === DEFAULT_CHAIN ? (
60+
<StyledButton
61+
disabled={isDisconnected || isSending || !balance || parsedAmount > balance.value}
62+
text={isDisconnected ? "Connect to Fund" : "Fund"}
63+
onClick={() => {
64+
if (fundAppeal) {
65+
setIsSending(true);
66+
wrapWithToast(fundAppeal!())
67+
.then(() => {
68+
setAmount("");
69+
close();
70+
})
71+
.finally(() => setIsSending(false));
72+
}
73+
}}
74+
/>
75+
) : (
76+
<ConnectButton />
77+
)}
7178
</div>
7279
</div>
7380
) : (

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

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import Modal from "react-modal";
55
import { Textarea, Button } from "@kleros/ui-components-library";
66
import { wrapWithToast, OPTIONS as toastOptions } from "utils/wrapWithToast";
77
import { uploadFormDataToIPFS } from "utils/uploadFormDataToIPFS";
8-
import { useWalletClient } from "wagmi";
8+
import { useWalletClient, useNetwork } from "wagmi";
99
import { prepareWriteDisputeKitClassic } from "hooks/contracts/generated";
10+
import { DEFAULT_CHAIN } from "consts/chains";
11+
import ConnectButton from "components/ConnectButton";
1012

1113
const SubmitEvidenceModal: React.FC<{
1214
isOpen: boolean;
1315
evidenceGroup: string;
1416
close: () => void;
1517
}> = ({ isOpen, evidenceGroup, close }) => {
1618
const { data: walletClient } = useWalletClient();
19+
const { chain } = useNetwork();
1720
const [isSending, setIsSending] = useState(false);
1821
const [message, setMessage] = useState("");
1922
return (
@@ -22,33 +25,37 @@ const SubmitEvidenceModal: React.FC<{
2225
<StyledTextArea value={message} onChange={(e) => setMessage(e.target.value)} placeholder="Your Arguments" />
2326
<ButtonArea>
2427
<Button variant="secondary" disabled={isSending} text="Return" onClick={close} />
25-
<Button
26-
text="Submit"
27-
isLoading={isSending}
28-
disabled={isSending}
29-
onClick={() => {
30-
setIsSending(true);
31-
const formData = constructEvidence(message);
32-
toast.info("Uploading to IPFS", toastOptions);
33-
uploadFormDataToIPFS(formData)
34-
.then(async (res) => {
35-
const response = await res.json();
36-
if (res.status === 200 && walletClient) {
37-
const cid = "/ipfs/" + response["cid"];
38-
const { request } = await prepareWriteDisputeKitClassic({
39-
functionName: "submitEvidence",
40-
args: [BigInt(evidenceGroup), cid],
41-
});
42-
await wrapWithToast(walletClient.writeContract(request)).then(() => {
43-
setMessage("");
44-
close();
45-
});
46-
}
47-
})
48-
.catch()
49-
.finally(() => setIsSending(false));
50-
}}
51-
/>
28+
{chain && chain.id === DEFAULT_CHAIN ? (
29+
<Button
30+
text="Submit"
31+
isLoading={isSending}
32+
disabled={isSending}
33+
onClick={() => {
34+
setIsSending(true);
35+
const formData = constructEvidence(message);
36+
toast.info("Uploading to IPFS", toastOptions);
37+
uploadFormDataToIPFS(formData)
38+
.then(async (res) => {
39+
const response = await res.json();
40+
if (res.status === 200 && walletClient) {
41+
const cid = "/ipfs/" + response["cid"];
42+
const { request } = await prepareWriteDisputeKitClassic({
43+
functionName: "submitEvidence",
44+
args: [BigInt(evidenceGroup), cid],
45+
});
46+
await wrapWithToast(walletClient.writeContract(request)).then(() => {
47+
setMessage("");
48+
close();
49+
});
50+
}
51+
})
52+
.catch()
53+
.finally(() => setIsSending(false));
54+
}}
55+
/>
56+
) : (
57+
<ConnectButton />
58+
)}
5259
</ButtonArea>
5360
</StyledModal>
5461
);
Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,58 @@
11
import React, { useState } from "react";
22
import styled from "styled-components";
33
import { useParams } from "react-router-dom";
4-
import { useAccount } from "wagmi";
4+
import { useAccount, useNetwork } from "wagmi";
55
import { Button, Searchbar } from "@kleros/ui-components-library";
66
import { useEvidenceGroup } from "queries/useEvidenceGroup";
77
import { useEvidences } from "queries/useEvidences";
88
import SubmitEvidenceModal from "./SubmitEvidenceModal";
99
import EvidenceCard from "components/EvidenceCard";
10+
import ConnectButton from "components/ConnectButton";
11+
import { DEFAULT_CHAIN } from "consts/chains";
12+
13+
const Container = styled.div`
14+
width: 100%;
15+
display: flex;
16+
flex-direction: column;
17+
gap: 16px;
18+
19+
align-items: center;
20+
`;
21+
22+
const StyledButton = styled(Button)`
23+
align-self: flex-end;
24+
`;
1025

1126
const Evidence: React.FC<{ arbitrable?: string }> = ({ arbitrable }) => {
1227
const [isModalOpen, setIsModalOpen] = useState(false);
1328
const { id } = useParams();
1429
const { data: evidenceGroup } = useEvidenceGroup(id, arbitrable);
1530
const { data } = useEvidences(evidenceGroup);
1631
const { address } = useAccount();
32+
const { chain } = useNetwork();
1733
return (
1834
<Container>
1935
{evidenceGroup && (
20-
<SubmitEvidenceModal
21-
isOpen={isModalOpen}
22-
close={() => setIsModalOpen(false)}
23-
{...{ evidenceGroup }}
24-
/>
36+
<SubmitEvidenceModal isOpen={isModalOpen} close={() => setIsModalOpen(false)} {...{ evidenceGroup }} />
2537
)}
2638
<Searchbar />
27-
<StyledButton
28-
small
29-
text="Submit Evidence"
30-
disabled={typeof address === "undefined" || isModalOpen}
31-
isLoading={isModalOpen}
32-
onClick={() => setIsModalOpen(true)}
33-
/>
39+
{chain && chain.id === DEFAULT_CHAIN ? (
40+
<StyledButton
41+
small
42+
text="Submit Evidence"
43+
disabled={typeof address === "undefined" || isModalOpen}
44+
isLoading={isModalOpen}
45+
onClick={() => setIsModalOpen(true)}
46+
/>
47+
) : (
48+
<ConnectButton />
49+
)}
3450
{data &&
3551
data.evidences.map(({ evidence, sender }, i) => (
36-
<EvidenceCard
37-
key={i}
38-
index={i + 1}
39-
sender={sender?.id}
40-
{...{ evidence }}
41-
/>
52+
<EvidenceCard key={i} index={i + 1} sender={sender?.id} {...{ evidence }} />
4253
))}
4354
</Container>
4455
);
4556
};
4657

47-
const Container = styled.div`
48-
width: 100%;
49-
display: flex;
50-
flex-direction: column;
51-
gap: 16px;
52-
53-
align-items: center;
54-
`;
55-
56-
const StyledButton = styled(Button)`
57-
align-self: flex-end;
58-
`;
59-
6058
export default Evidence;

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

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { useParams } from "react-router-dom";
44
import { Button, Textarea } from "@kleros/ui-components-library";
55
import { useGetMetaEvidence } from "queries/useGetMetaEvidence";
66
import { wrapWithToast } from "utils/wrapWithToast";
7-
import { useWalletClient } from "wagmi";
7+
import { useWalletClient, useNetwork } from "wagmi";
88
import { prepareWriteDisputeKitClassic } from "hooks/contracts/generated";
9+
import { DEFAULT_CHAIN } from "consts/chains";
10+
import ConnectButton from "components/ConnectButton";
911

1012
const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrable, voteIDs }) => {
1113
const { id } = useParams();
@@ -16,6 +18,7 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
1618
const [isSending, setIsSending] = useState(false);
1719
const [justification, setJustification] = useState("");
1820
const { data: walletClient } = useWalletClient();
21+
const { chain } = useNetwork();
1922

2023
return id ? (
2124
<Container>
@@ -31,51 +34,59 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
3134
variant="info"
3235
/>
3336
<OptionsContainer>
34-
{metaEvidence?.rulingOptions?.titles?.map((answer: string, i: number) => (
35-
<Button
36-
key={i}
37-
text={answer}
38-
disabled={isSending}
39-
isLoading={chosenOption === i + 1}
40-
onClick={async () => {
41-
setIsSending(true);
42-
setChosenOption(i + 1);
43-
const { request } = await prepareWriteDisputeKitClassic({
44-
functionName: "castVote",
45-
args: [parsedDisputeID, parsedVoteIDs, BigInt(i + 1), 0n, justification],
46-
});
47-
if (walletClient) {
48-
wrapWithToast(walletClient?.writeContract(request)).finally(() => {
49-
setChosenOption(-1);
50-
setIsSending(false);
37+
{metaEvidence?.rulingOptions?.titles?.map((answer: string, i: number) => {
38+
chain && chain.id === DEFAULT_CHAIN ? (
39+
<Button
40+
key={i}
41+
text={answer}
42+
disabled={isSending}
43+
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],
5150
});
52-
}
53-
}}
54-
/>
55-
))}
51+
if (walletClient) {
52+
wrapWithToast(walletClient?.writeContract(request)).finally(() => {
53+
setChosenOption(-1);
54+
setIsSending(false);
55+
});
56+
}
57+
}}
58+
/>
59+
) : (
60+
<ConnectButton />
61+
);
62+
})}
5663
</OptionsContainer>
5764
</MainContainer>
5865
<RefuseToArbitrateContainer>
59-
<Button
60-
variant="secondary"
61-
text="Refuse to Arbitrate"
62-
disabled={isSending}
63-
isLoading={chosenOption === 0}
64-
onClick={async () => {
65-
setIsSending(true);
66-
setChosenOption(0);
67-
const { request } = await prepareWriteDisputeKitClassic({
68-
functionName: "castVote",
69-
args: [parsedDisputeID, parsedVoteIDs, 0n, 0n, justification],
70-
});
71-
if (walletClient) {
72-
wrapWithToast(walletClient.writeContract(request)).finally(() => {
73-
setChosenOption(-1);
74-
setIsSending(false);
66+
{chain && chain.id === DEFAULT_CHAIN ? (
67+
<Button
68+
variant="secondary"
69+
text="Refuse to Arbitrate"
70+
disabled={isSending}
71+
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],
7578
});
76-
}
77-
}}
78-
/>
79+
if (walletClient) {
80+
wrapWithToast(walletClient.writeContract(request)).finally(() => {
81+
setChosenOption(-1);
82+
setIsSending(false);
83+
});
84+
}
85+
}}
86+
/>
87+
) : (
88+
<ConnectButton />
89+
)}
7990
</RefuseToArbitrateContainer>
8091
</Container>
8192
) : (

0 commit comments

Comments
 (0)