sendOtp method

Future<void> sendOtp(
  1. String email
)

Send an OTP challenge for email. On success, transitions to CrossmintEmailSignInStep.otpInput and starts the resend cooldown. On failure, stores the error message on error and stays on the email-input step.

A blank email is treated as a validation error (no network call).

Implementation

Future<void> sendOtp(String email) async {
  final String trimmed = email.trim();
  if (trimmed.isEmpty) {
    _error = 'Please enter your email address.';
    _safeNotify();
    return;
  }

  _isLoading = true;
  _error = null;
  _safeNotify();
  try {
    final CrossmintEmailOtpChallenge challenge = await _auth.sendEmailOtp(
      trimmed,
    );
    if (_disposed) {
      return;
    }
    _submittedEmail = trimmed;
    _emailId = challenge.state;
    _step = CrossmintEmailSignInStep.otpInput;
    _startCooldown();
  } on Exception catch (e) {
    if (_disposed) {
      return;
    }
    _error = e.toString();
  } finally {
    if (!_disposed) {
      _isLoading = false;
      _safeNotify();
    }
  }
}