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