From dede0d0431511ad1b1ed0548f6d42f881b0f95e0 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Mon, 16 Oct 2023 16:54:49 +0600 Subject: [PATCH] fix(eth-flow): update refund info for expired orders (#3222) * fix(eth-flow): update refund info for expired orders * chore: update comment * chore: fix ExpiredOrdersUpdater conditions * chore: fix namings --- .../updaters/orders/ExpiredOrdersUpdater.ts | 21 ++++++++----------- .../EthFlow/EthFlowStepper/index.cosmos.tsx | 10 +++++++-- libs/common-const/src/common.ts | 1 - 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts index 850cfd7201..006c88b659 100644 --- a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts +++ b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts @@ -1,6 +1,6 @@ import { useEffect, useCallback, useRef } from 'react' -import { EXPIRED_ORDERS_PENDING_TIME } from '@cowprotocol/common-const' +import { NATIVE_CURRENCY_BUY_ADDRESS } from '@cowprotocol/common-const' import { SupportedChainId as ChainId } from '@cowprotocol/cow-sdk' import { useWalletInfo } from '@cowprotocol/wallet' @@ -24,7 +24,6 @@ export function ExpiredOrdersUpdater(): null { const updateOrders = useCallback( async (chainId: ChainId, account: string) => { const lowerCaseAccount = account.toLowerCase() - const now = Date.now() if (isUpdating.current) { return @@ -33,26 +32,24 @@ export function ExpiredOrdersUpdater(): null { try { isUpdating.current = true - // Filter orders: + // Filter expired orders: + // - Only eth-flow orders // - Owned by the current connected account - // - Created in the last 5 min, no further // - Not yet refunded - const pending = expiredRef.current.filter(({ owner, creationTime: creationTimeString, refundHash }) => { - const creationTime = new Date(creationTimeString).getTime() + const orderWithoutRefund = expiredRef.current.filter(({ owner, refundHash, sellToken }) => { + const isEthFlowOrder = sellToken === NATIVE_CURRENCY_BUY_ADDRESS - return ( - owner.toLowerCase() === lowerCaseAccount && now - creationTime < EXPIRED_ORDERS_PENDING_TIME && !refundHash - ) + return isEthFlowOrder && owner.toLowerCase() === lowerCaseAccount && !refundHash }) - if (pending.length === 0) { + if (orderWithoutRefund.length === 0) { // console.debug(`[CancelledOrdersUpdater] No orders are being expired`) return } else { - console.debug(`[ExpiredOrdersUpdater] Checking ${pending.length} recently expired orders...`) + console.debug(`[ExpiredOrdersUpdater] Checking ${orderWithoutRefund.length} recently expired orders...`) } - const ordersPromises = pending.map(({ id }) => getOrder(chainId, id)) + const ordersPromises = orderWithoutRefund.map(({ id }) => getOrder(chainId, id)) const resolvedPromises = await Promise.allSettled(ordersPromises) diff --git a/apps/cowswap-frontend/src/modules/swap/pure/EthFlow/EthFlowStepper/index.cosmos.tsx b/apps/cowswap-frontend/src/modules/swap/pure/EthFlow/EthFlowStepper/index.cosmos.tsx index 1fd39c2845..022dcc648e 100644 --- a/apps/cowswap-frontend/src/modules/swap/pure/EthFlow/EthFlowStepper/index.cosmos.tsx +++ b/apps/cowswap-frontend/src/modules/swap/pure/EthFlow/EthFlowStepper/index.cosmos.tsx @@ -1,6 +1,7 @@ import 'inter-ui' // TODO: We need to do a cosmos wrapper with the global styles! Will reiterate to remove this line import { useSelect } from 'react-cosmos/client' +import styled from 'styled-components/macro' import { EthFlowStepper, EthFlowStepperProps, SmartOrderStatus } from '.' @@ -376,6 +377,11 @@ const STEPS_BY_DESCRIPTION = STEPS.reduce<{ [description: string]: EthFlowSteppe return acc }, {}) +const Wrapper = styled.div` + width: 80%; + margin: 20px auto; +` + function Fixture() { const [stepDescription] = useSelect('steps', { options: STEPS.map((step) => step.description), @@ -383,13 +389,13 @@ function Fixture() { const props = STEPS_BY_DESCRIPTION[stepDescription] return ( - <> +

Params

{JSON.stringify(props, null, 2)}
- +
) } diff --git a/libs/common-const/src/common.ts b/libs/common-const/src/common.ts index 4488559c9f..093a601cac 100644 --- a/libs/common-const/src/common.ts +++ b/libs/common-const/src/common.ts @@ -99,7 +99,6 @@ export const NATIVE_CURRENCY_BUY_TOKEN: { [chainId in ChainId | number]: Token } export const INPUT_OUTPUT_EXPLANATION = 'Only executed swaps incur fees.' export const PENDING_ORDERS_BUFFER = ms`60s` // 60s export const CANCELLED_ORDERS_PENDING_TIME = ms`5min` // 5min -export const EXPIRED_ORDERS_PENDING_TIME = ms`15min` // 15min export const PRICE_API_TIMEOUT_MS = ms`10s` // 10s export const GP_ORDER_UPDATE_INTERVAL = ms`30s` // 30s export const MINIMUM_ORDER_VALID_TO_TIME_SECONDS = 120