From 61d0872eee2257e3dd2bd9024e5ca0994955c9b5 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 13 Oct 2023 13:18:27 +0600 Subject: [PATCH 1/4] fix(eth-flow): update refund info for expired orders --- .../src/common/updaters/orders/ExpiredOrdersUpdater.ts | 10 ++-------- .../swap/pure/EthFlow/EthFlowStepper/index.cosmos.tsx | 10 ++++++++-- libs/common-const/src/common.ts | 1 - 3 files changed, 10 insertions(+), 11 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..aaacd58ef2 100644 --- a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts +++ b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts @@ -1,6 +1,5 @@ import { useEffect, useCallback, useRef } from 'react' -import { EXPIRED_ORDERS_PENDING_TIME } from '@cowprotocol/common-const' import { SupportedChainId as ChainId } from '@cowprotocol/cow-sdk' import { useWalletInfo } from '@cowprotocol/wallet' @@ -24,7 +23,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 @@ -37,12 +35,8 @@ export function ExpiredOrdersUpdater(): null { // - 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() - - return ( - owner.toLowerCase() === lowerCaseAccount && now - creationTime < EXPIRED_ORDERS_PENDING_TIME && !refundHash - ) + const pending = expiredRef.current.filter(({ owner, refundHash }) => { + return owner.toLowerCase() === lowerCaseAccount && !refundHash }) if (pending.length === 0) { 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 From c20dbf2ac1de93e8d2797df5fdc963b7e001c5ba Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 13 Oct 2023 16:11:32 +0600 Subject: [PATCH 2/4] chore: update comment --- .../src/common/updaters/orders/ExpiredOrdersUpdater.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts index aaacd58ef2..e0a2adfbcb 100644 --- a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts +++ b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts @@ -33,7 +33,6 @@ export function ExpiredOrdersUpdater(): null { // Filter orders: // - Owned by the current connected account - // - Created in the last 5 min, no further // - Not yet refunded const pending = expiredRef.current.filter(({ owner, refundHash }) => { return owner.toLowerCase() === lowerCaseAccount && !refundHash From 1a06dd71394520339c2a914845b9d0b3d04383d5 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 13 Oct 2023 16:45:17 +0600 Subject: [PATCH 3/4] chore: fix ExpiredOrdersUpdater conditions --- .../src/common/updaters/orders/ExpiredOrdersUpdater.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts index e0a2adfbcb..1aef34d057 100644 --- a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts +++ b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts @@ -1,5 +1,6 @@ import { useEffect, useCallback, useRef } from 'react' +import { NATIVE_CURRENCY_BUY_ADDRESS } from '@cowprotocol/common-const' import { SupportedChainId as ChainId } from '@cowprotocol/cow-sdk' import { useWalletInfo } from '@cowprotocol/wallet' @@ -32,10 +33,13 @@ export function ExpiredOrdersUpdater(): null { isUpdating.current = true // Filter orders: + // - Only eth-flow orders // - Owned by the current connected account // - Not yet refunded - const pending = expiredRef.current.filter(({ owner, refundHash }) => { - return owner.toLowerCase() === lowerCaseAccount && !refundHash + const pending = expiredRef.current.filter(({ owner, refundHash, sellToken }) => { + const isEthFlowOrder = sellToken === NATIVE_CURRENCY_BUY_ADDRESS + + return isEthFlowOrder && owner.toLowerCase() === lowerCaseAccount && !refundHash }) if (pending.length === 0) { From 6b03ec1509b1bf9f95844e33cf04e85bbef0ab68 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 13 Oct 2023 17:11:13 +0600 Subject: [PATCH 4/4] chore: fix namings --- .../src/common/updaters/orders/ExpiredOrdersUpdater.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts index 1aef34d057..006c88b659 100644 --- a/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts +++ b/apps/cowswap-frontend/src/common/updaters/orders/ExpiredOrdersUpdater.ts @@ -32,24 +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 // - Not yet refunded - const pending = expiredRef.current.filter(({ owner, refundHash, sellToken }) => { + const orderWithoutRefund = expiredRef.current.filter(({ owner, refundHash, sellToken }) => { const isEthFlowOrder = sellToken === NATIVE_CURRENCY_BUY_ADDRESS 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)