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

chore(orderbook): update orderbook to not be scrollable #846

Merged

Conversation

moo-onthelawn
Copy link
Contributor

@moo-onthelawn moo-onthelawn commented Jul 23, 2024

try #2 which is 100x simpler than my last thing I was trying cuz I think my brain was non functional the first round

Goal: To make the orderbook not scrollable (fixed height-ish) while still maintaining the reponsiveness of the screen sizing:

We still want the orderbook to grow when the height of the screen grows
We still want the whole page to fit on any (reasonably sized) screen without scrolling
We want the orderbook to be just large enough to show x rows, centered such that the price row is in the middle

Solution:

  1. Calculate the approximate size of the div of the canvas orderbook
  2. Calculate the number of rows we can render in this div
  3. Recalculate when browser or div resizes (latter happens without browser resizing if we just zoom in/out) using resizeObserver

EDIT: used resizeObserver and things work way better now

Unrelated polish included in this PR

  • Fix orderbook on TradeForm mobile view (changes here)
before after
Screenshot 2024-07-23 at 5 58 46 PM Screenshot 2024-07-23 at 5 59 16 PM
resizingWindow.mov
zoomInAndOut.mov

Things I did not do in this PR

  • Add a 50x resolution (we currently have 0.1, 1, 10, 100) - happy to do so in follow up if we get feedback but didn't seem super necessary rn

Views

  • forms/TradeForm
    • Changes to make orderbook look better on mobile view
  • views/CanvasOrderbook
    • Rename maxRowsPerSide to rowsPerSide

Components

  • VerticalPanel
    • Bulk of the logic
    • Adds a ref to the canvasOrderbook tab and use resizeObserver off of that to calculate the number of rows we can render without scrolling

Constants/Types

  • constants/orderbook.ts
    • Add approximate pixel height of orderbook header for calculations on how many rows we can render

Hooks

  • hooks/useDrawOrderbook

    • Not really any changes, just wrapped everything in useCallback and fixed up the useEffect dependencies
    • Updated windowResize listener to resizeObserver
  • hooks/useCalculateOrderbookData

    • Rename maxRowsPerSide to rowsPerSide

Copy link

vercel bot commented Jul 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
v4-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 27, 2024 0:44am
v4-testnet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 27, 2024 0:44am

Copy link

linear bot commented Jul 23, 2024

src/pages/trade/VerticalPanel.tsx Outdated Show resolved Hide resolved
src/pages/trade/VerticalPanel.tsx Outdated Show resolved Hide resolved
src/hooks/Orderbook/useDrawOrderbook.ts Outdated Show resolved Hide resolved

// Handle resize, sync to state
useEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last thing - do we support IE? Looks like even latest internet explorer doesn't support this.

Copy link
Contributor Author

@moo-onthelawn moo-onthelawn Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked in slack

tl;dr: nope (because you can't even connect a wallet on IE).
longer answer: stats show that none of our users use IE. Checked ResizeObserver on caniuse and seems like we should be safe outside of IE and OperaMini (the latter I think is fine since it's supported in Opera)

Copy link
Contributor

@tyleroooo tyleroooo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good but please check with @jaredvu who was generally opposed to merging this last week iirc.

@moo-onthelawn moo-onthelawn merged commit fa41976 into main Aug 5, 2024
6 checks passed
@moo-onthelawn moo-onthelawn deleted the mulan/ct-997-condense-orderbook-view-to-not-be-scrollable2 branch August 5, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants