classifyRecipient function

RecipientStatus classifyRecipient(
  1. WalletSession session,
  2. String raw
)

Classify the recipient field's current text against the wallet's own network. PURE over the (sync, local) WalletSession.validateRecipient seam — reads only memoCapable or the typed WalletApiError.kind (NEVER an address payload — §5.4), so it is unit-tested at its boundary behind a fake. A blank field is RecipientEmpty (no bridge call); any non-FRB error degrades to RecipientInvalid (honest, never a raw code — invariant 6).

Implementation

RecipientStatus classifyRecipient(WalletSession session, String raw) {
  final address = raw.trim();
  if (address.isEmpty) return const RecipientEmpty();
  try {
    final v = session.validateRecipient(address);
    // memoCapable ⟺ a shielded receiver is present ⟺ private. A transparent /
    // transparent-only address is !memoCapable ⇒ classified PUBLIC here, never
    // mislabelled off a precise kind a normal user wouldn't understand.
    return v.memoCapable
        ? const RecipientShielded()
        : const RecipientTransparent();
  } on WalletApiError catch (e) {
    return e.kind is WalletErrorKind_NetworkMismatch
        ? const RecipientWrongNetwork()
        : const RecipientInvalid();
  } catch (_) {
    return const RecipientInvalid();
  }
}