Skip to content

Commit

Permalink
fix: only update limit price once (#1357)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Dec 5, 2024
1 parent 22a6ed3 commit d56bbb3
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/views/forms/TradeForm/TradeFormInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,27 @@ export const TradeFormInputs = () => {
const { tickSizeDecimals } = orEmptyObj(useAppSelector(getCurrentMarketConfig, shallowEqual));

const midMarketPrice = useAppSelector(getCurrentMarketMidMarketPrice, shallowEqual);
const [hasUserChangedLimitInput, setHasUserChangedLimitInput] = useState(false);
const [hasSetMidMarketLimit, setHasSetMidMarketLimit] = useState(false);

useEffect(() => {
setHasUserChangedLimitInput(false);
setHasSetMidMarketLimit(false);
}, [marketId, type?.rawValue]);

useEffect(() => {
// when limit price input is empty and mid price is available, set limit price input to mid price
if (!midMarketPrice || !needsLimitPrice || hasUserChangedLimitInput) {
if (!midMarketPrice || !needsLimitPrice || hasSetMidMarketLimit) {
return;
}
dispatch(
setTradeFormInputs({
limitPriceInput: MustBigNumber(midMarketPrice).toFixed(tickSizeDecimals ?? USD_DECIMALS),
})
);
}, [
dispatch,
limitPriceInput,
midMarketPrice,
needsLimitPrice,
tickSizeDecimals,
marketId,
hasUserChangedLimitInput,
]);
setHasSetMidMarketLimit(true);
}, [dispatch, midMarketPrice, needsLimitPrice, tickSizeDecimals, marketId, hasSetMidMarketLimit]);

const onMidMarketPriceClick = () => {
if (!midMarketPrice) return;
setHasUserChangedLimitInput(false);
dispatch(
setTradeFormInputs({
limitPriceInput: MustBigNumber(midMarketPrice).toFixed(tickSizeDecimals ?? USD_DECIMALS),
Expand Down Expand Up @@ -132,7 +124,6 @@ export const TradeFormInputs = () => {
onChange: ({ value }: NumberFormatValues) => {
dispatch(setTradeFormInputs({ limitPriceInput: value }));
},
onInput: () => setHasUserChangedLimitInput(true),
value: limitPriceInput,
decimals: tickSizeDecimals ?? USD_DECIMALS,
slotRight: midMarketPrice ? midMarketPriceButton : undefined,
Expand Down

0 comments on commit d56bbb3

Please sign in to comment.