Skip to content

feat: add real-time bond estimation to order form#2333

Merged
KoalaSat merged 4 commits intoRoboSats:mainfrom
FedericoLuque:feature/order-creation-bond-preview
Jan 11, 2026
Merged

feat: add real-time bond estimation to order form#2333
KoalaSat merged 4 commits intoRoboSats:mainfrom
FedericoLuque:feature/order-creation-bond-preview

Conversation

@FedericoLuque
Copy link
Contributor

@FedericoLuque FedericoLuque commented Dec 23, 2025

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:

  • Real-time Calculation: Added logic to calculate the required Fidelity Bond in sats dynamically as the user adjusts the Amount, Premium, or Bond Size
    percentage.
  • UI Update: Displays the "Estimated Bond: [Value] Sats" directly below the order summary text in the Maker Form.
  • New Utility: Created frontend/src/utils/bondCalculator.ts to centralize the bond calculation logic, supporting both Fiat and Swap modes.
  • Edge Cases: Handles Amount Ranges by calculating the bond based on the maximum amount in the range to ensure safety.
  • Localization: Added translations for the string "Estimated Bond" across all supported languages.

This allows makers to know exactly how many sats they need in their wallet before clicking "Create Order".

Checklist before merging

  • Install pre-commit and initialize it: pip install pre-commit, then pre-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.

fav.mode,
maker.coordinator,
federationUpdatedAt,
]);
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, Let's give it a try.

}
}

if (amountToCalc === null) return null;
Copy link
Member

Choose a reason for hiding this comment

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

const amountToCalc: number = isRange ? maxAmount : amount

  if (!amountToCalc) return null;

}
}

return Math.round(tradeAmountSats * (bondSize / 100));
Copy link
Member

Choose a reason for hiding this comment

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

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));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, done!

Copy link
Member

@KoalaSat KoalaSat left a comment

Choose a reason for hiding this comment

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

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.

@KoalaSat KoalaSat merged commit 188326e into RoboSats:main Jan 11, 2026
6 checks passed
@FedericoLuque
Copy link
Contributor Author

lnbc600u1p5k86dapp5j0v87xzyl3msya09yapehpzr4c7udjrptu850lncxr0dz3ruelgsdqqcqzzsxq9z0rgqsp5c3zs52juvcpd8ncf4t5wul239xe2slx3z95q3zxlzacglvv4w32s9qxpqysgqdqg3asj5ny7zye0v836j9uakztqpgympz5ffgrhwtt3kegp65nv808kqqktmy2u4v4q3unq5ynk2ulchuapf2cf8gz2wkzdmfxqz5jqq2jx4z4

@RobosatsDevFund
Copy link

f56f196567aa31ad44c901058145e55150713bfd2e4d43e195b217917c199c3a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Real-time Estimated Bond Preview in Maker Order Form

3 participants