Skip to content

Commit

Permalink
Merge pull request #119 from KomodoPlatform/fix/advanced-orderbook-va…
Browse files Browse the repository at this point in the history
…lues

Fix advanced swap order book showing incorrect values
  • Loading branch information
CharlVS authored Mar 6, 2024
2 parents 47fece1 + d7e8737 commit 571a223
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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

0 comments on commit 571a223

Please sign in to comment.