From 23ca9e319ff86f3dbcdbdbafa6145d548b5fbd48 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Wed, 5 Jul 2023 22:56:30 +1000 Subject: [PATCH] feat(app): Consider fee when assessing usable balance --- mobile/lib/features/trade/trade_bottom_sheet_tab.dart | 3 ++- mobile/lib/features/trade/trade_value_change_notifier.dart | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mobile/lib/features/trade/trade_bottom_sheet_tab.dart b/mobile/lib/features/trade/trade_bottom_sheet_tab.dart index 0ef0431f6..e7b641d39 100644 --- a/mobile/lib/features/trade/trade_bottom_sheet_tab.dart +++ b/mobile/lib/features/trade/trade_bottom_sheet_tab.dart @@ -231,7 +231,8 @@ class _TradeBottomSheetTabState extends State { }); } - if (usableBalance < margin) { + Amount fee = provider.orderMatchingFee(direction) ?? Amount.zero(); + if (usableBalance < margin + fee.sats) { return "Insufficient balance"; } diff --git a/mobile/lib/features/trade/trade_value_change_notifier.dart b/mobile/lib/features/trade/trade_value_change_notifier.dart index 14b4dd931..766d04d60 100644 --- a/mobile/lib/features/trade/trade_value_change_notifier.dart +++ b/mobile/lib/features/trade/trade_value_change_notifier.dart @@ -67,6 +67,10 @@ class TradeValuesChangeNotifier extends ChangeNotifier implements Subscriber { } } + Amount? orderMatchingFee(Direction direction) { + return fromDirection(direction).fee; + } + void updateQuantity(Direction direction, double quantity) { fromDirection(direction).updateQuantity(quantity); notifyListeners();