Skip to content

Commit

Permalink
added avgFilled, updated tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed Oct 28, 2023
1 parent b7ae98d commit 0f2a315
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/app/components/DisplayTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React, { useMemo } from "react";
import { useAppSelector, useAppDispatch } from "../hooks";
import { displayTime, displayOrderSide, calculateTotalFees } from "../utils";
import {
displayTime,
displayOrderSide,
calculateTotalFees,
calculateAvgFilled,
} from "../utils";
import {
cancelOrder,
selectOpenOrders,
Expand Down Expand Up @@ -82,6 +87,7 @@ export function DisplayTable() {
const openOrders = useAppSelector(selectOpenOrders);
const orderHistory = useAppSelector(selectOrderHistory);
const tradeHistory = useAppSelector(selectTradeHistory);
console.log(orderHistory);

Check warning on line 90 in src/app/components/DisplayTable.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

const tableToShow = useMemo(() => {
switch (selectedTable) {
Expand Down Expand Up @@ -142,7 +148,9 @@ const OpenOrdersRows = ({ data }: TableProps) => {
<td>
{order.amount} {order.specifiedToken.symbol}
</td>
<td>PlaceHolder {order.specifiedToken.symbol}</td>
<td>
{order.price} {order.specifiedToken.symbol}
</td>
<td>
{order.amountFilled} {order.specifiedToken.symbol}
</td>
Expand Down Expand Up @@ -175,10 +183,13 @@ const OrderHistoryRows = ({ data }: TableProps) => {
<td>
{order.amount} {order.specifiedToken.symbol}
</td>
<td>
{calculateAvgFilled(order.token1Filled, order.token2Filled)}{" "}
{order.specifiedToken.symbol}
</td>
<td>
{order.price} {order.specifiedToken.symbol}
</td>
<td>PlaceHolder {order.specifiedToken.symbol}</td>
<td>
{calculateTotalFees(order)} {order.unclaimedToken.symbol}
</td>
Expand All @@ -203,10 +214,13 @@ const TradeHistoryTable = ({ data }: TableProps) => {
<td className={displayOrderSide(order.side).className}>
{displayOrderSide(order.side).text}
</td>
<td>PlaceHolder {order.specifiedToken.symbol}</td>
<td>
{order.price} {order.specifiedToken.symbol}
</td>
<td>
{calculateAvgFilled(order.token1Filled, order.token2Filled)}{" "}
{order.specifiedToken.symbol}
</td>
<td>
{order.amountFilled} {order.specifiedToken.symbol}
</td>
Expand Down
11 changes: 11 additions & 0 deletions src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ export function calculateTotalFees(order: any): number {
: totalFees;
}

//Calculate the Avg Filled from recieved token amounts
export function calculateAvgFilled(tokenOne: number, tokenTwo: number): number {
console.log(tokenOne, tokenTwo);

Check warning on line 318 in src/app/utils.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
if (tokenOne == 0 || tokenTwo == 0) return 0;
const avgFilled = tokenTwo / tokenOne;
const decimalPart = (avgFilled % 1).toString().split(".")[1];
return decimalPart && decimalPart.length > 8
? roundTo(avgFilled, 8, RoundType.NEAREST)
: avgFilled;
}

//Chart Helper Functions
export const formatPercentageChange = (percChange: number | null): string => {
if (percChange !== null) {
Expand Down

0 comments on commit 0f2a315

Please sign in to comment.