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

Alphadex package update #184

Merged
merged 3 commits into from
Nov 2, 2023
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/node": "20.3.3",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"alphadex-sdk-js": "^0.11.6",
"alphadex-sdk-js": "^0.12.0",
"autoprefixer": "10.4.14",
"eslint-config-next": "13.4.7",
"lightweight-charts": "^4.0.1",
Expand Down
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
2 changes: 1 addition & 1 deletion src/app/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function initializeSubscriptions(store: AppStore) {
setRdt(rdtInstance);
// TODO: "black" on the light theme
rdtInstance.buttonApi.setTheme("white");
adex.init();
adex.init("stokenet");
subs.push(
adex.clientState.stateChanged$.subscribe((newState) => {
const serializedState: adex.StaticState = JSON.parse(
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