Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Trans } from '@lingui/react/macro'

import { TradeWarning } from 'modules/trade/pure/TradeWarning'
import { TradeWarningType } from 'modules/trade/pure/TradeWarning/constants'
import { TradeFormValidation, useGetTradeFormValidation } from 'modules/tradeFormValidation'
import { ACTIVE_VALIDATION_CASES, useGetTradeFormValidation } from 'modules/tradeFormValidation'
import { useTradeQuote } from 'modules/tradeQuote'

import { noImpactWarningAcceptedAtom } from './useIsNoImpactWarningAccepted'
Expand Down Expand Up @@ -43,13 +43,13 @@ export function NoImpactWarning(props: NoImpactWarningProps): ReactNode {
const primaryFormValidation = useGetTradeFormValidation()
const tradeQuote = useTradeQuote()

const canTrade =
(primaryFormValidation === null || primaryFormValidation === TradeFormValidation.ApproveAndSwapInBundle) &&
!tradeQuote.error
const showPriceImpactWarning =
!!account &&
!tradeQuote.error &&
(primaryFormValidation === null || ACTIVE_VALIDATION_CASES.includes(primaryFormValidation)) &&
(priceImpactParams.loading || !priceImpactParams.priceImpact)

const showPriceImpactWarning = canTrade && !!account && !priceImpactParams.loading && !priceImpactParams.priceImpact

const acceptCallback = (): void => setIsAccepted((state) => !state)
const acceptCallback = (accepted: boolean): void => setIsAccepted(accepted)

useEffect(() => {
setIsAccepted(!showPriceImpactWarning)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { useGetTradeFormValidation } from './useGetTradeFormValidation'

import { TradeFormValidation } from '../types'

const ACTIVE_VALIDATION_CASES = [
export const ACTIVE_VALIDATION_CASES: readonly TradeFormValidation[] = [
TradeFormValidation.ApproveAndSwapInBundle,
TradeFormValidation.ApproveRequired,
TradeFormValidation.SellNativeToken,
]
Comment on lines +5 to 9
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Include ImpactLoading in the active validation set.

validateTradeForm() now emits TradeFormValidation.ImpactLoading, but this list still excludes it. That means NoImpactWarning will treat loading as an inactive validation and the warning/checkbox flow will stay hidden while price impact is pending.

🔧 Proposed fix
 export const ACTIVE_VALIDATION_CASES: readonly TradeFormValidation[] = [
   TradeFormValidation.ApproveAndSwapInBundle,
   TradeFormValidation.ApproveRequired,
+  TradeFormValidation.ImpactLoading,
   TradeFormValidation.SellNativeToken,
 ]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const ACTIVE_VALIDATION_CASES: readonly TradeFormValidation[] = [
TradeFormValidation.ApproveAndSwapInBundle,
TradeFormValidation.ApproveRequired,
TradeFormValidation.SellNativeToken,
]
export const ACTIVE_VALIDATION_CASES: readonly TradeFormValidation[] = [
TradeFormValidation.ApproveAndSwapInBundle,
TradeFormValidation.ApproveRequired,
TradeFormValidation.ImpactLoading,
TradeFormValidation.SellNativeToken,
]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/cowswap-frontend/src/modules/tradeFormValidation/hooks/useIsTradeFormValidationPassed.ts`
around lines 5 - 9, The ACTIVE_VALIDATION_CASES constant is missing
TradeFormValidation.ImpactLoading so validateTradeForm() can emit ImpactLoading
but the NoImpactWarning still treats loading as inactive; update
ACTIVE_VALIDATION_CASES to include TradeFormValidation.ImpactLoading alongside
TradeFormValidation.ApproveAndSwapInBundle, TradeFormValidation.ApproveRequired,
and TradeFormValidation.SellNativeToken so the loading/price-impact state is
treated as an active validation by NoImpactWarning.


export function useIsTradeFormValidationPassed(): boolean {
const primaryFormValidation = useGetTradeFormValidation()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ export function validateTradeForm(context: TradeFormValidationContext): TradeFor
validations.push(TradeFormValidation.ProxyAccountUnknown)
}
}
if (tradePriceImpact.loading) {
validations.push(TradeFormValidation.ImpactLoading)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a apps/cowswap-frontend/src/modules/tradeFormValidation/services/validateTradeForm.test.ts for validateTradeForm, it would be grate to add a test case for this fix

}
}

if (isWrapUnwrap) {
Expand Down
Loading