Skip to content

Commit

Permalink
Merge pull request #184 from nguvictor/alphadex-package-update
Browse files Browse the repository at this point in the history
Alphadex package update
  • Loading branch information
fliebenberg authored Nov 2, 2023
2 parents b7ae98d + e5be3e4 commit 9be1428
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
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

0 comments on commit 9be1428

Please sign in to comment.