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

Order Book UI updates #114

Merged
merged 8 commits into from
Sep 19, 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
64 changes: 35 additions & 29 deletions src/app/components/OrderBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function OrderBookRow(props: OrderBookRowProps) {
} as CSSProperties;

return (
<div className="relative col-span-4 sized-columns text-xs">
<div style={barStyle}></div>
<div className="order-cell">{orderCount}</div>
<div className="relative col-span-4 sized-columns text-xs mb-0.5 py-0.5 ">
<div className="" style={barStyle}></div>
<div className="order-cell text-start ml-2">{orderCount}</div>
<div className="order-cell text-end">{priceString}</div>
<div className="order-cell text-end">{sizeString}</div>
<div className="order-cell text-end">{totalString}</div>
<div className="order-cell text-end mr-2">{totalString}</div>
</div>
);
}
Expand All @@ -45,7 +45,7 @@ function OrderBookRow(props: OrderBookRowProps) {
return <div className="text-center col-span-4">{props.absentOrders}</div>;
}

function MiddleRows() {
function CurrentPriceRow() {
const trades = useAppSelector((state) => state.accountHistory.trades);
const orderBook = useAppSelector((state) => state.orderBook);
const priceMaxDecimals = useAppSelector(
Expand Down Expand Up @@ -81,19 +81,23 @@ function MiddleRows() {

return (
<>
<div className="text-2xl col-span-2 my-1 py-1 border-t border-b">
<div className="text-2xl text-accent text-left col-span-2 my-1 py-1 ml-2">
{lastPrice}
</div>

<div className="flex justify-end col-span-2 text-xl my-1 py-1 border-t border-b whitespace-nowrap ">
<span className="text-sm my-auto">Spread</span>{" "}
<span className="my-auto pl-2">{spreadString}</span>
<div className="flex text-accent justify-end col-span-2 text-sm my-1 py-1 whitespace-nowrap">
<span className="my-auto">Spread</span>{" "}
<span className="my-auto px-1 border-r-2 border-accent">
{spreadString}
</span>
</div>
</>
);
} else {
return (
<div className="text-2xl col-span-4 border-t border-b">{lastPrice}</div>
<div className="text-2xl text-left col-span-4 border-r-2 border-accent ml-2">
{lastPrice}
</div>
);
}
}
Expand All @@ -109,31 +113,33 @@ export function OrderBook() {
const buys = useAppSelector((state) => state.orderBook.buys);

return (
<div className="p-2 text-sx">
<div className="sized-columns max-w-sm">
<div className="">
Order
<br />
Count
</div>
<div className="text-end">
Price
<br />({token2Symbol})
</div>
<div className="text-end">
Size
<br />({token1Symbol})
</div>
<div className="text-end">
Total
<br />({token1Symbol})
<div className="p-2 text-sx text-primary-content">
<div className="sized-columns">
<div className="sized-columns mx-2 col-span-4 text-sm text-secondary-content">
<div className="text-start">
Order
<br />
Count
</div>
<div className="text-end">
Price
<br />({token2Symbol})
</div>
<div className="text-end">
Size
<br />({token1Symbol})
</div>
<div className="text-end">
Total
<br />({token1Symbol})
</div>
</div>

{sells.map((props, index) => (
<OrderBookRow key={"sell-" + index} {...props} />
))}

<MiddleRows />
<CurrentPriceRow />

{buys.map((props, index) => (
<OrderBookRow key={"buy-" + index} {...props} />
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Home() {
<PriceChart />
</div>
</div>
<div className="col-span-5 hidden lg:block xl:hidden text-center border-r-4 border-base-300">
<div className="col-span-12 xl:hidden lg:col-span-5 lg:border-r-4 border-base-300">
<OrderBook />
</div>
<div className="min-h-[200px] col-span-12 lg:col-span-7 xl:col-span-12 text-center">
Expand Down
5 changes: 2 additions & 3 deletions src/app/redux/orderBookSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ export function toOrderBookRowProps(
const props: OrderBookRowProps[] = [];
let adexRows = [...adexOrderbookLines]; // copy the array so we can mutate it

// TODO: custom daisyui variable bar color
let barColor = "hsl(var(--su))";
let barColor = "hsl(var(--suc))";
if (side === "sell") {
adexRows.reverse();
barColor = "hsl(var(--er))";
barColor = "hsl(var(--erc))";
}
adexRows = adexRows.slice(0, 8); // Limit to 8 rows

Expand Down
10 changes: 6 additions & 4 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ module.exports = {
dark: {
...require("daisyui/src/theming/themes")["[data-theme=dark]"],
primary: "#292C35",
"primary-content": "#F6F6F7",
"primary-content": "#fff",
secondary: "#5C5E66",
"secondary-content": "#F6F6F7",
"secondary-content": "#858D92",
accent: "#BFED3F",
"accent-content": "#12141C",
neutral: "#292C34",
error: "#FF7A75",
"error-content": "#4D2929",
success: "#73D2BD",
"base-100": "#292C35",
"base-300": "#12141C",
"success-content": "#243E17",
"base-100": "#191B1D",
"base-300": "#000",
"base-content": "#F6F6F7",
"--rounded-btn": "0",
"--btn-text-case": "none",
Expand Down