Skip to content

Commit ffe48c5

Browse files
committed
refactor(web-devtools): single-connect-button-at-top-level
1 parent 98eb691 commit ffe48c5

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

web-devtools/src/app/(main)/ruler/ChangeDeveloper.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useMemo, useState } from "react";
22
import styled from "styled-components";
33

44
import { Address, isAddress } from "viem";
5-
import { usePublicClient } from "wagmi";
5+
import { useAccount, usePublicClient } from "wagmi";
66

77
import { Button } from "@kleros/ui-components-library";
88

@@ -11,10 +11,10 @@ import { useSimulateKlerosCoreRulerChangeRuler, useWriteKlerosCoreRulerChangeRul
1111
import { isUndefined } from "utils/isUndefined";
1212
import { wrapWithToast } from "utils/wrapWithToast";
1313

14-
import { EnsureChain } from "components/EnsureChain";
1514
import LabeledInput from "components/LabeledInput";
1615

1716
import Header from "./Header";
17+
import { DEFAULT_CHAIN } from "consts/chains";
1818

1919
const Container = styled.div`
2020
width: 100%;
@@ -34,6 +34,7 @@ const StyledLabel = styled.label`
3434
`;
3535

3636
const ChangeDeveloper: React.FC = () => {
37+
const { isConnected, chainId } = useAccount();
3738
const { arbitrable, currentDeveloper, refetchData } = useRulerContext();
3839
const [newDeveloper, setNewDeveloper] = useState("");
3940
const [isChanging, setIsChanging] = useState(false);
@@ -62,6 +63,18 @@ const ChangeDeveloper: React.FC = () => {
6263
.finally(() => setIsChanging(false));
6364
}, [publicClient, changeRulerConfig, changeRuler, refetchData]);
6465

66+
const isDisabled = useMemo(
67+
() =>
68+
!isConnected ||
69+
chainId !== DEFAULT_CHAIN ||
70+
!changeRulerConfig ||
71+
isError ||
72+
isLoading ||
73+
isChanging ||
74+
isUndefined(arbitrable) ||
75+
!isValid,
76+
[changeRulerConfig, isError, isLoading, isChanging, arbitrable, isValid, isConnected, chainId]
77+
);
6578
return (
6679
<Container>
6780
<Header text="Developer" />
@@ -74,14 +87,7 @@ const ChangeDeveloper: React.FC = () => {
7487
variant={isValid ? "" : "error"}
7588
/>
7689
</InputContainer>
77-
<EnsureChain>
78-
<Button
79-
text="Update"
80-
onClick={handleClick}
81-
isLoading={isLoading || isChanging}
82-
disabled={!changeRulerConfig || isError || isLoading || isChanging || isUndefined(arbitrable) || !isValid}
83-
/>
84-
</EnsureChain>
90+
<Button text="Update" onClick={handleClick} isLoading={isLoading || isChanging} disabled={isDisabled} />
8591
</Container>
8692
);
8793
};

web-devtools/src/app/(main)/ruler/ManualRuling.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useCallback, useMemo, useState } from "react";
33
import styled from "styled-components";
44

55
import { RULING_MODE } from "consts";
6-
import { usePublicClient } from "wagmi";
6+
import { useAccount, usePublicClient } from "wagmi";
77

88
import { Button } from "@kleros/ui-components-library";
99

@@ -17,10 +17,10 @@ import {
1717
import { isUndefined } from "utils/isUndefined";
1818
import { wrapWithToast } from "utils/wrapWithToast";
1919

20-
import { EnsureChain } from "components/EnsureChain";
2120
import LabeledInput from "components/LabeledInput";
2221

2322
import Header from "./Header";
23+
import { DEFAULT_CHAIN } from "consts/chains";
2424

2525
const Container = styled.div`
2626
width: 100%;
@@ -37,8 +37,9 @@ const SelectContainer = styled.div`
3737
`;
3838

3939
const ManualRuling: React.FC = () => {
40-
const [isSending, setIsSending] = useState<boolean>(false);
40+
const { isConnected, chainId } = useAccount();
4141
const { arbitrable, arbitrableSettings } = useRulerContext();
42+
const [isSending, setIsSending] = useState<boolean>(false);
4243
const [tie, setTie] = useState(arbitrableSettings?.tied ?? false);
4344
const [overriden, setOverriden] = useState(arbitrableSettings?.overridden ?? false);
4445
const [ruling, setRuling] = useState(arbitrableSettings?.ruling);
@@ -55,8 +56,14 @@ const ManualRuling: React.FC = () => {
5556
const { writeContractAsync: changeToManualMode } = useWriteKlerosCoreRulerChangeRulingModeToManual();
5657

5758
const isDisabled = useMemo(() => {
58-
return isUndefined(disputeId) || isUndefined(ruling) || isUndefined(arbitrable);
59-
}, [disputeId, ruling, arbitrable]);
59+
return (
60+
!isConnected ||
61+
chainId !== DEFAULT_CHAIN ||
62+
isUndefined(disputeId) ||
63+
isUndefined(ruling) ||
64+
isUndefined(arbitrable)
65+
);
66+
}, [disputeId, ruling, arbitrable, isConnected, chainId]);
6067

6168
const {
6269
data: executeConfig,
@@ -113,14 +120,12 @@ const ManualRuling: React.FC = () => {
113120
onChange={() => setOverriden((prev) => !prev)}
114121
/>
115122
</SelectContainer>
116-
<EnsureChain>
117-
<Button
118-
text="Rule"
119-
onClick={handleRuling}
120-
isLoading={isLoadingExecuteConfig || isSending}
121-
disabled={isDisabled || isError || isSending || isLoadingExecuteConfig}
122-
/>
123-
</EnsureChain>
123+
<Button
124+
text="Rule"
125+
onClick={handleRuling}
126+
isLoading={isLoadingExecuteConfig || isSending}
127+
disabled={isDisabled || isError || isSending || isLoadingExecuteConfig}
128+
/>
124129
</Container>
125130
);
126131
};

web-devtools/src/app/(main)/ruler/RulingModes.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
22
import styled from "styled-components";
33

44
import { RULING_MODE } from "consts";
5-
import { usePublicClient } from "wagmi";
5+
import { useAccount, usePublicClient } from "wagmi";
66

77
import { Button, Radio } from "@kleros/ui-components-library";
88

@@ -18,10 +18,10 @@ import {
1818
import { isUndefined } from "utils/isUndefined";
1919
import { wrapWithToast } from "utils/wrapWithToast";
2020

21-
import { EnsureChain } from "components/EnsureChain";
2221
import LabeledInput from "components/LabeledInput";
2322

2423
import Header from "./Header";
24+
import { DEFAULT_CHAIN } from "consts/chains";
2525

2626
const Container = styled.div`
2727
width: 100%;
@@ -46,6 +46,7 @@ const AutomaticPresetInputsContainer = styled.div`
4646
`;
4747

4848
const RulingModes: React.FC = () => {
49+
const { isConnected, chainId } = useAccount();
4950
const { arbitrable, arbitrableSettings } = useRulerContext();
5051
const [rulingMode, setRulingMode] = useState<RULING_MODE>();
5152
const [tie, setTie] = useState(false);
@@ -54,7 +55,6 @@ const RulingModes: React.FC = () => {
5455
const [isSending, setIsSending] = useState(false);
5556

5657
const publicClient = usePublicClient();
57-
5858
useEffect(() => {
5959
// only update once the arbitrable settings are fetched and only update initially, not updated on refetch
6060
if (!isUndefined(rulingMode) || !arbitrableSettings) return;
@@ -117,7 +117,7 @@ const RulingModes: React.FC = () => {
117117
useWriteKlerosCoreRulerChangeRulingModeToAutomaticRandom();
118118

119119
const isDisabled = useMemo(() => {
120-
if (!arbitrable) return true;
120+
if (!arbitrable || !isConnected || chainId !== DEFAULT_CHAIN) return true;
121121
switch (rulingMode) {
122122
case RULING_MODE.Manual:
123123
return (
@@ -160,6 +160,8 @@ const RulingModes: React.FC = () => {
160160
tie,
161161
overriden,
162162
ruling,
163+
isConnected,
164+
chainId,
163165
]);
164166

165167
const isLoading = useMemo(() => {
@@ -270,14 +272,12 @@ const RulingModes: React.FC = () => {
270272
</AutomaticPresetInputsContainer>
271273
)}
272274
</SelectContainer>
273-
<EnsureChain>
274-
<Button
275-
text="Update"
276-
onClick={handleUpdate}
277-
isLoading={isLoading || isSending}
278-
disabled={isDisabled || isSending}
279-
/>
280-
</EnsureChain>
275+
<Button
276+
text="Update"
277+
onClick={handleUpdate}
278+
isLoading={isLoading || isSending}
279+
disabled={isDisabled || isSending}
280+
/>
281281
</Container>
282282
);
283283
};

web-devtools/src/app/(main)/ruler/page.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import React from "react";
2+
import React, { useEffect, useState } from "react";
33
import styled from "styled-components";
44

55
import RulerContextProvider from "context/RulerContext";
@@ -10,6 +10,9 @@ import ChangeDeveloper from "./ChangeDeveloper";
1010
import ManualRuling from "./ManualRuling";
1111
import RulingModes from "./RulingModes";
1212
import SelectArbitrable from "./SelectArbitrable";
13+
import ConnectWallet from "components/ConnectWallet";
14+
import { useAccount } from "wagmi";
15+
import { DEFAULT_CHAIN } from "consts/chains";
1316

1417
const Container = styled.div`
1518
min-height: calc(100vh - 160px);
@@ -21,12 +24,21 @@ const Container = styled.div`
2124
padding: ${responsiveSize(32, 72)} ${responsiveSize(16, 132)} ${responsiveSize(76, 96)};
2225
`;
2326

27+
const StyledConnectWallet = styled(ConnectWallet)`
28+
align-self: flex-start;
29+
`;
30+
2431
const Ruler: React.FC = () => {
32+
const { isConnected, chainId } = useAccount();
33+
const [isClient, setIsClient] = useState(false);
34+
35+
useEffect(() => setIsClient(true), []);
2536
return (
2637
<RulerContextProvider>
2738
<Container>
2839
<h1>Ruler</h1>
2940
<SelectArbitrable />
41+
{isClient && (!isConnected || chainId !== DEFAULT_CHAIN) ? <StyledConnectWallet /> : null}
3042
<RulingModes />
3143
<ManualRuling />
3244
<ChangeDeveloper />

0 commit comments

Comments
 (0)