fix: ignore a failed build after cancel
What changed, and why it matters
This commit fixes a UI bug in Stack Wallet where cancelling a transaction build could cause the app to try to close a dialog that was already gone, leading to a crash or confusing error screen. The fix moves a 'wasCancelled' flag outside the try-block so it remains visible in the catch-block, and then skips popping the dialog if the user cancelled. It is a stability/UX fix, not a cryptographic or funds-theft issue.
Treat as a routine bug-fix release; no urgent security response required. Verify that no other send flows have the same scoping pattern and that cancellation still cleanly aborts the underlying wallet build operation.
Security signals we found
UI state desynchronization between dialog dismissal and exception handler
Unconditional Navigator.pop() in catch block could pop wrong route
Local variable scope bug fixed by hoisting cancellation flag
Evidence from the diff
Across ten send/build views, the local boolean wasCancelled was declared inside the try block. If an exception was thrown after the user cancelled, the catch block could not see that flag and would unconditionally call Navigator.of(context).pop(), potentially popping the wrong route or throwing because the building dialog was already dismissed. The patch hoists wasCancelled to just before the try and guards the pop() and error dialog with if (mounted && !wasCancelled). This prevents a failed build after user cancellation from triggering spurious navigation or error dialogs.
Changed components
lib/pages/exchange_view/send_from_view.dartlib/pages/namecoin_names/sub_widgets/transfer_option_widget.dartlib/pages/namecoin_names/sub_widgets/update_option_widget.dartlib/pages/salvium_stake/salvium_create_stake_view.dartlib/pages/send_view/send_view.dartlib/pages/send_view/sol_token_send_view.dartlib/pages/send_view/token_send_view.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_sol_token_send.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dartInspect captured patch +20 / −30
### lib/pages/exchange_view/send_from_view.dart
@@ -225,9 +225,8 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
Future<void> _send({bool? shouldSendPublicFiroFunds}) async {
final coin = ref.read(pWalletCoin(walletId));
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
final wallet = ref.read(pWallets).getWallet(walletId);
unawaited(
@@ -362,7 +361,7 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
}
} catch (e, s) {
Logging.instance.e("$e\n$s", error: e, stackTrace: s);
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context, rootNavigator: Util.isDesktop).pop();
### lib/pages/namecoin_names/sub_widgets/transfer_option_widget.dart
@@ -71,11 +71,10 @@ class _TransferOptionWidgetState extends ConsumerState<TransferOptionWidget> {
FocusScope.of(context).unfocus();
await Future<void>.delayed(const Duration(milliseconds: 100));
+ bool wasCancelled = false;
try {
final wallet = ref.read(pWallets).getWallet(walletId) as NamecoinWallet;
- bool wasCancelled = false;
-
if (mounted) {
if (Util.isDesktop) {
unawaited(
@@ -194,7 +193,7 @@ class _TransferOptionWidgetState extends ConsumerState<TransferOptionWidget> {
stackTrace: s,
);
- if (mounted) {
+ if (mounted && !wasCancelled) {
String err = e.toString();
if (err.startsWith("Exception: ")) {
err = err.replaceFirst("Exception: ", "");
### lib/pages/namecoin_names/sub_widgets/update_option_widget.dart
@@ -73,6 +73,7 @@ class _BuyDomainWidgetState extends ConsumerState<UpdateOptionWidget> {
Future<void> _previewUpdate() async {
if (_previewLock) return;
_previewLock = true;
+ bool wasCancelled = false;
try {
final newValue = _getNewValue();
if (newValue == _currentValue) {
@@ -86,8 +87,6 @@ class _BuyDomainWidgetState extends ConsumerState<UpdateOptionWidget> {
final wallet =
ref.read(pWallets).getWallet(widget.walletId) as NamecoinWallet;
- bool wasCancelled = false;
-
if (mounted) {
if (Util.isDesktop) {
unawaited(
@@ -214,7 +213,7 @@ class _BuyDomainWidgetState extends ConsumerState<UpdateOptionWidget> {
err = "Contains invalid characters";
}
- if (mounted) {
+ if (mounted && !wasCancelled) {
await showDialog<void>(
context: context,
builder:
### lib/pages/salvium_stake/salvium_create_stake_view.dart
@@ -74,9 +74,8 @@ class _SalviumCreateStakeViewState
if (_lock) return;
_lock = true;
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
unawaited(
showDialog<dynamic>(
context: context,
@@ -170,7 +169,7 @@ class _SalviumCreateStakeViewState
} catch (e, s) {
Logging.instance.e("Salvium stake preview: ", error: e, stackTrace: s);
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context, rootNavigator: Util.isDesktop).pop();
### lib/pages/send_view/send_view.dart
@@ -935,9 +935,8 @@ class _SendViewState extends ConsumerState<SendView> {
}
}
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
if (mounted) {
unawaited(
showDialog<void>(
@@ -1167,7 +1166,7 @@ class _SendViewState extends ConsumerState<SendView> {
}
} catch (e, s) {
Logging.instance.e("$e\n$s", error: e, stackTrace: s);
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context, rootNavigator: true).pop();
### lib/pages/send_view/sol_token_send_view.dart
@@ -464,9 +464,8 @@ class _SolTokenSendViewState extends ConsumerState<SolTokenSendView> {
final wallet = ref.read(pWallets).getWallet(walletId);
final Amount amount = _amountToSend!;
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
if (mounted) {
unawaited(
showDialog<void>(
@@ -543,7 +542,7 @@ class _SolTokenSendViewState extends ConsumerState<SolTokenSendView> {
}
} catch (e, s) {
Logging.instance.e("$e\n$s", error: e, stackTrace: s);
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context).pop();
### lib/pages/send_view/token_send_view.dart
@@ -463,9 +463,8 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
// }
// }
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
if (mounted) {
unawaited(
showDialog<void>(
@@ -538,7 +537,7 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
}
} catch (e, s) {
Logging.instance.e("$e\n$s", error: e, stackTrace: s);
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context).pop();
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart
@@ -549,9 +549,8 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
}
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
if (mounted) {
unawaited(
showDialog<dynamic>(
@@ -793,7 +792,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
} catch (e, s) {
Logging.instance.e("Desktop send: ", error: e, stackTrace: s);
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context, rootNavigator: true).pop();
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_sol_token_send.dart
@@ -225,9 +225,8 @@ class _DesktopSolTokenSendState extends ConsumerState<DesktopSolTokenSend> {
}
}
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
if (mounted) {
unawaited(
showDialog<dynamic>(
@@ -310,7 +309,7 @@ class _DesktopSolTokenSendState extends ConsumerState<DesktopSolTokenSend> {
);
}
} catch (e) {
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context, rootNavigator: true).pop();
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart
@@ -207,9 +207,8 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
}
}
+ bool wasCancelled = false;
try {
- bool wasCancelled = false;
-
if (mounted) {
unawaited(
showDialog<dynamic>(
@@ -289,7 +288,7 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
);
}
} catch (e) {
- if (mounted) {
+ if (mounted && !wasCancelled) {
// pop building dialog
Navigator.of(context, rootNavigator: true).pop();
Why this scored 23/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.