Skip to content

Commit 4087e7a

Browse files
authored
Merge pull request #1140 from kleros/fix(web)/withdrawing-bug
Fix(web): withdraw partial amounts
2 parents 6cc8638 + e807d34 commit 4087e7a

File tree

5 files changed

+500
-626
lines changed

5 files changed

+500
-626
lines changed

web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@kleros/kleros-v2-prettier-config": "workspace:^",
4242
"@kleros/kleros-v2-tsconfig": "workspace:^",
4343
"@netlify/functions": "^1.6.0",
44-
"@parcel/transformer-svg-react": "~2.9.0",
44+
"@parcel/transformer-svg-react": "~2.8.0",
4545
"@parcel/watcher": "~2.2.0",
4646
"@types/amqplib": "^0.10.1",
4747
"@types/busboy": "^1.5.0",
@@ -58,6 +58,7 @@
5858
"eslint-plugin-react": "^7.33.0",
5959
"eslint-plugin-react-hooks": "^4.6.0",
6060
"lru-cache": "^7.18.3",
61+
"parcel": "~2.8.0",
6162
"typescript": "^4.9.5"
6263
},
6364
"dependencies": {
@@ -78,7 +79,6 @@
7879
"graphql": "^16.7.1",
7980
"graphql-request": "~6.1.0",
8081
"moment": "^2.29.4",
81-
"parcel": "~2.9.0",
8282
"react": "^18.2.0",
8383
"react-chartjs-2": "^4.3.1",
8484
"react-dom": "^18.2.0",

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useDebounce } from "react-use";
66
import { useAccount } from "wagmi";
77
import { Field } from "@kleros/ui-components-library";
88
import { useParsedAmount } from "hooks/useParsedAmount";
9+
import { useCourtDetails } from "hooks/queries/useCourtDetails";
910
import { useKlerosCoreGetJurorBalance, usePnkBalanceOf } from "hooks/contracts/generated";
1011
import StakeWithdrawButton, { ActionType } from "./StakeWithdrawButton";
1112
import { isUndefined } from "utils/index";
@@ -55,6 +56,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
5556
const parsedAmount = useParsedAmount(debouncedAmount);
5657

5758
const { id } = useParams();
59+
const { data: courtDetails } = useCourtDetails(id);
5860
const { address } = useAccount();
5961
const { data: balance } = usePnkBalanceOf({
6062
enabled: !isUndefined(address),
@@ -73,7 +75,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
7375
return (
7476
<>
7577
<LabelArea>
76-
<label>{`Available ${parsedBalance} PNK`}</label>
78+
<label>{`Available ${isStaking ? parsedBalance : parsedStake} PNK`}</label>
7779
<StyledLabel
7880
onClick={() => {
7981
const amount = isStaking ? parsedBalance : parsedStake;
@@ -92,7 +94,12 @@ const InputDisplay: React.FC<IInputDisplay> = ({
9294
}}
9395
placeholder={isStaking ? "Amount to stake" : "Amount to withdraw"}
9496
message={
95-
isStaking ? "You may need two transactions, one to increase allowance, the other to stake." : undefined
97+
isStaking
98+
? `You need to stake at least ${formatEther(courtDetails?.court.minStake ?? 0n)} PNK. ` +
99+
"You may need two transactions, one to increase allowance, the other to stake."
100+
: `You need to either withdraw all or keep at least ${formatEther(
101+
courtDetails?.court.minStake ?? 0n
102+
)} PNK.`
96103
}
97104
variant="info"
98105
/>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useKlerosCoreGetJurorBalance,
1313
usePnkAllowance,
1414
} from "hooks/contracts/generated";
15+
import { useCourtDetails } from "hooks/queries/useCourtDetails";
1516
import { wrapWithToast } from "utils/wrapWithToast";
1617
import { isUndefined } from "utils/index";
1718
import { EnsureChain } from "components/EnsureChain";
@@ -41,6 +42,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
4142
const { id } = useParams();
4243
const { address } = useAccount();
4344
const klerosCore = getKlerosCore({});
45+
const { data: courtDetails } = useCourtDetails(id);
4446
const { data: balance } = usePnkBalanceOf({
4547
enabled: !isUndefined(address),
4648
args: [address!],
@@ -90,11 +92,10 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
9092
}
9193
};
9294

93-
const { config: setStakeConfig, error } = usePrepareKlerosCoreSetStake({
94-
enabled: !isUndefined(targetStake) && !isUndefined(id) && isStaking && !isAllowance,
95+
const { config: setStakeConfig } = usePrepareKlerosCoreSetStake({
96+
enabled: !isUndefined(targetStake) && !isUndefined(id) && !isAllowance,
9597
args: [BigInt(id ?? 0), targetStake],
9698
});
97-
console.log(setStakeConfig, error);
9899
const { writeAsync: setStake } = useKlerosCoreSetStake(setStakeConfig);
99100
const handleStake = () => {
100101
if (typeof setStake !== "undefined") {
@@ -135,7 +136,9 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
135136
isSending ||
136137
parsedAmount == 0n ||
137138
isUndefined(targetStake) ||
139+
isUndefined(courtDetails) ||
138140
checkDisabled() ||
141+
(targetStake !== 0n && targetStake < BigInt(courtDetails.court.minStake)) ||
139142
(isStaking && !isAllowance && isUndefined(setStakeConfig.request))
140143
}
141144
onClick={onClick}

web/src/pages/Courts/CourtDetails/Stats.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import PNKIcon from "svgs/icons/pnk.svg";
1313
import PNKRedistributedIcon from "svgs/icons/redistributed-pnk.svg";
1414
import EthereumIcon from "svgs/icons/ethereum.svg";
1515
import { useCoinPrice } from "hooks/useCoinPrice";
16-
import { isUndefined } from "~src/utils";
16+
import { isUndefined } from "utils/index";
1717

1818
const StyledCard = styled.div`
1919
width: auto;

0 commit comments

Comments
 (0)