Advertisement
McFamous

Untitled

Feb 25th, 2021
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.27 KB | None | 0 0
  1. void confirmCode(String confirmationCode) {
  2.     if (state is! EnteringSmsCodeRegistration) return;
  3.     EnteringSmsCodeRegistration currentState = state;
  4.     RegistrationSession currentSession = currentState.registrationSession;
  5.     emit(ProcessingEnteredSmsCode(
  6.       phone: currentState.phone,
  7.       region: currentState.region,
  8.       password: currentState.password,
  9.       registrationSession: currentSession,
  10.       secondToRequest: currentState.secondToRequest,
  11.     ));
  12.     _confirmCode(currentSession.sessionId, confirmationCode).then(
  13.       (confirmCodeResult) {
  14.         confirmCodeResult.process(
  15.           (value) {
  16.             _timerCode.cancel();
  17.             emit(EnteringUserInformation(
  18.               phone: currentState.phone,
  19.               region: currentState.region,
  20.               password: currentState.password,
  21.               registrationSession: currentSession,
  22.             ));
  23.           },
  24.           (exception) {
  25.             if (exception is InvalidSmsCodeException) {
  26.               var previousState;
  27.               if (state is! ProcessingEnteredSmsCode && state is! EnteringSmsCodeRegistration) return;
  28.               previousState = state;
  29.               emit(EnteringSmsCodeRegistration(
  30.                 phone: previousState.phone,
  31.                 region: previousState.region,
  32.                 password: previousState.password,
  33.                 registrationSession:
  34.                     currentSession.copy(confirmationAttemptsLeft: currentSession.confirmationAttemptsLeft - 1),
  35.                 secondToRequest: previousState.secondToRequest,
  36.               ));
  37.               if (state is! EnteringSmsCodeRegistration) return;
  38.               currentState = state;
  39.               currentSession = currentState.registrationSession;
  40.               if (currentSession.confirmationAttemptsLeft < 1) {
  41.                 _timerCode.cancel();
  42.                 _timerRegistration.cancel();
  43.                 emit(
  44.                   EnteringRegistrationInfo(
  45.                     phone: currentState.phone,
  46.                     region: currentState.region,
  47.                     password: currentState.password,
  48.                   ),
  49.                 );
  50.               }
  51.             } else {
  52.               // TODO
  53.             }
  54.           },
  55.         );
  56.       },
  57.     );
  58.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement