Skip to content
Merged
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
4 changes: 4 additions & 0 deletions apps/cowswap-frontend/src/locales/en-US.po
Original file line number Diff line number Diff line change
Expand Up @@ -5105,6 +5105,10 @@ msgstr "Order Creation Failed"
msgid "This wallet is not yet supported"
msgstr "This wallet is not yet supported"

#: apps/cowswap-frontend/src/modules/tradeFormValidation/pure/TradeFormButtons/tradeButtonsMap.tsx
msgid "The token pair is constrained"
msgstr "The token pair is constrained"

#: apps/cowswap-frontend/src/modules/affiliate/containers/AffiliatePartnerCodeInfo.tsx
#: apps/cowswap-frontend/src/modules/ordersTable/pure/ReceiptModal/ReceiptModal.modal.tsx
msgid "Created"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,7 @@ export const tradeButtonsMap: Record<TradeFormValidation, ButtonErrorConfig | Bu
</TradeFormBlankButton>
)
},
[TradeFormValidation.WidgetConstrainedTokenPair]: {
text: <Trans>The token pair is constrained</Trans>,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('validateTradeForm - xStock logic', () => {
recipient: '0x123',
isQuoteBasedOrder: true,
tradeType: TradeType.SWAP,
slippage: null,
},
tradeQuote: { isLoading: false } as unknown as TradeQuoteState,
isOnline: true,
Expand All @@ -48,12 +49,13 @@ describe('validateTradeForm - xStock logic', () => {
intermediateTokenToBeImported: false,
isAccountProxyLoading: false,
isProxySetupValid: true,
customTokenError: null,
customTokenError: undefined,
isRestrictedForCountry: false,
isBalancesLoading: false,
isBundlingSupported: true,
isInputCurrencyXstock: false,
isOutputCurrencyXstock: false,
injectedWidgetParams: {},
}

test('shows xStock minimum trade size for sell orders when xStock sell amount is below $10', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getIsNativeToken, isFractionFalsy, isSellOrder } from '@cowprotocol/common-utils'
import { isEvmChain } from '@cowprotocol/cow-sdk'
import { getCurrencyAddress, getIsNativeToken, isFractionFalsy, isSellOrder } from '@cowprotocol/common-utils'
import { areAddressesEqual, isEvmChain } from '@cowprotocol/cow-sdk'

import { TradeType } from 'modules/trade'
import { getIsFastQuote, isQuoteExpired } from 'modules/tradeQuote'
Expand Down Expand Up @@ -90,6 +90,21 @@ export function validateTradeForm(context: TradeFormValidationContext): TradeFor
return [TradeFormValidation.XstockMinimumTradeSize]
}

if (injectedWidgetParams.tokenPairConstraints && inputCurrency && outputCurrency) {
const isTradeConstrained = injectedWidgetParams.tokenPairConstraints.some((rule) => {
return (
rule.sell.chainId === inputCurrency.chainId &&
areAddressesEqual(rule.sell.address, getCurrencyAddress(inputCurrency)) &&
rule.buy.chainId === outputCurrency.chainId &&
areAddressesEqual(rule.buy.address, getCurrencyAddress(outputCurrency))
)
})

if (isTradeConstrained) {
validations.push(TradeFormValidation.WidgetConstrainedTokenPair)
}
}

if (!isWrapUnwrap && tradeQuote.error) {
if (inputAmountIsNotSet) {
validations.push(TradeFormValidation.InputAmountNotSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ export enum TradeFormValidation {
// Widget controlled
DisableTradeWithUnknownPriceImpact,
DisableTradeWithHighPriceImpact,
WidgetConstrainedTokenPair,
}
8 changes: 8 additions & 0 deletions libs/widget-lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ export interface CowSwapWidgetParams {
whenPriceImpactIsHigherThan?: number
}

/**
* Disables trading of specific token pair
*/
tokenPairConstraints?: {
sell: { address: string; chainId: SupportedChainId }
buy: { address: string; chainId: SupportedChainId }
}[]

hooks?: Partial<{
onBeforeApproval(payload: OnApprovalPayload): WidgetHookResult
onBeforeWrapOrUnwrap(payload: OnTradeParamsPayload): WidgetHookResult
Expand Down
Loading