@@ -81,16 +81,19 @@ const InputDisplay: React.FC<IInputDisplay> = ({ action, amount, setAmount }) =>
8181
8282 const parsedBalance = formatPNK ( balance ?? 0n , 0 , true ) ;
8383
84- const parsedStake = formatPNK ( jurorBalance ?. [ 2 ] ?? 0n , 0 , true ) ;
84+ const maxWithdrawAmount = jurorBalance
85+ ? BigInt ( Math . min ( Number ( jurorBalance [ 2 ] ) , Number ( jurorBalance [ 0 ] - jurorBalance [ 1 ] ) ) )
86+ : 0n ;
87+ const parsedMaxWithdrawAmount = formatPNK ( maxWithdrawAmount , 0 , true ) ;
8588 const isStaking = useMemo ( ( ) => action === ActionType . stake , [ action ] ) ;
8689
8790 useEffect ( ( ) => {
8891 if ( parsedAmount > 0n && balance === 0n && isStaking ) {
8992 setErrorMsg ( "You need a non-zero PNK balance to stake" ) ;
9093 } else if ( isStaking && balance && parsedAmount > balance ) {
9194 setErrorMsg ( "Insufficient balance to stake this amount" ) ;
92- } else if ( ! isStaking && jurorBalance && parsedAmount > jurorBalance [ 2 ] ) {
93- setErrorMsg ( "Insufficient staked amount to withdraw this amount" ) ;
95+ } else if ( ! isStaking && jurorBalance && parsedAmount > maxWithdrawAmount ) {
96+ setErrorMsg ( "Insufficient available amount to withdraw this amount" ) ;
9497 } else if (
9598 action === ActionType . stake &&
9699 courtDetails &&
@@ -102,15 +105,15 @@ const InputDisplay: React.FC<IInputDisplay> = ({ action, amount, setAmount }) =>
102105 } else {
103106 setErrorMsg ( undefined ) ;
104107 }
105- } , [ parsedAmount , isStaking , balance , jurorBalance , action , courtDetails ] ) ;
108+ } , [ parsedAmount , isStaking , balance , jurorBalance , action , courtDetails , maxWithdrawAmount ] ) ;
106109
107110 return (
108111 < >
109112 < LabelArea >
110- < label > { `Available ${ isStaking ? parsedBalance : parsedStake } PNK` } </ label >
113+ < label > { `Available ${ isStaking ? parsedBalance : parsedMaxWithdrawAmount } PNK` } </ label >
111114 < StyledLabel
112115 onClick = { ( ) => {
113- const amount = isStaking ? parsedBalance : parsedStake ;
116+ const amount = isStaking ? parsedBalance : parsedMaxWithdrawAmount ;
114117 setAmount ( amount ) ;
115118 } }
116119 >
0 commit comments