This commit is contained in:
Arseni
2025-12-16 18:21:49 +03:00
parent 6ee146b95a
commit a2c05745ad
12 changed files with 180 additions and 88 deletions

View File

@@ -17,6 +17,7 @@ class TwoFactorProvider extends ChangeNotifier {
bool _hasError = false;
bool _verificationSuccess = false;
String? _errorMessage;
String? _currentPendingToken;
bool get isSubmitting => _isSubmitting;
bool get hasError => _hasError;
@@ -26,6 +27,12 @@ class TwoFactorProvider extends ChangeNotifier {
void update(AccountProvider accountProvider) {
_accountProvider = accountProvider;
final pending = accountProvider.pendingLogin;
final token = pending?.pendingToken.token;
if (token != _currentPendingToken || accountProvider.account == null) {
_resetState();
_currentPendingToken = token;
}
}
Future<void> submitCode(String code) async {
@@ -46,6 +53,7 @@ class TwoFactorProvider extends ChangeNotifier {
);
_accountProvider.completePendingLogin(account);
_verificationSuccess = true;
_currentPendingToken = null;
} catch (e) {
_hasError = true;
_errorMessage = e.toString();
@@ -71,4 +79,17 @@ class TwoFactorProvider extends ChangeNotifier {
notifyListeners();
}
}
}
void reset() {
_resetState();
_currentPendingToken = null;
}
void _resetState() {
_isSubmitting = false;
_hasError = false;
_errorMessage = null;
_verificationSuccess = false;
notifyListeners();
}
}