diff --git a/lib/pages/send_view/send_view.dart b/lib/pages/send_view/send_view.dart index aaae70d97..d6dd4b0c1 100644 --- a/lib/pages/send_view/send_view.dart +++ b/lib/pages/send_view/send_view.dart @@ -159,6 +159,20 @@ class _SendViewState extends ConsumerState { } } + int _currentFee = 0; + + void _setCurrentFee(String fee, bool shouldSetState) { + final value = Format.decimalAmountToSatoshis( + Decimal.parse(fee), + coin, + ); + if (shouldSetState) { + setState(() => _currentFee = value); + } else { + _currentFee = value; + } + } + String? _updateInvalidAddressText(String address, Manager manager) { if (_data != null && _data!.contactLabel == address) { return null; @@ -328,45 +342,48 @@ class _SendViewState extends ConsumerState { selectedUTXOs.isEmpty)) { // confirm send all if (amount == availableBalance) { - final bool? shouldSendAll = await showDialog( - context: context, - useSafeArea: false, - barrierDismissible: true, - builder: (context) { - return StackDialog( - title: "Confirm send all", - message: - "You are about to send your entire balance. Would you like to continue?", - leftButton: TextButton( - style: Theme.of(context) - .extension()! - .getSecondaryEnabledButtonStyle(context), - child: Text( - "Cancel", - style: STextStyles.button(context).copyWith( - color: Theme.of(context) - .extension()! - .accentColorDark), + bool? shouldSendAll; + if (mounted) { + shouldSendAll = await showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return StackDialog( + title: "Confirm send all", + message: + "You are about to send your entire balance. Would you like to continue?", + leftButton: TextButton( + style: Theme.of(context) + .extension()! + .getSecondaryEnabledButtonStyle(context), + child: Text( + "Cancel", + style: STextStyles.button(context).copyWith( + color: Theme.of(context) + .extension()! + .accentColorDark), + ), + onPressed: () { + Navigator.of(context).pop(false); + }, ), - onPressed: () { - Navigator.of(context).pop(false); - }, - ), - rightButton: TextButton( - style: Theme.of(context) - .extension()! - .getPrimaryEnabledButtonStyle(context), - child: Text( - "Yes", - style: STextStyles.button(context), + rightButton: TextButton( + style: Theme.of(context) + .extension()! + .getPrimaryEnabledButtonStyle(context), + child: Text( + "Yes", + style: STextStyles.button(context), + ), + onPressed: () { + Navigator.of(context).pop(true); + }, ), - onPressed: () { - Navigator.of(context).pop(true); - }, - ), - ); - }, - ); + ); + }, + ); + } if (shouldSendAll == null || shouldSendAll == false) { // cancel preview @@ -378,22 +395,24 @@ class _SendViewState extends ConsumerState { try { bool wasCancelled = false; - unawaited( - showDialog( - context: context, - useSafeArea: false, - barrierDismissible: false, - builder: (context) { - return BuildingTransactionDialog( - onCancel: () { - wasCancelled = true; + if (mounted) { + unawaited( + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: false, + builder: (context) { + return BuildingTransactionDialog( + onCancel: () { + wasCancelled = true; - Navigator.of(context).pop(); - }, - ); - }, - ), - ); + Navigator.of(context).pop(); + }, + ); + }, + ), + ); + } Map txData; @@ -1569,18 +1588,33 @@ class _SendViewState extends ConsumerState { ? "Select coins" : "Selected coins (${selectedUTXOs.length})", onTap: () async { + final spendable = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .balance + .spendable; + + int? amount; + if (_amountToSend != null) { + amount = Format.decimalAmountToSatoshis( + _amountToSend!, + coin, + ); + + if (spendable == amount) { + // this is now a send all + } else { + amount += _currentFee; + } + } + final result = await Navigator.of(context).pushNamed( CoinControlView.routeName, arguments: Tuple4( walletId, CoinControlViewType.use, - _amountToSend != null - ? Format.decimalAmountToSatoshis( - _amountToSend!, - coin, - ) - : null, + amount, selectedUTXOs, ), ); @@ -1711,6 +1745,10 @@ class _SendViewState extends ConsumerState { .text) ?? Decimal.zero, updateChosen: (String fee) { + _setCurrentFee( + fee, + true, + ); setState(() { _calculateFeesFuture = Future(() => fee); @@ -1736,6 +1774,10 @@ class _SendViewState extends ConsumerState { ConnectionState .done && snapshot.hasData) { + _setCurrentFee( + snapshot.data! as String, + false, + ); return Text( "~${snapshot.data! as String} ${coin.ticker}", style: STextStyles @@ -1788,6 +1830,11 @@ class _SendViewState extends ConsumerState { ConnectionState .done && snapshot.hasData) { + _setCurrentFee( + snapshot.data! + as String, + false, + ); return Text( "~${snapshot.data! as String} ${coin.ticker}", style: STextStyles