Skip to content
Open
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
10 changes: 5 additions & 5 deletions lib/model/swap_constructor_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)}'
Expand Down
22 changes: 7 additions & 15 deletions lib/screens/dex/trade/pro/create/trade_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/screens/dex/trade/pro/create/trade_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _TradePageState extends State<TradePage> with TickerProviderStateMixin {
_listeners.add(swapBloc.outAmountSell.listen(_onFormStateChange));
_listeners.add(swapBloc.outAmountReceive.listen(_onFormStateChange));

tradeForm.updateMaxSellAmount();
// tradeForm.updateMaxSellAmount();

_onFormStateChange(null);

Expand Down Expand Up @@ -350,7 +350,7 @@ class _TradePageState extends State<TradePage> with TickerProviderStateMixin {

swapBloc.updateSellCoin(coin);
swapBloc.setEnabledSellField(true);
tradeForm.updateMaxSellAmount();
// tradeForm.updateMaxSellAmount();
},
);
}
Expand Down Expand Up @@ -385,10 +385,10 @@ class _TradePageState extends State<TradePage> 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) {
Expand Down