nmGuardAccount<T> function

Future<T?> nmGuardAccount<T>({
  1. required Future<T> action(),
  2. required String? reasonOf(
    1. Object error
    ),
  3. required Future<bool> prompt(
    1. String reason
    ),
})

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();
  }
}