Skip to content

Commit

Permalink
fix: bug that allowed the slippage percentage to be set as an empty s…
Browse files Browse the repository at this point in the history
…tring
  • Loading branch information
Nathan Richards committed Nov 27, 2023
1 parent 011bf9c commit 888bea5
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChangeEventHandler } from 'react';
import type { ChangeEventHandler, FocusEventHandler } from 'react';
import { useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import PercentIcon from '@mui/icons-material/Percent';
Expand Down Expand Up @@ -32,7 +32,22 @@ export const SlippageSettings: React.FC = () => {

const handleInputUpdate: ChangeEventHandler<HTMLInputElement> = (event) => {
const { value } = event.target;
setValue('slippage', formatSlippage(value, defaultValue.current, true));

setValue(
'slippage',
formatSlippage(value || slippageDefault, defaultValue.current, true),
);
};

const handleInputBlur: FocusEventHandler<HTMLInputElement> = (event) => {
setFocused(undefined);

const { value } = event.target;

setValue(
'slippage',
formatSlippage(value || slippageDefault, defaultValue.current),
);
};

const customInputValue =
Expand Down Expand Up @@ -80,9 +95,7 @@ export const SlippageSettings: React.FC = () => {
onFocus={() => {
setFocused('input');
}}
onBlur={() => {
setFocused(undefined);
}}
onBlur={handleInputBlur}
value={customInputValue}
autoComplete="off"
/>
Expand Down

0 comments on commit 888bea5

Please sign in to comment.