Skip to content

Commit

Permalink
fix(eth-flow): update refund info for expired orders (#3222)
Browse files Browse the repository at this point in the history
* fix(eth-flow): update refund info for expired orders

* chore: update comment

* chore: fix ExpiredOrdersUpdater conditions

* chore: fix namings
  • Loading branch information
shoom3301 authored Oct 16, 2023
1 parent 79cb48a commit dede0d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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 '.'

Expand Down Expand Up @@ -376,20 +377,25 @@ 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),
})
const props = STEPS_BY_DESCRIPTION[stepDescription]

return (
<>
<Wrapper>
<EthFlowStepper {...props} />
<h3>Params</h3>
<div>
<pre>{JSON.stringify(props, null, 2)}</pre>
</div>
</>
</Wrapper>
)
}

Expand Down
1 change: 0 additions & 1 deletion libs/common-const/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dede0d0

Please sign in to comment.