feat: add real-time bond estimation to order form#2333
feat: add real-time bond estimation to order form#2333KoalaSat merged 4 commits intoRoboSats:mainfrom
Conversation
| fav.mode, | ||
| maker.coordinator, | ||
| federationUpdatedAt, | ||
| ]); |
There was a problem hiding this comment.
Calling this method here kind of isolates this logic from the rest, to help future developers understand whatś happening and even if we duplicate code, I did rather move this logic to a regular function and call it at the end of every handle...() function (when it applies), instead of checking so many maker attributes.
There was a problem hiding this comment.
Thanks for the feedback! I started implementing the changes as suggested, but I noticed that manually updating the bondAmount in every handler became quite complex (especially handling async state updates and child components).
I am worried that this manual approach might lead to bugs where the bond value gets out of sync with the inputs. Would you be open to extracting this logic into a custom hook instead? That way we can clean up the main component code as you requested, but still keep the calculation automatic and safe.
frontend/src/utils/bondCalculator.ts
Outdated
| } | ||
| } | ||
|
|
||
| if (amountToCalc === null) return null; |
There was a problem hiding this comment.
const amountToCalc: number = isRange ? maxAmount : amount
if (!amountToCalc) return null;
frontend/src/utils/bondCalculator.ts
Outdated
| } | ||
| } | ||
|
|
||
| return Math.round(tradeAmountSats * (bondSize / 100)); |
There was a problem hiding this comment.
Your calculations are great but it seems to always not match with the generated invoice by 1 sat. Probably the reason is that coordinators always round down. Implementing a round down here should do the trick: Math.floor(tradeAmountSats * (bondSize / 100));
KoalaSat
left a comment
There was a problem hiding this comment.
Great feature @FedericoLuque , thanks!!
Please accept a small tip for your work. Share a LN invoice for 60,000 sats with a long expiration date.
|
lnbc600u1p5k86dapp5j0v87xzyl3msya09yapehpzr4c7udjrptu850lncxr0dz3ruelgsdqqcqzzsxq9z0rgqsp5c3zs52juvcpd8ncf4t5wul239xe2slx3z95q3zxlzacglvv4w32s9qxpqysgqdqg3asj5ny7zye0v836j9uakztqpgympz5ffgrhwtt3kegp65nv808kqqktmy2u4v4q3unq5ynk2ulchuapf2cf8gz2wkzdmfxqz5jqq2jx4z4 |
|
f56f196567aa31ad44c901058145e55150713bfd2e4d43e195b217917c199c3a |
What does this PR do?
Fixes #2332
This PR introduces a real-time bondestimation feature to the Maker Order Form. It improves the User Experience by providing immediate feedback on the capital required to create an order, eliminating guesswork for the user.
Key Changes:
percentage.
This allows makers to know exactly how many sats they need in their wallet before clicking "Create Order".
Checklist before merging
pip install pre-commit, thenpre-commit install. Pre-commit installs git hooks that automatically check the codebase. If pre-commit fails when you commit your changes, please fix the problems it points out.