From 9a311d4b1eded122a75c19178cc27209fc08d407 Mon Sep 17 00:00:00 2001 From: Rorry Date: Tue, 12 Dec 2023 11:55:29 -0300 Subject: [PATCH] fix(STK-218): Stack orders should show the correct cow order status (#142) * fix(STK-218): fix the way we handle the order status visualization --- .../stack-modal/StackOrdersTable.tsx | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/app/components/stack-modal/StackOrdersTable.tsx b/packages/app/components/stack-modal/StackOrdersTable.tsx index 3261cfae..15cb90f2 100644 --- a/packages/app/components/stack-modal/StackOrdersTable.tsx +++ b/packages/app/components/stack-modal/StackOrdersTable.tsx @@ -1,7 +1,7 @@ import { useState } from "react"; import Link from "next/link"; -import { Order as CowOrder } from "@cowprotocol/cow-sdk"; +import { Order as CowOrder, OrderStatus } from "@cowprotocol/cow-sdk"; import { addressShortner, convertedAmount, formatDate } from "@/utils"; import { @@ -26,6 +26,14 @@ import { useNetworkContext } from "@/contexts"; const INITIAL_NUMBER_OF_COW_ORDERS = 8; const MORE_ORDERS_NUMBER = 4; +enum CowOrderStatus { + PRESIGNATURE_PENDING = "presignaturePending", + OPEN = "open", + FULFILLED = "fulfilled", + CANCELLED = "cancelled", + EXPIRED = "expired", +} + export const StackOrdersTable = ({ stackOrder }: StackOrderProps) => { const initialCowOrders = stackOrder?.cowOrders?.slice(0, INITIAL_NUMBER_OF_COW_ORDERS) ?? []; @@ -83,6 +91,21 @@ export const StackOrdersTable = ({ stackOrder }: StackOrderProps) => { ); }; +const getOrderStatusText = ( + orderStatus: OrderStatus | CowOrderStatus, + price?: number +) => { + switch (orderStatus) { + case CowOrderStatus.FULFILLED: + return price?.toFixed(4); + case CowOrderStatus.CANCELLED: + case CowOrderStatus.EXPIRED: + case CowOrderStatus.PRESIGNATURE_PENDING: + return orderStatus; + case CowOrderStatus.OPEN: + return "in progress"; + } +}; const TableCowBody = ({ stackOrder, cowOrders, @@ -136,15 +159,9 @@ const TableCowBody = ({ - {cowOrder.status === "fulfilled" ? ( - - {averagePrice.toFixed(4)} - - ) : ( - - in progress - - )} + + {getOrderStatusText(cowOrder.status, averagePrice)} + );