Skip to content

Commit

Permalink
Merge pull request #3455 from cowprotocol/hotfix/1.50.2
Browse files Browse the repository at this point in the history
Hotfix/1.50.2
  • Loading branch information
fairlighteth authored Nov 29, 2023
2 parents 0b2a8a5 + 162f48e commit 8a3ee43
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function emulatePartOrders(
const enrichedOrder = emulatePartAsOrder(item, parent)
const order = mapPartOrderToStoreOrder(item, enrichedOrder, isVirtualPart, parent, tokensByAddress)

acc.push(order)
if (order) {
acc.push(order)
}

return acc
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export function useEmulatedTwapOrders(tokensByAddress: TokensByAddress | undefin
return acc
}

acc.push(mapTwapOrderToStoreOrder(order, tokensByAddress))
const orderDetails = mapTwapOrderToStoreOrder(order, tokensByAddress)
if (orderDetails) {
acc.push(orderDetails)
}
return acc
}, [])
}, [allTwapOrders, accountLowerCase, chainId, tokensByAddress, refresher])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useTokensForOrdersList, getTokensListFromOrders, useSWRProdOrders } fro
import { twapOrdersAtom } from '../state/twapOrdersListAtom'
import { TwapPartOrderItem, twapPartOrdersListAtom, updatePartOrdersAtom } from '../state/twapPartOrdersAtom'
import { TwapOrderItem } from '../types'
import { mapPartOrderToStoreOrder } from '../utils/mapPartOrderToStoreOrder'
import { isOrder, mapPartOrderToStoreOrder } from '../utils/mapPartOrderToStoreOrder'

interface TwapOrderInfo {
item: TwapPartOrderItem
Expand Down Expand Up @@ -65,9 +65,11 @@ export function CreatedInOrderBookOrdersUpdater() {

const allTokens = await getTokensForOrdersList(getTokensListFromOrders(ordersInfo))

return ordersInfo.map(({ item, parent, order }) => {
return mapPartOrderToStoreOrder(item, order, isVirtualPart, parent, allTokens)
})
return ordersInfo
.map(({ item, parent, order }) => {
return mapPartOrderToStoreOrder(item, order, isVirtualPart, parent, allTokens)
})
.filter(isOrder)
},
[prodOrders, twapPartOrdersMap, getTokensForOrdersList, twapOrders],
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ export function mapPartOrderToStoreOrder(
isVirtualPart: boolean,
parent: TwapOrderItem,
tokensByAddress: TokensByAddress
): Order {
): Order | undefined {
const isCancelling = item.isCancelling || parent.status === TwapOrderStatus.Cancelling
const status = getPartOrderStatus(enrichedOrder, parent, isVirtualPart)

const inputToken = tokensByAddress[enrichedOrder.sellToken.toLowerCase()]
const outputToken = tokensByAddress[enrichedOrder.buyToken.toLowerCase()]

if (!inputToken || !outputToken) {
// FIXME: this is a hack to prevent errors, we should ensure this doesn't happen
console.error('mapTwapOrderToStoreOrder: inputToken or outputToken not found', { inputToken, outputToken })
return undefined
}

const storeOrder: Order = {
...enrichedOrder,
id: enrichedOrder.uid,
Expand All @@ -30,8 +39,8 @@ export function mapPartOrderToStoreOrder(
parentId: parent.id,
},
sellAmountBeforeFee: enrichedOrder.sellAmount,
inputToken: tokensByAddress[enrichedOrder.sellToken.toLowerCase()],
outputToken: tokensByAddress[enrichedOrder.buyToken.toLowerCase()],
inputToken,
outputToken,
creationTime: enrichedOrder.creationDate,
summary: '',
status,
Expand All @@ -45,3 +54,7 @@ export function mapPartOrderToStoreOrder(

return storeOrder
}

export function isOrder(order: Order | undefined): order is Order {
return !!order
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@ const statusesMap: Record<TwapOrderStatus, OrderStatus> = {
[TwapOrderStatus.Cancelling]: OrderStatus.PENDING,
}

export function mapTwapOrderToStoreOrder(order: TwapOrderItem, tokensByAddress: TokensByAddress): Order {
export function mapTwapOrderToStoreOrder(order: TwapOrderItem, tokensByAddress: TokensByAddress): Order | undefined {
const enrichedOrder = emulateTwapAsOrder(order)
const status = statusesMap[order.status]

const inputToken = tokensByAddress[enrichedOrder.sellToken.toLowerCase()]
const outputToken = tokensByAddress[enrichedOrder.buyToken.toLowerCase()]

if (!inputToken || !outputToken) {
// FIXME: this is a hack to prevent errors, we should ensure this doesn't happen
console.error('mapTwapOrderToStoreOrder: inputToken or outputToken not found', { inputToken, outputToken })
return undefined
}

const storeOrder: Order = {
...enrichedOrder,
id: enrichedOrder.uid,
composableCowInfo: {
id: order.id,
},
sellAmountBeforeFee: enrichedOrder.sellAmount,
inputToken: tokensByAddress[enrichedOrder.sellToken.toLowerCase()],
outputToken: tokensByAddress[enrichedOrder.buyToken.toLowerCase()],
inputToken,
outputToken,
creationTime: enrichedOrder.creationDate,
summary: '',
status,
Expand Down

2 comments on commit 8a3ee43

@vercel
Copy link

@vercel vercel bot commented on 8a3ee43 Nov 29, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 8a3ee43 Nov 29, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

cosmos – ./

cowswap-seven.vercel.app
cosmos-git-main-cowswap.vercel.app
cosmos-cowswap.vercel.app
cosmos.cow.fi

Please sign in to comment.