Skip to content

Commit

Permalink
feat(namadillo): adding validation to unstake amounts (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorezende committed Aug 15, 2024
1 parent f67437c commit c3dbd98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions apps/namadillo/src/App/Staking/Unstake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ const Unstake = (): JSX.Element => {

const validationMessage = ((): string => {
if (totalStakedAmount.lt(totalUpdatedAmount)) return "Invalid amount";

for (const address in updatedAmountByAddress) {
if (stakedAmountByAddress[address].lt(updatedAmountByAddress[address])) {
return "Invalid amount";
}
}
return "";
})();

Expand Down
11 changes: 9 additions & 2 deletions apps/namadillo/src/App/Staking/UnstakeBondingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const UnstakeBondingTable = ({
updatedAmountByAddress[validator.address] ?? new BigNumber(0);

const hasNewAmounts = amountToUnstake.gt(0);
const newAmount = stakedAmount.minus(amountToUnstake);

return {
className: "",
Expand Down Expand Up @@ -114,9 +115,15 @@ export const UnstakeBondingTable = ({
<NamCurrency amount={stakedAmount} />
</span>
{hasNewAmounts && (
<span className="text-orange text-sm">
<span
className={twMerge(
clsx("text-orange text-sm", {
"text-fail": newAmount.lt(0),
})
)}
>
=
<NamCurrency amount={stakedAmount.minus(amountToUnstake)} />
<NamCurrency amount={newAmount} />
</span>
)}
</div>,
Expand Down

0 comments on commit c3dbd98

Please sign in to comment.