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

Fix advanced swap order book showing incorrect values #119

Merged
merged 2 commits into from
Mar 6, 2024
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
14 changes: 12 additions & 2 deletions lib/model/orderbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,18 @@ class Ask {

Rational getReceiveAmount(Rational amountToSell) {
Rational buyAmount = amountToSell / fract2rat(priceFract);
if (buyAmount >= fract2rat(maxvolumeFract))
buyAmount = fract2rat(maxvolumeFract);
final Rational buyBaseAmount = buyAmount * fract2rat(priceFract);

final Rational maxVolumeBase = fract2rat(maxvolumeFract);
final Rational maxVolumeRel =
fract2rat(maxvolumeFract) / fract2rat(priceFract);

final bool askRelGreaterThanMaxRelVolume = buyAmount >= maxVolumeRel;
final bool askBaseGreaterThanMaxBaseVolume = buyBaseAmount >= maxVolumeBase;

if (askRelGreaterThanMaxRelVolume || askBaseGreaterThanMaxBaseVolume) {
buyAmount = maxVolumeRel;
}
return buyAmount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class _MatchingBidsTableState extends State<MatchingBidsTable> {
}

TableRow _tableRow(Ask bid, int index) {
/// Convert the USD equivalent of the bid volume to the receive coin amount
final double _bidVolume = bid.maxvolume.toDouble();
final double convertedVolume = _bidVolume / bid.priceRat.toDouble();

return TableRow(
children: [
TableRowInkWell(
Expand Down Expand Up @@ -192,7 +196,7 @@ class _MatchingBidsTableState extends State<MatchingBidsTable> {
color: Theme.of(context).highlightColor,
))),
child: Text(
formatPrice(bid.maxvolume.toDouble()),
formatPrice(convertedVolume),
style:
Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 13),
),
Expand All @@ -215,7 +219,7 @@ class _MatchingBidsTableState extends State<MatchingBidsTable> {
color: Theme.of(context).highlightColor,
))),
child: Text(
formatPrice(bid.maxvolume.toDouble() * double.parse(bid.price)),
formatPrice(convertedVolume * double.parse(bid.price)),
style:
Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 13),
),
Expand Down
Loading