useGraphResend function

Future<void> useGraphResend({
  1. required BuildContext context,
  2. required dynamic appWrapperContext,
  3. required String phoneNumber,
  4. required int step,
  5. required Function toggleResend,
  6. required Function showErr,
  7. required Function resetTimer,
  8. required Function generateOtpFunc,
  9. required dynamic client,
  10. required OnOTPReceivedNavigateCallback onOTPCallback,
})

Resends an OTP code using a GraphQL API and handles relevant callbacks.

This function initiates the process of resending an OTP code using a GraphQL API. It toggles the resend button's state, clears any error indicators, and attempts to generate a new OTP code. If the OTP generation is successful, the timer is reset, and the onOTPCallback callback is used to notify the app with the new OTP code. In case of an error during the process, appropriate error indicators are shown.

Implementation

Future<void> useGraphResend({
  required BuildContext context,
  required dynamic appWrapperContext,
  required String phoneNumber,
  required int step,
  required Function toggleResend,
  required Function showErr,
  required Function resetTimer,
  required Function generateOtpFunc,
  required dynamic client,
  required OnOTPReceivedNavigateCallback onOTPCallback,
}) async {
  toggleResend();
  showErr(val: false);
  try {
    // do the resend here
    final dynamic otp = await generateOtpFunc(
        client: client, phoneNumber: phoneNumber, step: step);

    if (otp == 'Error') {
      throw 'Could not regenerate otp';
    } else {
      // reset the timer
      resetTimer();

      // return the new otp
      onOTPCallback(otp as String);
      toggleResend();
    }
  } catch (e) {
    toggleResend();
    showErr(val: true);
  }
}