From 127357334197e616573df96fbbd8a25b0eef8ea2 Mon Sep 17 00:00:00 2001 From: Francois Date: Tue, 27 Feb 2024 14:03:08 +0100 Subject: [PATCH 1/2] Fix advanced order book showing incorrect values --- .../dex/trade/pro/create/receive/matching_bids_table.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/screens/dex/trade/pro/create/receive/matching_bids_table.dart b/lib/screens/dex/trade/pro/create/receive/matching_bids_table.dart index 5d452cff0..dd458391c 100644 --- a/lib/screens/dex/trade/pro/create/receive/matching_bids_table.dart +++ b/lib/screens/dex/trade/pro/create/receive/matching_bids_table.dart @@ -120,6 +120,10 @@ class _MatchingBidsTableState extends State { } 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( @@ -192,7 +196,7 @@ class _MatchingBidsTableState extends State { color: Theme.of(context).highlightColor, ))), child: Text( - formatPrice(bid.maxvolume.toDouble()), + formatPrice(convertedVolume), style: Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 13), ), @@ -215,7 +219,7 @@ class _MatchingBidsTableState extends State { 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), ), From d7e8737ea1161c15151d64ca3997e8a9989fff8b Mon Sep 17 00:00:00 2001 From: Francois Date: Tue, 27 Feb 2024 18:12:20 +0100 Subject: [PATCH 2/2] Fix order book incorrect received amount --- lib/model/orderbook.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/model/orderbook.dart b/lib/model/orderbook.dart index dd4cab835..5be8565a8 100644 --- a/lib/model/orderbook.dart +++ b/lib/model/orderbook.dart @@ -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; }