diff --git a/.gitignore b/.gitignore index 9d706fac..ea546958 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ next-env.d.ts /test-results/ /playwright-report/ /playwright/.cache/ + +localhost:3000/ diff --git a/.prettierignore b/.prettierignore index 95ee8ea2..2f4d2f7a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -37,5 +37,11 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts -logs/* -playwright-report/* +/logs/ +.swc/ +/test-results/ +/playwright-report/ +/playwright/.cache/ + +localhost:3000/ + diff --git a/src/app/components/AccountHistory.tsx b/src/app/components/AccountHistory.tsx index 3e3a8367..ad9311ce 100644 --- a/src/app/components/AccountHistory.tsx +++ b/src/app/components/AccountHistory.tsx @@ -1,34 +1,50 @@ -import React, { useEffect, useCallback } from "react"; -import { useAppDispatch, useAppSelector } from "../hooks"; +import React, { useEffect } from "react"; +import { useAppDispatch, useAppSelector } from "hooks"; import { - fetchAccountHistory, Tables, + fetchAccountHistory, + selectOpenOrders, setSelectedTable, - selectTables, -} from "../redux/accountHistorySlice"; +} from "redux/accountHistorySlice"; import { DisplayTable } from "./DisplayTable"; -interface ButtonProps { - label: string; - value: Tables; - selectedValue: Tables; - onClick: (value: Tables) => void; -} +function OrdersTabs() { + const dispatch = useAppDispatch(); + const { selectedTable, tables } = useAppSelector( + (state) => state.accountHistory + ); + const openOrders = useAppSelector(selectOpenOrders); + + function tabClass(isActive: boolean) { + return ( + "tab w-max no-underline h-full py-3 tab-border-1 uppercase" + + (isActive + ? " tab-active tab-bordered text-accent-focus !border-accent" + : "") + ); + } -const Button: React.FC = ({ - label, - value, - selectedValue, - onClick, -}) => ( - -); + return ( +
+
+ {tables.map((tableName) => ( +
dispatch(setSelectedTable(tableName))} + > + {tableName}{" "} + {tableName === Tables.OPEN_ORDERS && openOrders.length ? ( + + {openOrders.length} + + ) : null} +
+ ))} +
+
+ ); +} export function AccountHistory() { const dispatch = useAppDispatch(); @@ -36,51 +52,17 @@ export function AccountHistory() { (state) => state.radix?.walletData.accounts[0]?.address ); const pairAddress = useAppSelector((state) => state.pairSelector.address); - const selectedTable = useAppSelector( - (state) => state.accountHistory.selectedTable - ); - const tables = useAppSelector(selectTables); useEffect(() => { dispatch(fetchAccountHistory()); }, [dispatch, account, pairAddress]); - const handleButtonClick = useCallback( - (table: Tables) => { - dispatch(setSelectedTable(table)); - }, - [dispatch] - ); - return (
-
- {tables.map((table) => ( - - - className="btn btn-ghost normal-case text-xl" - aria-label="Export as CSV" - > - Export as CSV - */} + +
+
-
); } diff --git a/src/app/components/DisplayTable.tsx b/src/app/components/DisplayTable.tsx index c7bbe0bf..693a1816 100644 --- a/src/app/components/DisplayTable.tsx +++ b/src/app/components/DisplayTable.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useMemo } from "react"; import { useAppSelector, useAppDispatch } from "../hooks"; import { displayTime, displayOrderSide, calculateTotalFees } from "../utils"; import { @@ -12,6 +12,44 @@ interface TableProps { data: AccountHistoryState["orderHistory"]; } +import "../styles/table.css"; + +const headers = { + [Tables.OPEN_ORDERS]: [ + "Pair", + "Order Type", + "Direction", + "Time Ordered", + "Amount", + "Order Price", + "Filled Qty", + "Completed %", + "Action", + ], + [Tables.ORDER_HISTORY]: [ + "Pair", + "Order Type", + "Direction", + "Status", + "Filled Qty", + "Order Qty", + "Avg Filled Price", + "Order Price", + "Order Fee", + "Time Ordered", + "Action", + ], + [Tables.TRADE_HISTORY]: [ + "Pair", + "Direction", + "Order Price", + "Avg Filled Price", + "Filled Qty", + "Order Fee", + "Time Completed", + ], +}; + function ActionButton({ order, }: { @@ -28,7 +66,7 @@ function ActionButton({ cancelOrder({ orderId: order.id, pairAddress: order.pairAddress }) ); }} - className="text-lime-400 px-4 py-2 rounded hover:bg-lime-400 hover:text-black transition" + className="text-error hover:underline transition" > Cancel @@ -45,166 +83,142 @@ export function DisplayTable() { const orderHistory = useAppSelector(selectOrderHistory); const tradeHistory = useAppSelector(selectTradeHistory); - switch (selectedTable) { - case Tables.OPEN_ORDERS: - return ; - case Tables.ORDER_HISTORY: - return ; - case Tables.TRADE_HISTORY: - return ; - default: - return null; - } -} + const tableToShow = useMemo(() => { + switch (selectedTable) { + case Tables.OPEN_ORDERS: + return { + headers: headers[Tables.OPEN_ORDERS], + rows: , + }; + + case Tables.ORDER_HISTORY: + return { + headers: headers[Tables.ORDER_HISTORY], + rows: , + }; + + case Tables.TRADE_HISTORY: + return { + headers: headers[Tables.TRADE_HISTORY], + rows: , + }; + + default: + return { + headers: [], + rows: <>, + }; + } + }, [openOrders, orderHistory, selectedTable, tradeHistory]); -//TABLE FUNCTIONS -function OpenOrdersTable({ data }: TableProps) { return ( - - - - - - - - - - - - - - - - {data.length === 0 ? ( +
+
PairOrder TypeDirectionTime OrderedAmountOrder PriceFilled QtyCompleted %Action
+ - + {tableToShow.headers.map((header, i) => ( + + ))} - ) : ( - data.map((order) => ( - - - - - - - - - - - - )) - )} - -
No Active Orders + {header} +
{order.pairName}{order.orderType} - {displayOrderSide(order.side).text} - {displayTime(order.timeSubmitted, "full")} - {order.amount} {order.specifiedToken.symbol} - PlaceHolder {order.specifiedToken.symbol} - {order.amountFilled} {order.specifiedToken.symbol} - {order.completedPerc}% - -
+ + {tableToShow.rows} + +
); } -function OrderHistoryTable({ data }: TableProps) { - return ( - - - - - - - - - - - - - - - - - - {data.length === 0 ? ( - - - - ) : ( - data.map((order) => ( - - - - - - - - - - - - - - )) - )} - -
PairOrder TypeDirectionStatusFilled QtyOrder QtyAvg Filled PriceOrder PriceOrder FeeTime OrderedAction
No Order History to display
{order.pairName}{order.orderType} - {displayOrderSide(order.side).text} - {order.status} - {order.amountFilled} {order.specifiedToken.symbol} - - {order.amount} {order.specifiedToken.symbol} - - {order.price} {order.specifiedToken.symbol} - PlaceHolder {order.specifiedToken.symbol} - {calculateTotalFees(order)} {order.unclaimedToken.symbol} - {displayTime(order.timeSubmitted, "full")} - -
+const OpenOrdersRows = ({ data }: TableProps) => { + return data.length ? ( + data.map((order) => ( + + {order.pairName} + {order.orderType} + + {displayOrderSide(order.side).text} + + {displayTime(order.timeSubmitted, "full")} + + {order.amount} {order.specifiedToken.symbol} + + PlaceHolder {order.specifiedToken.symbol} + + {order.amountFilled} {order.specifiedToken.symbol} + + {order.completedPerc}% + + + + + )) + ) : ( + + No Active Orders + ); -} +}; -function TradeHistoryTable({ data }: TableProps) { - return ( - - - - - - - - - - - - - - {data.length === 0 ? ( - - - - ) : ( - data.map((order) => ( - - - - - - - - - - )) - )} - -
PairDirectionOrder PriceAvg Filled PriceFilled QtyOrder FeeTime Completed
No Trade History to display
{order.pairName} - {displayOrderSide(order.side).text} - PlaceHolder {order.specifiedToken.symbol} - {order.price} {order.specifiedToken.symbol} - - {order.amountFilled} {order.specifiedToken.symbol} - - {calculateTotalFees(order)} {order.unclaimedToken.symbol} - {displayTime(order.timeCompleted, "full")}
+const OrderHistoryRows = ({ data }: TableProps) => { + return data.length ? ( + data.map((order) => ( + + {order.pairName} + {order.orderType} + + {displayOrderSide(order.side).text} + + {order.status} + + {order.amountFilled} {order.specifiedToken.symbol} + + + {order.amount} {order.specifiedToken.symbol} + + + {order.price} {order.specifiedToken.symbol} + + PlaceHolder {order.specifiedToken.symbol} + + {calculateTotalFees(order)} {order.unclaimedToken.symbol} + + {displayTime(order.timeSubmitted, "full")} + + + + + )) + ) : ( + + No Order History + ); -} +}; + +const TradeHistoryTable = ({ data }: TableProps) => { + return data.length ? ( + data.map((order) => ( + + {order.pairName} + + {displayOrderSide(order.side).text} + + PlaceHolder {order.specifiedToken.symbol} + + {order.price} {order.specifiedToken.symbol} + + + {order.amountFilled} {order.specifiedToken.symbol} + + + {calculateTotalFees(order)} {order.unclaimedToken.symbol} + + {displayTime(order.timeCompleted, "full")} + + )) + ) : ( + + No Trade History + + ); +}; diff --git a/src/app/components/PairSelector.tsx b/src/app/components/PairSelector.tsx index 5d19ab1d..30100c4e 100644 --- a/src/app/components/PairSelector.tsx +++ b/src/app/components/PairSelector.tsx @@ -9,10 +9,7 @@ export function PairSelector() { }; return (
-