diff --git a/lib/model/swap_constructor_provider.dart b/lib/model/swap_constructor_provider.dart index 09662d35..ce1d8684 100644 --- a/lib/model/swap_constructor_provider.dart +++ b/lib/model/swap_constructor_provider.dart @@ -112,7 +112,7 @@ class ConstructorProvider extends ChangeNotifier { ? _matchingOrder.price : _matchingOrder.price.inverse; - final Rational maxOrderAmt = _matchingOrder.maxVolume / price; + final Rational maxOrderAmt = _matchingOrder.maxVolume; // if > than order max volume if (value > maxOrderAmt) { value = maxOrderAmt; @@ -460,14 +460,14 @@ class ConstructorProvider extends ChangeNotifier { } // if < than order min volume - final Rational minOrderVolume = _matchingOrder.minVolume; + final Rational price = _matchingOrder.action == Market.SELL + ? _matchingOrder.price + : _matchingOrder.price.inverse; + final Rational minOrderVolume = _matchingOrder.minVolume * price; if (minOrderVolume != null && _buyAmount != null && minOrderVolume > _buyAmount) { isValid = false; - final Rational price = _matchingOrder.action == Market.SELL - ? _matchingOrder.price - : _matchingOrder.price.inverse; final Rational minSellVolume = minOrderVolume / price; _error = 'Min order volume is' ' ${minSellVolume.toStringAsFixed(appConfig.tradeFormPrecision)}' diff --git a/lib/screens/dex/trade/pro/create/trade_form.dart b/lib/screens/dex/trade/pro/create/trade_form.dart index efcec6fb..d8eb4f5b 100644 --- a/lib/screens/dex/trade/pro/create/trade_form.dart +++ b/lib/screens/dex/trade/pro/create/trade_form.dart @@ -56,31 +56,23 @@ class TradeForm { } void updateAmountSell(Rational amount) { - // If greater than max available balance - final double maxAmount = _getMaxSellAmount(); - if (amount.toDouble() >= maxAmount) { - amount = Rational.parse(maxAmount.toString()); - swapBloc.setIsMaxActive(true); - } else { - swapBloc.setIsMaxActive(false); - } - + final Ask matchingBid = swapBloc.matchingBid; if (matchingBid != null) { final Rational bidPrice = fract2rat(matchingBid.priceFract) ?? Rational.parse(matchingBid.price); final Rational bidVolume = fract2rat(matchingBid.maxvolumeFract) ?? Rational.parse(matchingBid.maxvolume.toString()); - + // If greater than matching bid max receive volume - if (amount >= (bidVolume * bidPrice)) { - amount = bidVolume * bidPrice; + if (amount >= bidVolume ) { + amount = bidVolume; swapBloc.setIsMaxActive(false); - swapBloc.shouldBuyOut = true; + swapBloc.shouldBuyOut = false; } else { swapBloc.shouldBuyOut = false; } - + final Rational amountReceive = amount / bidPrice; updateAmountReceive(amountReceive); } @@ -255,7 +247,7 @@ class TradeForm { } void setMaxSellAmount() { - swapBloc.setIsMaxActive(true); + swapBloc.setIsMaxActive(false); final Rational max = Rational.parse(_getMaxSellAmount().toString()); if (max != swapBloc.amountSell) updateAmountSell(max); } diff --git a/lib/screens/dex/trade/pro/create/trade_page.dart b/lib/screens/dex/trade/pro/create/trade_page.dart index 0f1290da..cf6223cb 100644 --- a/lib/screens/dex/trade/pro/create/trade_page.dart +++ b/lib/screens/dex/trade/pro/create/trade_page.dart @@ -52,7 +52,7 @@ class _TradePageState extends State with TickerProviderStateMixin { _listeners.add(swapBloc.outAmountSell.listen(_onFormStateChange)); _listeners.add(swapBloc.outAmountReceive.listen(_onFormStateChange)); - tradeForm.updateMaxSellAmount(); + // tradeForm.updateMaxSellAmount(); _onFormStateChange(null); @@ -350,7 +350,7 @@ class _TradePageState extends State with TickerProviderStateMixin { swapBloc.updateSellCoin(coin); swapBloc.setEnabledSellField(true); - tradeForm.updateMaxSellAmount(); + // tradeForm.updateMaxSellAmount(); }, ); } @@ -385,10 +385,10 @@ class _TradePageState extends State with TickerProviderStateMixin { final Rational bidPrice = fract2rat(bid.priceFract); final Rational bidVolume = fract2rat(bid.maxvolumeFract); - if (amountSell > bidVolume * bidPrice) { - tradeForm.updateAmountSell(bidVolume * bidPrice); - swapBloc.setIsMaxActive(false); - } + // if (amountSell > bidVolume * bidPrice) { + // tradeForm.updateAmountSell(bidVolume * bidPrice); + // swapBloc.setIsMaxActive(false); + // } } void _showSnackbar(String text) {