Skip to content
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
1 change: 0 additions & 1 deletion src/components/Layout/Layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import classes from './Layout.module.css'
import {images} from "../../assets/images";
import LayoutHeader from "./LayoutHeader/LayoutHeader";
import {Outlet} from "react-router-dom";
import Footer from "../../main/Browser/Pages/UserPanel/Sections/Footer/Footer";
Expand Down
6 changes: 2 additions & 4 deletions src/components/Layout/LayoutHeader/LayoutHeader.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React from 'react';
import classes from './LayoutHeader.module.css';
import {useTranslation} from "react-i18next";
import {Link, NavLink, Route, Routes, useLocation, useParams} from "react-router-dom";
import {Link, NavLink, Route, Routes, useLocation} from "react-router-dom";
import * as RoutesName from "../../../main/Browser/Routes/routes";
import {Commission, Login} from "../../../main/Browser/Routes/routes";
import {Login} from "../../../main/Browser/Routes/routes";
import {toAbsoluteUrl} from "../../../utils/utils";
import Clock from "../../../main/Browser/Pages/UserPanel/Sections/Header/components/Clock/Clock";
import {images} from "../../../assets/images";
import {useDispatch, useSelector} from "react-redux";
import {logout} from "js-api-client";
import {toast} from "react-hot-toast";
import {setLogoutInitiate} from "../../../store/actions";
import AboutUs from "../../../main/Browser/Pages/Info/AboutUs/AboutUs";

const LayoutHeader = () => {
const {t} = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import classes from "./OrderBook.module.css";
import OrderBookTable from "./components/OrderBookTable/OrderBookTable";
import {useTranslation} from "react-i18next";
import {useSelector} from "react-redux";
import OrderBookTableSafari from "./components/OrderBookTableSafari/OrderBookTableSafari";
import {isSafari} from "react-device-detect";
import Error from "../../../../../../../../../../components/Error/Error";
import Loading from "../../../../../../../../../../components/Loading/Loading";
import {useOrderBook} from "../../../../../../../../../../queries";
Expand All @@ -23,18 +21,10 @@ const OrderBook = () => {
const tableRender = () => {
if (error) return <span className={`width-100`}><Error/></span>
if (isLoading) return <Loading/>

if (isSafari) {
return <>
<OrderBookTableSafari data={data.asks}/>
<OrderBookTableSafari data={data.bids} type="buy"/>
</>
} else {
return <>
<OrderBookTable data={data.asks}/>
<OrderBookTable data={data.bids} type="buy"/>
</>
}
return <>
<OrderBookTable data={data.asks}/>
<OrderBookTable data={data.bids} type="buy"/>
</>
}

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,76 +1,74 @@
import React, {useEffect, useState} from "react";
import classes from "./OrderBookTable.module.css";
import {useTranslation} from "react-i18next";
import {connect} from "react-redux";
import i18n from "i18next";
import {useDispatch, useSelector} from "react-redux";
import {BN} from "../../../../../../../../../../../../utils/utils";
import ScrollBar from "../../../../../../../../../../../../components/ScrollBar";
import {
setBestBuyPrice,
setBestSellPrice,
setBuyOrder,
setSellOrder
setBestBuyPrice,
setBestSellPrice,
setBuyOrder,
setSellOrder
} from "../../../../../../../../../../../../store/actions";

const OrderBookTable = (props) => {
const {t} = useTranslation();
const {activePair,data,type,onSetBuyOrder,onSetSellOrder,setBestSellPrice,setBestBuyPrice} = props
const OrderBookTable = ({data, type}) => {
const {t} = useTranslation();
const [selected, setSelected] = useState({buy: -1, sell: -1});
const activePair = useSelector((state) => state.exchange.activePair)
const dispatch = useDispatch();

const [selected, setSelected] = useState({buy: -1, sell: -1});
let header;

let header;
let totalAmount = data.reduce((total, asks) => parseFloat(asks[1]) + total, 0);
let avg = {pricePerUnit: new BN(0), amount: new BN(0), total: new BN(0)};
let start = "right";
let end = "left";

let totalAmount = data.reduce((total, asks) => parseFloat(asks[1]) + total, 0);
let avg = {pricePerUnit: new BN(0), amount: new BN(0), total: new BN(0)};
let start = "right";
let end = "left";

if (i18n.language === "en") {
start = "left";
end = "right";
}



if (type === "buy") {
header = (
<tr>
<th>{t("pricePerUnit")}</th>
<th>{t("volume")}</th>
<th>{t("totalPrice")}</th>
</tr>
);
} else {
header = (
<tr>
<th>{t("totalPrice")}</th>
<th>{t("volume")}</th>
<th>{t("pricePerUnit")}</th>
</tr>
);
}
useEffect(() => {
if (data.length > 0) {
totalAmount = data.reduce((total, asks) => parseFloat(asks[1]) + total, 0);
type === "buy"
? setBestSellPrice(data[0][0])
: setBestBuyPrice(data[0][0]);
if (i18n.language === "en") {
start = "left";
end = "right";
}
}, [data]);

const backgroundBar = (percent) => {
if (type === "buy") {
return {
background: `linear-gradient(to ${end}, var(--greenAlpha) ${percent}%, transparent ${percent}%) no-repeat`,
};
header = (
<div className="row jc-between">
<span className="width-30">{t("pricePerUnit")}</span>
<span className="width-30">{t("volume")}</span>
<span className="width-40">{t("totalPrice")}</span>
</div>
);
} else {
header = (
<div className="row jc-between">
<span className="width-40">{t("totalPrice")}</span>
<span className="width-30">{t("volume")}</span>
<span className="width-30">{t("pricePerUnit")}</span>
</div>
);
}
useEffect(() => {
if (data.length > 0) {
totalAmount = data.reduce((total, asks) => parseFloat(asks[1]) + total, 0);
type === "buy"
? dispatch(setBestSellPrice(data[0][0]))
: dispatch(setBestBuyPrice(data[0][0]));
}
}, [data]);

const backgroundBar = (percent) => {
if (type === "buy") {
return {
background: `linear-gradient(to ${end}, var(--greenAlpha) ${percent}%, transparent ${percent}%) no-repeat`,
};
}
return {
background: `linear-gradient(to ${start}, var(--redAlpha) ${percent}%, transparent ${percent}%) no-repeat`,
};
}
return {
background: `linear-gradient(to ${start}, var(--redAlpha) ${percent}%, transparent ${percent}%) no-repeat`,
};
}

const toolTipHandler = (average,index) => {
return `<div class="column jc-between col-100">
const toolTipHandler = (average, index) => {
return `<div class="column jc-between col-100">
<div class="row jc-between col-100">
<span class="pl-05">${t("averagePrice")}:</span>
<span>${average.pricePerUnit.dividedBy(index + 1).decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</span>
Expand All @@ -84,93 +82,80 @@ const OrderBookTable = (props) => {
<span>${average.total.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</span>
</div>
</div>`
}


return (
<div className={`column width-100 ${classes.container}`}>
<ScrollBar>
<table className="text-center" cellSpacing="0" cellPadding="0">
<thead>{header}</thead>
<tbody>
{data.map((tr, index) => {
const pricePerUnit = new BN(tr[0])
const amount = new BN(tr[1])
const percent = amount.multipliedBy(100).dividedBy(totalAmount)
const totalPrice = pricePerUnit.multipliedBy(amount)

avg = {
pricePerUnit: pricePerUnit.plus(avg.pricePerUnit),
amount: amount.plus(avg.amount),
total: totalPrice.plus(avg.total)
}
return type === "buy" ? (
<tr
key={index}
style={backgroundBar(percent.toString())}
onMouseEnter={() => setSelected({...selected, sell: index})}
onMouseLeave={() => setSelected({...selected, sell: -1})}
data-tooltip-id="opex-tooltip"
className={`${selected.sell >= index ? `${classes.selected}` : ""} cursor-pointer`}
data-tooltip-place="bottom"
data-tooltip-float={true}
data-tooltip-html={toolTipHandler(avg , index)}
data-amount={avg.amount.toString()}
onClick={(e) =>
onSetSellOrder({
pricePerUnit: pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toString(),
amount: parseFloat(e.currentTarget.getAttribute("data-amount")),
})
}>
<td>{pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</td>
<td>{amount.decimalPlaces(activePair.baseAssetPrecision).toFormat()}</td>
<td>{totalPrice.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</td>
</tr>
) : (
<tr
key={index}
style={backgroundBar(percent.toString())}
onMouseEnter={() => setSelected({...selected, buy: index})}
onMouseLeave={() => setSelected({...selected, buy: -1})}
data-tooltip-id="opex-tooltip"
className={`${selected.buy >= index ? `${classes.selected}` : ""} cursor-pointer`}
data-tooltip-place="bottom"
data-tooltip-float={true}
data-tooltip-html={toolTipHandler(avg , index)}
data-amount={avg.amount.toString()}
onClick={(e) =>
onSetBuyOrder({
pricePerUnit: parseFloat(pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toString()),
amount: parseFloat(e.currentTarget.getAttribute("data-amount")),
})
}>
<td>{totalPrice.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</td>
<td>{amount.decimalPlaces(activePair.baseAssetPrecision).toFormat()}</td>
<td>{pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</td>
</tr>
);
})}
</tbody>
</table>
</ScrollBar>
</div>
);
};

const mapStateToProps = (state) => {
return {
activePair: state.exchange.activePair,
activePairOrders: state.exchange.activePairOrders,
};
};
}

const mapDispatchToProps = (dispatch) => {
return {
onSetBuyOrder: (selected) => dispatch(setBuyOrder(selected)),
onSetSellOrder: (selected) => dispatch(setSellOrder(selected)),
setBestSellPrice: (bestSellPrice) => dispatch(setBestSellPrice(bestSellPrice)),
setBestBuyPrice: (bestBuyPrice) => dispatch(setBestBuyPrice(bestBuyPrice)),
};
return (
<div className={`column width-100 ${classes.container}`}>
<ScrollBar>
<div className="text-center">
<div className={` ${classes.thead} `}>{header}</div>
<div className={` ${classes.tbody} `}>
{data.map((tr, index) => {
const pricePerUnit = new BN(tr[0])
const amount = new BN(tr[1])
const percent = amount.multipliedBy(100).dividedBy(totalAmount)
const totalPrice = pricePerUnit.multipliedBy(amount)

avg = {
pricePerUnit: pricePerUnit.plus(avg.pricePerUnit),
amount: amount.plus(avg.amount),
total: totalPrice.plus(avg.total)
}
return type === "buy" ? (
<div
key={index}
style={backgroundBar(percent.toString())}
onMouseEnter={() => setSelected({...selected, sell: index})}
onMouseLeave={() => setSelected({...selected, sell: -1})}
data-tooltip-id="opex-tooltip"
className={`${selected.sell >= index ? `${classes.selected}` : ""} cursor-pointer row jc-between ${classes.tbodyRow}`}
data-tooltip-place="bottom"
data-tooltip-float={true}
data-tooltip-html={toolTipHandler(avg, index)}
data-amount={avg.amount.toString()}
onClick={(e) => dispatch(setSellOrder({
pricePerUnit: pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toString(),
amount: parseFloat(e.currentTarget.getAttribute("data-amount")),
}))}>
<span
className="width-30">{pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</span>
<span
className="width-30">{amount.decimalPlaces(activePair.baseAssetPrecision).toFormat()}</span>
<span
className="width-40">{totalPrice.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</span>
</div>
) : (
<div
key={index}
style={backgroundBar(percent.toString())}
onMouseEnter={() => setSelected({...selected, buy: index})}
onMouseLeave={() => setSelected({...selected, buy: -1})}
data-tooltip-id="opex-tooltip"
className={`${selected.buy >= index ? `${classes.selected}` : ""} cursor-pointer row jc-between ${classes.tbodyRow}`}
data-tooltip-place="bottom"
data-tooltip-float={true}
data-tooltip-html={toolTipHandler(avg, index)}
data-amount={avg.amount.toString()}
onClick={(e) =>
dispatch(setBuyOrder({
pricePerUnit: parseFloat(pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toString()),
amount: parseFloat(e.currentTarget.getAttribute("data-amount")),
}))
}>
<span
className="width-40">{totalPrice.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</span>
<span
className="width-30">{amount.decimalPlaces(activePair.baseAssetPrecision).toFormat()}</span>
<span
className="width-30">{pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}</span>
</div>
);
})}
</div>
</div>
</ScrollBar>
</div>
);
};

export default connect(mapStateToProps, mapDispatchToProps)(OrderBookTable);
export default OrderBookTable;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.container tr:nth-child(even) td {
.container .tbody .tbodyRow:nth-child(even) span{
background-color: var(--tableRow);
transition: background-color 0.4s;
}
Expand All @@ -24,7 +24,17 @@
:global .place-top::after {
border-top-color: var(--toolTipBG) !important;
}

.selected {
background: var(--orangeAlpha) !important;
}
.tbody{
line-height: 3.7vh;
}
.thead{
position: sticky;
top: 0;
z-index: 1;
font-weight: normal;
background-color: var(--tableHeader);
line-height: 3.7vh;
}
Loading