Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
14 changes: 7 additions & 7 deletions apps/cowswap-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@cowprotocol/common-utils": "workspace:*",
"@cowprotocol/core": "workspace:*",
"@cowprotocol/cow-runner-game": "https://registry.npmjs.org/@cowprotocol/cow-runner-game/-/cow-runner-game-0.2.9.tgz",
"@cowprotocol/cow-sdk": "9.1.5",
"@cowprotocol/cow-sdk": "9.2.0",
"@cowprotocol/cowswap-abis": "workspace:*",
"@cowprotocol/currency": "workspace:*",
"@cowprotocol/ens": "workspace:*",
Expand All @@ -49,12 +49,12 @@
"@cowprotocol/iframe-transport": "workspace:*",
"@cowprotocol/multicall": "workspace:*",
"@cowprotocol/permit-utils": "workspace:*",
"@cowprotocol/sdk-bridging": "4.1.3",
"@cowprotocol/sdk-contracts-ts": "3.1.2",
"@cowprotocol/sdk-cow-shed": "0.3.13",
"@cowprotocol/sdk-order-book": "3.2.2",
"@cowprotocol/sdk-trading": "2.1.2",
"@cowprotocol/sdk-viem-adapter": "0.3.23",
"@cowprotocol/sdk-bridging": "4.2.0",
"@cowprotocol/sdk-contracts-ts": "3.2.0",
"@cowprotocol/sdk-cow-shed": "0.4.0",
"@cowprotocol/sdk-order-book": "4.0.0",
"@cowprotocol/sdk-trading": "2.2.0",
"@cowprotocol/sdk-viem-adapter": "0.3.24",
"@cowprotocol/snackbars": "workspace:*",
"@cowprotocol/tokens": "workspace:*",
"@cowprotocol/types": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions apps/cowswap-frontend/src/locales/en-US.po
Original file line number Diff line number Diff line change
Expand Up @@ -3211,8 +3211,8 @@ msgid "Rewards will be sent on Ethereum to"
msgstr "Rewards will be sent on Ethereum to"

#: apps/cowswap-frontend/src/modules/tradeFormValidation/pure/QuoteApiErrorButton.pure.tsx
msgid "Bridging without swapping is not yet supported. Let us know if you want this feature!"
msgstr "Bridging without swapping is not yet supported. Let us know if you want this feature!"
#~ msgid "Bridging without swapping is not yet supported. Let us know if you want this feature!"
#~ msgstr "Bridging without swapping is not yet supported. Let us know if you want this feature!"

#: apps/cowswap-frontend/src/modules/affiliate/containers/AffiliateTraderCodeInfo.tsx
msgid "Rewards end"
Expand Down Expand Up @@ -7185,8 +7185,8 @@ msgid "Advanced"
msgstr "Advanced"

#: apps/cowswap-frontend/src/modules/tradeFormValidation/pure/QuoteApiErrorButton.pure.tsx
msgid "Not yet supported"
msgstr "Not yet supported"
#~ msgid "Not yet supported"
#~ msgstr "Not yet supported"

#: apps/cowswap-frontend/src/modules/affiliate/pure/AffiliateTraderModal/AffiliateTradeCodeForm.tsx
#: apps/cowswap-frontend/src/modules/hooksStore/pure/HookListItem/index.tsx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ export function HooksStoreWidget(): ReactNode {
return (
<>
<TradeWidgetWrapper visible$={!hideSwapWidget}>
{/*TODO: sell=buy feature. Add allowSwapSameToken attribute again when feature is ready */}
<SwapWidget topContent={TopContent} bottomContent={BottomContent} />
<SwapWidget topContent={TopContent} bottomContent={BottomContent} allowSwapSameToken />
</TradeWidgetWrapper>
<IframeDappsManifestUpdater />
{isHookSelectionOpen && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useIsHooksTradeType, useIsNativeIn } from 'modules/trade'
// TODO: Add proper return type annotation
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function useSetRecipientOverride() {
const { onChangeRecipient } = useSwapWidgetActions()
const { onChangeRecipient } = useSwapWidgetActions(true)
const hookRecipientOverride = usePostHooksRecipientOverride()
const isHooksTradeType = useIsHooksTradeType()
const isNativeIn = useIsNativeIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function SwapWidget({ topContent, bottomContent, allowSwapSameToken }: Sw
quoteError instanceof QuoteApiError && quoteError.type === QuoteApiErrorCodes.SellAmountDoesNotCoverFee
const hideQuoteAmount = useShouldHideTradeRateDetails()
const priceImpact = useTradePriceImpact()
const widgetActions = useSwapWidgetActions()
const widgetActions = useSwapWidgetActions(hooksEnabledState[0])
const receiveAmountInfo = useGetReceiveAmountInfo()
const { disableCustomRecipient } = useInjectedWidgetParams()
const { token: intermediateBuyToken, toBeImported } = useTryFindToken(getBridgeIntermediateTokenAddress(bridgeQuote))
Expand Down Expand Up @@ -262,6 +262,7 @@ export function SwapWidget({ topContent, bottomContent, allowSwapSameToken }: Sw
const params = {
compactView: true,
enableSmartSlippage: true,
enableSellEqBuy: hooksEnabledState[0],
isMarketOrderWidget: true,
isSellingEthSupported: true,
allowSwapSameToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { useUpdateSwapRawState } from './useUpdateSwapRawState'

import { SELL_ETH_RESET_STATE } from '../consts'

export function useOnCurrencySelection(): (field: Field, currency: Currency | null) => void {
export function useOnCurrencySelection(enableSellEqBuy = false): (field: Field, currency: Currency | null) => void {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I didn't get why we want to enable sell=buy conditional to whether hook store is enabled

const { orderKind } = useSwapDerivedState()
const tradeOnCurrencySelection = useTradeOnCurrencySelection()
const tradeOnCurrencySelection = useTradeOnCurrencySelection(enableSellEqBuy)
const updateSwapState = useUpdateSwapRawState()
const navigateOnCurrencySelection = useNavigateOnCurrencySelection()
const navigateOnCurrencySelection = useNavigateOnCurrencySelection(enableSellEqBuy)

return useCallback(
(field: Field, currency: Currency | null) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { useSwapDerivedState } from './useSwapDerivedState'
import { useUpdateCurrencyAmount } from './useUpdateCurrencyAmount'
import { useUpdateSwapRawState } from './useUpdateSwapRawState'

export function useSwapWidgetActions(): TradeWidgetActions {
export function useSwapWidgetActions(isHooksStoreEnabled: boolean): TradeWidgetActions {
const { inputCurrency, outputCurrency } = useSwapDerivedState()
const updateSwapState = useUpdateSwapRawState()
const onCurrencySelection = useOnCurrencySelection()
const onCurrencySelection = useOnCurrencySelection(isHooksStoreEnabled)
const updateCurrencyAmount = useUpdateCurrencyAmount()

const onUserInput = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface TradeWidgetUpdatersProps {
disableQuotePolling: boolean
disableNativeSelling: boolean
enableSmartSlippage?: boolean
enableSellEqBuy?: boolean
disableSuggestedSlippageApi?: boolean
allowSwapSameToken: boolean
children: ReactNode
Expand All @@ -25,6 +26,7 @@ interface TradeWidgetUpdatersProps {
export function TradeWidgetUpdaters({
disableQuotePolling,
disableNativeSelling,
enableSellEqBuy = false,
disableSuggestedSlippageApi,
onChangeRecipient,
allowSwapSameToken,
Expand All @@ -48,7 +50,7 @@ export function TradeWidgetUpdaters({
/>
<PriceImpactUpdater />
<TradeFormValidationUpdater />
<CommonTradeUpdater />
<CommonTradeUpdater enableSellEqBuy={enableSellEqBuy} />
{!allowSwapSameToken && <ForbidSwapSameTokenUpdater />}
{disableNativeSelling && <DisableNativeTokenSellingUpdater />}
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function TradeWidget(props: TradeWidgetProps): JSX.Element {
disableNativeSelling = false,
disableSuggestedSlippageApi = false,
allowSwapSameToken = false,
enableSellEqBuy = false,
enableSmartSlippage,
} = params
const { open: isTokenSelectOpen } = useSelectTokenWidgetState()
Expand All @@ -45,6 +46,7 @@ export function TradeWidget(props: TradeWidgetProps): JSX.Element {
<>
<styledEl.Container id={id} isTokenSelectOpen={isTokenSelectOpen} isTokenSelectWide={isTokenSelectWide}>
<TradeWidgetUpdaters
enableSellEqBuy={enableSellEqBuy}
allowSwapSameToken={allowSwapSameToken}
disableQuotePolling={disableQuotePolling}
disableNativeSelling={disableNativeSelling}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface TradeWidgetParams {
displayChainName?: boolean
isPriceStatic?: boolean
allowSwapSameToken?: boolean
enableSellEqBuy?: boolean
customSelectTokenButton?: ReactNode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const EMPTY_TOKEN_ID = '_'

// TODO: Break down this large function into smaller functions
// eslint-disable-next-line max-lines-per-function
export function useSetupTradeState(): void {
export function useSetupTradeState(enableSellEqBuy = false): void {
useSetupTradeStateFromUrl()
const { chainId: providerChainId, account } = useWalletInfo()
const prevProviderChainId = usePrevious(providerChainId)
Expand All @@ -43,6 +43,7 @@ export function useSetupTradeState(): void {
// We must change chainId in provider, and only then change the trade state
// Since the network changing process takes some time, we have to remember the state from URL
const rememberedUrlStateRef = useRef<TradeRawState | null>(null)
const enableSellEqBuyRef = useRef<boolean>(enableSellEqBuy)
const [isFirstLoad, setIsFirstLoad] = useState(true)

const isWalletConnected = !!account
Expand Down Expand Up @@ -115,6 +116,10 @@ export function useSetupTradeState(): void {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [providerChainId, prevProviderChainId])

useEffect(() => {
enableSellEqBuyRef.current = enableSellEqBuy
}, [enableSellEqBuy])

/**
* On URL parameter changes
*
Expand Down Expand Up @@ -189,7 +194,7 @@ export function useSetupTradeState(): void {
return
}

if (sameTokens || tokensAreEmpty || onlyChainIdIsChanged) {
if ((sameTokens && !enableSellEqBuyRef.current) || tokensAreEmpty || onlyChainIdIsChanged) {
navigateAndSwitchNetwork(currentChainId, defaultState, prevProviderChainId)

if (sameTokens) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type CurrencySelectionCallback = (
* if there are more than one token with the same symbol
* @see useResetStateWithSymbolDuplication.ts
*/
export function useNavigateOnCurrencySelection(): CurrencySelectionCallback {
export function useNavigateOnCurrencySelection(enableSellEqBuy = false): CurrencySelectionCallback {
const { chainId } = useWalletInfo()
const { inputCurrency, outputCurrency, orderKind } = useDerivedTradeState() || {}
const navigate = useTradeNavigate()
Expand Down Expand Up @@ -107,21 +107,21 @@ export function useNavigateOnCurrencySelection(): CurrencySelectionCallback {
if (!isOutputCurrencyBridgeSupported) delete searchParams?.targetChainId
if (shouldResetBuyOrder) searchParams = { ...searchParams, kind: OrderKind.SELL, amount: '1' }

const currencyIds = areCurrenciesTheSame
? { inputCurrencyId: outputCurrencyId, outputCurrencyId: inputCurrencyId }
: {
inputCurrencyId: targetInputCurrencyId,
outputCurrencyId: isBridgeTrade && !isOutputCurrencyBridgeSupported ? null : targetOutputCurrencyId,
}
const currencyIds =
areCurrenciesTheSame && !enableSellEqBuy
? { inputCurrencyId: outputCurrencyId, outputCurrencyId: inputCurrencyId }
: {
inputCurrencyId: targetInputCurrencyId,
outputCurrencyId: isBridgeTrade && !isOutputCurrencyBridgeSupported ? null : targetOutputCurrencyId,
}
const nextChainId = isInputField ? targetChainId : chainId
const nextState: Partial<ExtendedTradeRawState> = {

// Apply next state to callback so caller can merge amount and update once (avoids glitch from URL sync effect applying currencies in a second render).
stateUpdateCallback?.({
chainId: nextChainId ?? null,
...currencyIds,
targetChainId: searchParams?.targetChainId ?? null,
}

// Apply next state to callback so caller can merge amount and update once (avoids glitch from URL sync effect applying currencies in a second render).
stateUpdateCallback?.(nextState)
})

navigate(nextChainId, currencyIds, searchParams)
},
Expand All @@ -133,6 +133,7 @@ export function useNavigateOnCurrencySelection(): CurrencySelectionCallback {
outputCurrency,
isOutputCurrencyBridgeSupported,
resolveCurrencyAddressOrSymbol,
enableSellEqBuy,
],
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import { useDerivedTradeState } from './useDerivedTradeState'
import { useNavigateOnCurrencySelection } from './useNavigateOnCurrencySelection'
import { useTradeState } from './useTradeState'

export function useOnCurrencySelection(): (field: Field, currency: Currency | null, callback?: Command) => void {
export function useOnCurrencySelection(
enableSellEqBuy = false,
): (field: Field, currency: Currency | null, callback?: Command) => void {
const { inputCurrencyAmount, outputCurrencyAmount } = useDerivedTradeState() || {}
const navigateOnCurrencySelection = useNavigateOnCurrencySelection()
const navigateOnCurrencySelection = useNavigateOnCurrencySelection(enableSellEqBuy)
const { updateState } = useTradeState()

return useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { useSetupTradeState } from '../hooks/setupTradeState/useSetupTradeState'
import { useNotifyWidgetTrade } from '../hooks/useNotifyWidgetTrade'
import { useSetupTradeTypeInfo } from '../hooks/useSetupTradeTypeInfo'

// TODO: Add proper return type annotation
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function CommonTradeUpdater() {
useSetupTradeState()
interface CommonTradeUpdaterProps {
enableSellEqBuy?: boolean
}

export function CommonTradeUpdater({ enableSellEqBuy }: CommonTradeUpdaterProps): null {
useSetupTradeState(enableSellEqBuy)
useNotifyWidgetTrade()
useSetupTradeTypeInfo()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { ReactNode } from 'react'

import { BridgeQuoteErrors } from '@cowprotocol/sdk-bridging'
import { HelpTooltip } from '@cowprotocol/ui'

import { t } from '@lingui/core/macro'

import { QuoteApiError, QuoteApiErrorCodes, UNHANDLED_ERROR_CODE } from 'api/cowProtocol/errors/QuoteError'

import {
getBridgeQuoteErrorTexts,
getDefaultQuoteError,
getQuoteErrorTexts,
} from './QuoteErrorsButton/quoteErrors.utils'
import { getDefaultQuoteError, getQuoteErrorTexts } from './QuoteErrorsButton/quoteErrors.utils'
import { TradeFormBlankButton } from './TradeFormBlankButton'
import { UnsupportedTokenButton } from './UnsupportedTokenButton.pure'

Expand All @@ -26,19 +19,6 @@ export function QuoteApiErrorButton(props: TradeFormButtonContext): ReactNode {

const quoteErrorTexts = getQuoteErrorTexts()

{
/*TODO: sell=buy feature. Remove all SameBuyAndSellToken usages once feature is ready */
}
const quoteErrorTextsForBridges: Partial<Record<QuoteApiErrorCodes, string>> = {
[QuoteApiErrorCodes.SameBuyAndSellToken]: t`Not yet supported`,
}

const errorTooltipContentForBridges: Partial<Record<QuoteApiErrorCodes, string>> = {
[QuoteApiErrorCodes.SameBuyAndSellToken]: t`Bridging without swapping is not yet supported. Let us know if you want this feature!`,
}

const bridgeQuoteErrorTexts = getBridgeQuoteErrorTexts()

const errorType = quote.error.type
const errorDescription = quote.error.description

Expand All @@ -54,33 +34,9 @@ export function QuoteApiErrorButton(props: TradeFormButtonContext): ReactNode {
)
}

const isBridge = quote.isBridgeQuote
const errorText = (() => {
const quoteErrorText = quoteErrorTexts[errorType]
const bridgeQuoteErrorText = quoteErrorTextsForBridges[errorType]

if (isBridge && bridgeQuoteErrorText) {
// Do not display "Not yet supported" when sell and intermediate tokens are the same
// Because user doesn't see intermediate token
if (errorType === QuoteApiErrorCodes.SameBuyAndSellToken) {
const areSwapAssetsDifferent =
props.derivedState.inputCurrency?.symbol?.toLowerCase() !==
props.derivedState.outputCurrency?.symbol?.toLowerCase()

if (areSwapAssetsDifferent) {
return bridgeQuoteErrorTexts[BridgeQuoteErrors.NO_ROUTES]
}
}

return bridgeQuoteErrorText
}

return quoteErrorText ?? DEFAULT_ERROR_TEXT
})()
const errorText = quoteErrorTexts[errorType] ?? DEFAULT_ERROR_TEXT

const errorTooltipText =
(isBridge ? errorTooltipContentForBridges[errorType] : null) ??
(errorText === DEFAULT_ERROR_TEXT ? errorDescription : null)
const errorTooltipText = errorText === DEFAULT_ERROR_TEXT ? errorDescription : null

return (
<TradeFormBlankButton disabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export async function fetchAndProcessQuote(
quoteSigner: isBridge ? getBridgeQuoteSigner(chainId) : undefined,
getSlippageSuggestion: useSuggestedSlippageApi ? coWBFFClient.getSlippageTolerance.bind(coWBFFClient) : undefined,
getCorrelatedTokens,
// TODO: sell=buy feature. Set allowIntermediateEqSellToken: true once the feature is ready
// allowIntermediateEqSellToken: true
allowIntermediateEqSellToken: true,
}

const processQuoteError = (errorLocation: string, error: unknown): void => {
Expand Down
10 changes: 5 additions & 5 deletions apps/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"@cowprotocol/common-hooks": "workspace:*",
"@cowprotocol/common-utils": "workspace:*",
"@cowprotocol/core": "workspace:*",
"@cowprotocol/cow-sdk": "9.1.5",
"@cowprotocol/cow-sdk": "9.2.0",
"@cowprotocol/hook-dapp-lib": "workspace:*",
"@cowprotocol/sdk-bridging": "4.1.3",
"@cowprotocol/sdk-contracts-ts": "3.1.2",
"@cowprotocol/sdk-subgraph": "1.1.2",
"@cowprotocol/sdk-viem-adapter": "0.3.23",
"@cowprotocol/sdk-bridging": "4.2.0",
"@cowprotocol/sdk-contracts-ts": "3.2.0",
"@cowprotocol/sdk-subgraph": "1.2.0",
"@cowprotocol/sdk-viem-adapter": "0.3.24",
"@cowprotocol/types": "workspace:*",
"@cowprotocol/ui": "workspace:*",
"@fortawesome/fontawesome-svg-core": "6.7.2",
Expand Down
6 changes: 3 additions & 3 deletions apps/sdk-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
},
"dependencies": {
"@cowprotocol/common-const": "workspace:*",
"@cowprotocol/cow-sdk": "9.1.5",
"@cowprotocol/sdk-composable": "1.0.6",
"@cowprotocol/sdk-viem-adapter": "0.3.23",
"@cowprotocol/cow-sdk": "9.2.0",
"@cowprotocol/sdk-composable": "1.1.0",
"@cowprotocol/sdk-viem-adapter": "0.3.24",
"@cowprotocol/wallet": "workspace:*",
"viem": "2.48.8",
"wagmi": "3.6.9",
Expand Down
Loading
Loading