Skip to content

Commit

Permalink
adding balance checks on SP (#742)
Browse files Browse the repository at this point in the history
* adding balance checks on SP

* tweaks

---------

Co-authored-by: Pierre Bertet <hi@bpier.re>
  • Loading branch information
ColinPlatt and bpierre authored Jan 22, 2025
1 parent 64fe327 commit 5b908fb
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions frontend/app/src/screens/EarnPoolScreen/PanelUpdateDeposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function PanelUpdateDeposit({
const [focused, setFocused] = useState(false);
const [claimRewards, setClaimRewards] = useState(false);

const hasDeposit = position?.deposit && dn.gt(position.deposit, 0);
const hasDeposit = dn.gt(position?.deposit ?? DNUM_0, 0);

const parsedValue = parseInputFloat(value);

Expand All @@ -60,9 +60,20 @@ export function PanelUpdateDeposit({

const collateral = getCollToken(collIndex);

const insufficientBalance = mode === "add"
&& parsedValue
&& boldBalance.data
&& dn.lt(boldBalance.data, parsedValue);

const withdrawAboveDeposit = mode === "remove"
&& parsedValue
&& dn.gt(parsedValue, position?.deposit ?? DNUM_0);

const allowSubmit = account.isConnected
&& parsedValue
&& dn.gt(parsedValue, 0);
&& dn.gt(parsedValue, 0)
&& !insufficientBalance
&& !withdrawAboveDeposit;

return (
<div
Expand All @@ -77,6 +88,19 @@ export function PanelUpdateDeposit({
<Field
field={
<InputField
drawer={insufficientBalance
? {
mode: "error",
message: `Insufficient balance. You have ${fmtnum(boldBalance.data ?? 0)} BOLD.`,
}
: withdrawAboveDeposit
? {
mode: "error",
message: hasDeposit
? `You can’t withdraw more than you have deposited.`
: `No BOLD deposited.`,
}
: null}
contextual={
<InputTokenBadge
background={false}
Expand Down

0 comments on commit 5b908fb

Please sign in to comment.