diff --git a/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/index.tsx b/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/index.tsx index bb06bf9faa..8c5bfb0591 100644 --- a/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/index.tsx +++ b/apps/cowswap-frontend/src/modules/limitOrders/containers/RateInput/index.tsx @@ -224,7 +224,7 @@ export function RateInput() { rateImpact={rateImpact} toggleIcon={ diff --git a/apps/cowswap-frontend/src/modules/limitOrders/hooks/useUpdateCurrencyAmount.ts b/apps/cowswap-frontend/src/modules/limitOrders/hooks/useUpdateCurrencyAmount.ts index 79ccadbbdf..e2be50c2c2 100644 --- a/apps/cowswap-frontend/src/modules/limitOrders/hooks/useUpdateCurrencyAmount.ts +++ b/apps/cowswap-frontend/src/modules/limitOrders/hooks/useUpdateCurrencyAmount.ts @@ -1,9 +1,8 @@ -import { useAtomValue, useSetAtom } from 'jotai' import { useCallback } from 'react' import { FractionUtils, isSellOrder } from '@cowprotocol/common-utils' import { OrderKind } from '@cowprotocol/cow-sdk' -import { Currency, CurrencyAmount, Fraction, Price } from '@uniswap/sdk-core' +import { Currency, CurrencyAmount, Fraction } from '@uniswap/sdk-core' import { Writeable } from 'types' @@ -12,8 +11,6 @@ import { Field } from 'legacy/state/types' import { useLimitOrdersDerivedState } from 'modules/limitOrders/hooks/useLimitOrdersDerivedState' import { useUpdateLimitOrdersRawState } from 'modules/limitOrders/hooks/useLimitOrdersRawState' import { LimitOrdersRawState } from 'modules/limitOrders/state/limitOrdersRawStateAtom' -import { limitOrdersSettingsAtom } from 'modules/limitOrders/state/limitOrdersSettingsAtom' -import { updateLimitRateAtom } from 'modules/limitOrders/state/limitRateAtom' import { calculateAmountForRate } from 'utils/orderUtils/calculateAmountForRate' @@ -25,46 +22,13 @@ type CurrencyAmountProps = { export function useUpdateCurrencyAmount() { const updateLimitOrdersState = useUpdateLimitOrdersRawState() - const { inputCurrency, outputCurrency, inputCurrencyAmount: currentInputAmount } = useLimitOrdersDerivedState() - const { limitPriceLocked } = useAtomValue(limitOrdersSettingsAtom) - const updateLimitRateState = useSetAtom(updateLimitRateAtom) + const { inputCurrency, outputCurrency } = useLimitOrdersDerivedState() return useCallback( (params: CurrencyAmountProps) => { const { activeRate, amount, orderKind } = params const field = isSellOrder(orderKind) ? Field.INPUT : Field.OUTPUT - const isBuyAmountChange = field === Field.OUTPUT - if (isBuyAmountChange) { - const update: Partial> = { - orderKind, - outputCurrencyAmount: FractionUtils.serializeFractionToJSON(amount), - } - - updateLimitOrdersState(update) - - // If price is unlocked, update the rate based on the new amounts - if (!limitPriceLocked) { - // Calculate and update the new rate - if (amount && currentInputAmount) { - const newRate = new Price( - currentInputAmount.currency, - amount.currency, - currentInputAmount.quotient, - amount.quotient, - ) - updateLimitRateState({ - activeRate: FractionUtils.fractionLikeToFraction(newRate), - isTypedValue: false, - isRateFromUrl: false, - isAlternativeOrderRate: false, - }) - } - } - return - } - - // Normal flow for SELL amount changes const calculatedAmount = calculateAmountForRate({ activeRate, amount, @@ -88,6 +52,6 @@ export function useUpdateCurrencyAmount() { updateLimitOrdersState(update) }, - [inputCurrency, outputCurrency, updateLimitOrdersState, limitPriceLocked, updateLimitRateState, currentInputAmount], + [inputCurrency, outputCurrency, updateLimitOrdersState], ) } diff --git a/apps/cowswap-frontend/src/modules/limitOrders/state/limitOrdersSettingsAtom.ts b/apps/cowswap-frontend/src/modules/limitOrders/state/limitOrdersSettingsAtom.ts index 4f1a259712..492c2c3595 100644 --- a/apps/cowswap-frontend/src/modules/limitOrders/state/limitOrdersSettingsAtom.ts +++ b/apps/cowswap-frontend/src/modules/limitOrders/state/limitOrdersSettingsAtom.ts @@ -29,7 +29,7 @@ export const defaultLimitOrdersSettings: LimitOrdersSettingsState = { deadlineMilliseconds: defaultLimitOrderDeadline.value, customDeadlineTimestamp: null, limitPricePosition: 'bottom', - limitPriceLocked: false, + limitPriceLocked: true, ordersTableOnLeft: false, isUsdValuesMode: false, }