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

Avg Filled and Cleaned up placeholders #182

Merged
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
21 changes: 17 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 @@ -142,7 +147,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 +182,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 +213,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
10 changes: 10 additions & 0 deletions src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ export function calculateTotalFees(order: any): number {
: totalFees;
}

//Calculate the Avg Filled from recieved token amounts
export function calculateAvgFilled(tokenOne: number, tokenTwo: number): number {
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