Skip to content

Commit

Permalink
deposit-hook: add min amount validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesfracari committed Dec 2, 2024
1 parent 326d465 commit 13d54ed
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions apps/deposit-pool/src/components/FormButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,23 @@ export function FormButton({ poolBalances }: { poolBalances: IBalance[] }) {
.filter((symbol) => symbol) as string[];
}, [amounts, poolTokens, tokenAddresses]);

const zeroAmount = useMemo(() => {
return tokenAddresses
.map((tokenAddress) => amounts[tokenAddress])
.some((amount) => Number(amount) <= 0);
}, [amounts, tokenAddresses]);

const shouldDisableButton = useMemo(() => {
if (insufficientTokenSymbols.length) return true;
if (Number(referenceAmount || "0") <= 0) return true;
if (zeroAmount) return true;
if (isSubmitting) return true;
return false;
}, [insufficientTokenSymbols, isSubmitting, referenceAmount]);
}, [insufficientTokenSymbols, isSubmitting, referenceAmount, zeroAmount]);

const ButtonMessage = () => {
const buttonMessage = useMemo(() => {
if (Number(referenceAmount || "0") <= 0) return "Enter an amount";
if (zeroAmount) return "Enter a larger amount";
if (insufficientTokenSymbols.length === 1) {
return `Insufficient ${insufficientTokenSymbols[0]} balance`;
}
Expand All @@ -69,14 +77,21 @@ export function FormButton({ poolBalances }: { poolBalances: IBalance[] }) {
if (isSubmitting) return "Creating hook...";
if (context?.hookToEdit) return "Update post-hook";
return "Add post-hook";
};
}, [
zeroAmount,
insufficientTokenSymbols,
isSubmitting,
referenceAmount,
context?.hookToEdit,
]);

return (
<ButtonPrimary
className="mt-3"
type="submit"
disabled={shouldDisableButton}
>
<ButtonMessage />
{buttonMessage}
</ButtonPrimary>
);
}

0 comments on commit 13d54ed

Please sign in to comment.