Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into develop #3457

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.50.2](https://github.com/cowprotocol/cowswap/compare/v1.50.1...v1.50.2) (2023-11-29)


### Bug Fixes

* make typescript happy ([24d3924](https://github.com/cowprotocol/cowswap/commit/24d39246a5343656b402671a5bca8cbc94b79242))

## [1.50.1](https://github.com/cowprotocol/cowswap/compare/v1.50.0...v1.50.1) (2023-11-27)


Expand Down
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 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cowswap",
"version": "1.50.1",
"version": "1.50.2",
"description": "CoW Swap",
"main": "index.js",
"author": "",
Expand Down
Loading