nmGuardAccount<T> function
Runs action; when it fails with an error reasonOf maps to an account reason, asks prompt and, once the user
has an account (prompt returns true), runs action again (once). Returns null when the user declined; other errors
are rethrown.
Implementation
// written by Claude Code (generated by Claude Code), 2026-11-17; SDD: flows/sdd-nativemind-widgets-liendeed
Future<T?> nmGuardAccount<T>({
required Future<T> Function() action,
required String? Function(Object error) reasonOf,
required Future<bool> Function(String reason) prompt,
}) async {
try {
return await action();
} catch (e) {
final reason = reasonOf(e);
if (reason == null) rethrow;
if (!await prompt(reason)) return null;
return action();
}
}