From dc5ce37dc704ddfa0274b24b28dae7bf3a39df65 Mon Sep 17 00:00:00 2001
From: fairlighteth <31534717+fairlighteth@users.noreply.github.com>
Date: Thu, 9 Jan 2025 15:48:24 +0000
Subject: [PATCH] feat: show TWAP parent fill price for next scheduled order
---
.../containers/OrdersTableWidget/index.tsx | 1 -
.../OrdersTableContainer/OrderRow/index.tsx | 90 ++++++++++++++++---
2 files changed, 79 insertions(+), 12 deletions(-)
diff --git a/apps/cowswap-frontend/src/modules/ordersTable/containers/OrdersTableWidget/index.tsx b/apps/cowswap-frontend/src/modules/ordersTable/containers/OrdersTableWidget/index.tsx
index 90dd733c10..2f8bb269ef 100644
--- a/apps/cowswap-frontend/src/modules/ordersTable/containers/OrdersTableWidget/index.tsx
+++ b/apps/cowswap-frontend/src/modules/ordersTable/containers/OrdersTableWidget/index.tsx
@@ -12,7 +12,6 @@ import styled from 'styled-components/macro'
import { Order } from 'legacy/state/orders/actions'
import { useInjectedWidgetParams } from 'modules/injectedWidget'
-import { limitOrdersSettingsAtom } from 'modules/limitOrders/state/limitOrdersSettingsAtom'
import { pendingOrdersPricesAtom } from 'modules/orders/state/pendingOrdersPricesAtom'
import { useGetSpotPrice } from 'modules/orders/state/spotPricesAtom'
import { BalancesAndAllowances } from 'modules/tokens'
diff --git a/apps/cowswap-frontend/src/modules/ordersTable/pure/OrdersTableContainer/OrderRow/index.tsx b/apps/cowswap-frontend/src/modules/ordersTable/pure/OrdersTableContainer/OrderRow/index.tsx
index 12ec8ecdbc..ccadae546b 100644
--- a/apps/cowswap-frontend/src/modules/ordersTable/pure/OrdersTableContainer/OrderRow/index.tsx
+++ b/apps/cowswap-frontend/src/modules/ordersTable/pure/OrdersTableContainer/OrderRow/index.tsx
@@ -262,6 +262,70 @@ export function OrderRow({
)
const renderFillsAtWithDistance = () => {
+ // For TWAP parent orders, show the next scheduled child order's fills at price
+ if (children) {
+ // Get the next scheduled order from the children prop
+ const childrenArray = React.Children.toArray(children) as React.ReactElement<{ order: ParsedOrder }>[]
+ const nextScheduledOrder = childrenArray
+ .map((child) => child.props.order)
+ .find((childOrder) => {
+ return childOrder && childOrder.status === OrderStatus.SCHEDULED && !getIsFinalizedOrder(childOrder)
+ })
+
+ if (nextScheduledOrder) {
+ // Get the execution price from the next scheduled order
+ const nextOrderExecutionPrice = nextScheduledOrder.executionData.executedPrice
+ const nextOrderPriceDiffs = calculatePriceDifference({
+ referencePrice: spotPrice,
+ targetPrice: nextOrderExecutionPrice,
+ isInverted: false,
+ })
+
+ // Show the execution price for the next scheduled order
+ let nextOrderFillsAtContent
+ if (nextScheduledOrder.status === OrderStatus.CANCELLED || nextScheduledOrder.isUnfillable) {
+ nextOrderFillsAtContent = ''
+ } else if (!nextOrderExecutionPrice || nextScheduledOrder.status === OrderStatus.CREATING) {
+ nextOrderFillsAtContent = '-'
+ } else {
+ nextOrderFillsAtContent = (
+
+ )
+ }
+
+ const nextOrderDistance = nextOrderPriceDiffs?.percentage
+ ? `${nextOrderPriceDiffs.percentage.toFixed(2)}%`
+ : '-'
+
+ return (
+
+ {nextOrderFillsAtContent}
+
+ {nextOrderDistance}
+
+
+ )
+ }
+
+ // If no scheduled orders found, show dash
+ return (
+
+ -
+
+ )
+ }
+
+ // Regular order display logic
const fillsAtContent = renderFillsAt()
const distance =
getIsFinalizedOrder(order) ||
@@ -290,7 +354,9 @@ export function OrderRow({
const renderMarketPrice = () => (
<>
- {order.status === OrderStatus.CANCELLED || withWarning ? (
+ {children ? (
+ '-'
+ ) : order.status === OrderStatus.CANCELLED || withWarning ? (
'-'
) : spotPrice ? (
{/* Status label */}
-
-
-
-
-
+ {!children && (
+
+
+
+
+
+ )}
{/* Children (e.g. ToggleExpandButton for parent orders) */}
{children}