-
Notifications
You must be signed in to change notification settings - Fork 133
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
Add book depth chart #219
Add book depth chart #219
Conversation
@@ -0,0 +1,172 @@ | |||
import React, { useEffect, useState } from "react" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice in React to always create index.ts|tsx
files, let me know what do you think
@@ -0,0 +1,29 @@ | |||
import { Theme } from "@nivo/core" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intended to be the default shared theme for future Nivo charts
5c1ef91
to
496f6fc
Compare
* Add WebLN support * Fix Variable Typo * Invoice Generation Signed-off-by: KoalaSat <111684255+KoalaSat@users.noreply.github.com> * Code Review * Second CR * Catch cancelations * Final Review Signed-off-by: KoalaSat <111684255+KoalaSat@users.noreply.github.com>
496f6fc
to
656328e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is perfect and really fun to use! Congratulations I am sure Robots will enjoy this feature. I certainly do 😄
- The chart theme is not sensitive to a switch between dark and light theme on the RoboSats app. The axes and numbers can only be seen with the dark theme (therefore not visible by default in Tor Browser). The lines themselves would also look prettier on the light theme if they were darker.
- I am unsure on how the (-) and (+) buttons are supposed to work. These are zoom-in and zoom-out buttons, but at the moment they do not seem to be specially useful, do you envision them being useful at some point?
- Given that the last day premium is located on the center as if it was the chart title, one instantly think that it is also the center of the Depth Chart, and that - and + will move you up and down in the X axis.
- I see finally you have left the X axis only in premium units. What happened to the X axes priced in Fiat units? :D Both are potentially very useful and informative. In fact, the fiat unit chosen for display could be the one in
this.props.currency
, to not leave behind those users who do not price life in USD.
All in all I think the chart might not need to display the last day average premium (or at least, not so prominently). What do you think?
Hypothetical cool things that could be done:
- On desktop, hovering the mouse shows a crosshair and the points can be "clicked". I am not sure if this is even possible, since the chart is aggregating the height of many orders... Is there a way we can overlay a small Tooltip with a little info about the order that matches that premium and has the highest volume on mouse hovering (E.g. RobotName, FiatAmount, Currency and Payment Method Icons)? That would be really top!!
axis: { | ||
ticks: { | ||
text: { | ||
fill: "rgb(255, 255, 255)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great if these variables can be dynamically set to match the colors defined in the MUI theme in App.js
. It is provided as context to all children. https://github.com/Reckless-Satoshi/robosats/blob/8eda1dd20fec576726cb1578e263bfb43472be48/frontend/src/components/App.js#L26-L42
This would solve the conflict we have now with the light/dark themes as well as make it future-proof for any possible theme change.
Take a look at MUI Theming and the use of the hook useTheme()
https://mui.com/material-ui/customization/theming/
frontend/src/components/BookPage.js
Outdated
<> | ||
<Button variant="contained" color='primary' to='/make/' component={Link}>{t("Make Order")}</Button> | ||
<Button color='inherit' style={{color: '#111111'}} onClick={this.handleClickView}> | ||
{ this.state.view == 'depth' ? t("List") : t("Depth") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of using "Chart" instead of "Depth"?
We could also add a small icon on this button so it is highlighted. For example:
// Chart Button
import BarChartIcon from '@mui/icons-material/BarChart';
// List Button
import FormatListBulletedIcon from '@mui/icons-material/FormatListBulleted';
b6087ab
to
7fb2767
Compare
I just thought + and - represent the range, but you are right I checked other exchanges and it's clearly a zoom
The point is, that value is the one that determines de exact middle X point on the chart, Y can hide it but I see it useful to easily understand where the chart is located.
I think with the magic of Nivo this should be easy peasy |
I understood the idea was just show, the premium, no problem I have that piece of code I can recover it |
Ah, I see! Maybe we can instead mark the "last 24h premium" as a dotted vertical line in the chart and label it inside the chart? It would be clearer in my opinion. Centered texts just above a chart usually are the title. |
That was my original idea but there is no way to make it appear 🥲 the documentation clearly allows it and it had an example but after trying over and over I found no way, I'll give another try with a workaround I don't like but maybe it'll make it work |
da2abaa
to
19c04c1
Compare
New Version looks cooler X Axis selector
TooltipAs suggested, I included a too-tip per point, the criteria to show one point or another is based on a boronoi map generated by Nivo. Clicking on the chart when a tool-tip is being displayed pushes the user to the order page. IMPORTANT Because I wanted to reuse the avatar code, I ended up refactoring a little bit the columns arrays on the book orders list, I hope that's fine, there was a couple of unnecessary loops, another unnecessary serialization and a lot of duplicated/unused code. Right now I think it looks cleaner :) Light/Dark ModeA function returns one theme or another base on Mui's theme, I decided to move the entire object in case in the future we want to reuse colors. Vertical middle lineI didn't manage to make it work 😅 |
payment_method: order.payment_method, | ||
price: order.price, | ||
premium: order.premium, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider this serialization unnecessary, we already have an book
object with all the information, I see no point on just changing names and confuse future developers
)} }, | ||
]} | ||
)} | ||
}]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In another iteration I see this array reusable for both tables, mobile and desktop
19c04c1
to
bf054de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This chart is soo much fun to use and look at! To me is already looking ready for merge. I requested a few tiny changes.
A couple of things we also might want to check:
- Switching the currency on the drop down menu does change the currency code shown on the chart, but does not change the tick labels of the X axis (They remain in USD)
- In mobile, when using Price in the X axis, the ticks of the X label become unreadable as they are too close to each other. Maybe the number of ticks has to be decimated.
- When hovering the mouse, for a fraction of a second, the tooltips show below the pointer, then on top. No issue whatsoever, yet when you are looking at tooltips on the bottom of the chart, the bigger size makes the vertical and horizontal scroll bars show. Just a tiny detail that might be too hard to fix to bother though...
(I was able to take this screenshot, but it lasts for a fraction of a second only)
All in all congrats! This is a feature robots will love 🚀
|
||
return bookLoading || !center || enrichedOrders.length < 1 ? ( | ||
<div style={{display: "flex", justifyContent: "center", paddingTop: 200, height: 420 }}> | ||
<CircularProgress /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chart feels sluggish to load if you switch a few times between List/Chart repeatedly. I believe this is because every single time the chart is loaded, there is a call to "/limits/" that has to be waited.
Do you think we could save /limits/
into the app state and from that point on only update that variable? (same as we do with the book orders)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I change it and now it only loads once :)
<PaymentText | ||
othersText={t("Others")} | ||
verbose={true} | ||
size={12} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe use size 20 or 22 for better visibility. Any cons to this bigger size?
xFormat={(value) => Number(value).toFixed(0)} | ||
lineWidth={3} | ||
theme={getNivoScheme(theme)} | ||
colors={['rgb(136, 252, 102)', 'rgb(255, 108, 57)']} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While orange and green is widely used for depth charts, we could give it a touch by sticking to the RoboSats color scheme. Throughout the UI we are loosely sticking to using purple for "things you click if you want to sell" and blue for "things you click on if you want to buy".
What do you think of this?
colors={[theme.palette.secondary.main,theme.palette.primary.main]}
These are the color references for the default MUI palette https://mui.com/material-ui/customization/palette/
When using these theme variables, the line colors will be brighter when the dark mode is enabled.
looks like something on Nivo, it only happens for the first tool tip that loads once the mouse hovers the charts, looks like the default position, which quickly gets the first configuration and changes, I don't see any way to change it from outside the library. |
Good news, I managed to generate the middle line 😄 I think I already covered all your comments @Reckless-Satoshi |
ef252f9
to
1b6ea99
Compare
It's looking great! I will take a more deep read at the code to understand myself everything that has been introduced before merging. So it might take 1-2 days until this PR is merge. Please, share a LN invoice for 300K with a long expiration time and from a proxy wallet. |
Take your time, any clarification or modification request will be welcome |
lnbc3m1p3shvrlpp5wtptd958lwqwekgrdctyf5geuzwu6j380wwqcpppqj0dhu2h2xesdq5g9kxy7fqd9h8vmmfvdjscqzpgxqyz5vqsp55mhyf3g3vadlnkcpuuamanlmc2npglwx5kr2dcqjslmdeunar73s9qyyssq3l20e72s82y6nlvfx2h6lp4cwwf64frslk8x928yvsqwyr0y66dkt389xku0tr7z26t8n4qqgqwuamu7phcnjyx4e73xez2u4y255kqqppql8a |
const calculateBtc = (order: Order): number => { | ||
const amount = parseInt(order.amount) || order.max_amount | ||
return amount / order.price | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calculus might potentially be included on the back-end response, I can even do it myself if that sounds good, I wasn't sure if there is any politics for including new attributes on the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be added to the API. It is still very fluid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking on creating a separate PR after we merge this one so we don't overcharge it, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's do that on a different PR. Take a look at the model Order and the var order.last_satoshis
, it keeps a snapshot of the size of the order in satoshis when it is created. Maybe it can be added as one of the response variable to the Book List API view. Is this enough or do we need it to be realtime ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be real time, consider everyone creates right now their orders and this night Bitcoin pumps up 20%, the amount of BTC you'll be able to buy tomorrow morning is going to be 20% more than the real quantity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found these 2:
https://github.com/Reckless-Satoshi/robosats/blob/eff58dc91d93fe98a6738e0e3898ed2a476d2ebc/api/models.py#L382
https://github.com/Reckless-Satoshi/robosats/blob/eff58dc91d93fe98a6738e0e3898ed2a476d2ebc/api/models.py#L390
but the only logic for t0_satoshis
is this:
Looks like there was an original intention to keep the sats on creation and the sats right now, that's cool, but at some point it got lost and last_satoshis
was used as t0_satoshis
.
I like the original idea, I had a look and there are not too many places where last_satoshis
is being used
https://github.com/Reckless-Satoshi/robosats/search?q=last_satoshis
do you believe it's a good idea to try a renaming so we use t0_satoshis
everywhere and start calculating last_satoshis
on every request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll move this conversation to an issue I can assign to myself so it doesn't get lost into this PR
data={series} | ||
enableArea={true} | ||
useMesh={true} | ||
animate={false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, the animation feature is cool, but on this case the X axis scale changes so drastically (from premium to price) that it really looks odd.
3037303861373334363436653765376562316364343532383730623833633163 (Funny, Alby wallet preimage HEX is always made only with decimal numbers!) |
I was also wondering what were the odds the first time 😄 |
ff3e913
to
e613cd9
Compare
* Amount X Axis, Avatars and refactor * Theme and performance improvements * Remove duplicated tooltips * Code Review * Marker Theme color * Missing end lines Signed-off-by: KoalaSat <111684255+KoalaSat@users.noreply.github.com>
* Amount X Axis, Avatars and refactor * Theme and performance improvements * Remove duplicated tooltips * Code Review * Marker Theme color * Missing end lines Signed-off-by: KoalaSat <111684255+KoalaSat@users.noreply.github.com>
* Amount X Axis, Avatars and refactor * Theme and performance improvements * Remove duplicated tooltips * Code Review * Marker Theme color * Missing end lines Signed-off-by: KoalaSat <111684255+KoalaSat@users.noreply.github.com>
* Amount X Axis, Avatars and refactor * Theme and performance improvements * Remove duplicated tooltips * Code Review * Marker Theme color * Missing end lines Signed-off-by: KoalaSat <111684255+KoalaSat@users.noreply.github.com>
* Amount X Axis, Avatars and refactor * Theme and performance improvements * Remove duplicated tooltips * Code Review * Marker Theme color * Missing end lines Signed-off-by: KoalaSat <111684255+KoalaSat@users.noreply.github.com>
describe("amountToString", () => { | ||
test("pn()", () => { | ||
[ | ||
{input: null, output: undefined}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KoalaSat just a heads up. After merging this PR the frontend build GH action was failing because it did not pass this test. I amended this test in the main branch.
Fixes #134
Max Zoom
Lines disappears after over passing Y Axis
Cross-hair
Mobile
Y Axis
X Axis