Skip to content

Commit

Permalink
fix: min amount handling fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarm22 committed Sep 23, 2024
1 parent 603d894 commit b485214
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions wormhole-connect/src/components/InputTransparent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Props = {
disabled?: boolean;
value?: string | number;
testId?: string;
pattern?: string;
};

const NUMBER_FORMAT_REGEX = /^\d*\.?\d*$/;
Expand Down Expand Up @@ -78,6 +79,7 @@ function InputTransparent(props: Props) {
readOnly={props.disabled}
value={props.value}
data-testid={props.testId}
pattern={props.pattern}
/>
);
}
Expand Down
12 changes: 8 additions & 4 deletions wormhole-connect/src/hooks/useAmountValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ export const useAmountValidation = (props: Props): HookReturn => {
// All quotes fail.
if (allRoutesFailed) {
if (minAmount) {
const amountDisplay = sdkAmount.display(minAmount);
const formattedAmount = sdkAmount.whole(minAmount).toLocaleString('en', {
maximumFractionDigits: 4,
});
return {
error: `Amount too small (min ~${amountDisplay} ${props.tokenSymbol})`,
error: `Amount too small (min ~${formattedAmount} ${props.tokenSymbol})`,
};
} else {
return {
Expand All @@ -95,9 +97,11 @@ export const useAmountValidation = (props: Props): HookReturn => {

// MinQuote warnings information
if (minAmount) {
const amountDisplay = sdkAmount.display(minAmount);
const formattedAmount = sdkAmount.whole(minAmount).toLocaleString('en', {
maximumFractionDigits: 4,
});
return {
warning: `More routes available for amounts exceeding ${amountDisplay} ${props.tokenSymbol}`,
warning: `More routes available for amounts exceeding ${formattedAmount} ${props.tokenSymbol}`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion wormhole-connect/src/utils/sdkv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,5 +445,5 @@ export const isMinAmountError = (
error?: Error,
): error is routes.MinAmountError => {
const unsafeCastError = error as routes.MinAmountError;
return isAmount(unsafeCastError?.min?.amount);
return isAmount(unsafeCastError?.min);
};
1 change: 1 addition & 0 deletions wormhole-connect/src/views/Bridge/Inputs/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function AmountInput(props: Props) {
disabled={isTransactionInProgress || props.disabled}
value={props.value}
testId={props.side + '-section-amount-input'}
pattern="[0-9]+([\.|,][0-9]{1,2})?"
/>
{price && <Price>{price}</Price>}
</>
Expand Down

0 comments on commit b485214

Please sign in to comment.