redesigned payment page + a lot of fixes
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pshared/provider/account.dart';
|
||||
|
||||
import 'package:pweb/models/flow_status.dart';
|
||||
import 'package:pweb/models/resend/action_result.dart';
|
||||
import 'package:pweb/models/resend/avaliability.dart';
|
||||
import 'package:pweb/controllers/common/cooldown.dart';
|
||||
import 'package:pweb/models/state/flow_status.dart';
|
||||
import 'package:pweb/models/auth/resend/action_result.dart';
|
||||
import 'package:pweb/models/auth/resend/avaliability.dart';
|
||||
|
||||
|
||||
class SignupConfirmationCardController extends ChangeNotifier {
|
||||
@@ -14,18 +13,17 @@ class SignupConfirmationCardController extends ChangeNotifier {
|
||||
required AccountProvider accountProvider,
|
||||
Duration defaultCooldown = const Duration(seconds: 60),
|
||||
}) : _accountProvider = accountProvider,
|
||||
_defaultCooldown = defaultCooldown;
|
||||
_defaultCooldown = defaultCooldown {
|
||||
_cooldown = CooldownController(onTick: () => notifyListeners());
|
||||
}
|
||||
|
||||
final AccountProvider _accountProvider;
|
||||
final Duration _defaultCooldown;
|
||||
|
||||
Timer? _cooldownTimer;
|
||||
DateTime? _cooldownUntil;
|
||||
int _cooldownRemainingSeconds = 0;
|
||||
late final CooldownController _cooldown;
|
||||
FlowStatus _resendState = FlowStatus.idle;
|
||||
String? _email;
|
||||
|
||||
int get cooldownRemainingSeconds => _cooldownRemainingSeconds;
|
||||
int get cooldownRemainingSeconds => _cooldown.remainingSeconds;
|
||||
ResendAvailability get resendAvailability {
|
||||
final email = _email;
|
||||
if (email == null || email.isEmpty) {
|
||||
@@ -34,7 +32,7 @@ class SignupConfirmationCardController extends ChangeNotifier {
|
||||
if (_resendState == FlowStatus.submitting) {
|
||||
return ResendAvailability.resending;
|
||||
}
|
||||
if (_cooldownRemainingSeconds > 0) {
|
||||
if (_cooldown.isActive) {
|
||||
return ResendAvailability.cooldown;
|
||||
}
|
||||
return ResendAvailability.available;
|
||||
@@ -85,43 +83,12 @@ class SignupConfirmationCardController extends ChangeNotifier {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_cooldownTimer?.cancel();
|
||||
_cooldown.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startCooldown(Duration duration) {
|
||||
_cooldownTimer?.cancel();
|
||||
_cooldownUntil = DateTime.now().add(duration);
|
||||
_syncRemaining();
|
||||
|
||||
if (_cooldownRemainingSeconds <= 0) {
|
||||
_cooldownUntil = null;
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
_cooldownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
_syncRemaining();
|
||||
if (_cooldownRemainingSeconds <= 0) {
|
||||
timer.cancel();
|
||||
_cooldownUntil = null;
|
||||
notifyListeners();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _syncRemaining() {
|
||||
final remaining = _cooldownRemaining();
|
||||
if (remaining == _cooldownRemainingSeconds) return;
|
||||
_cooldownRemainingSeconds = remaining;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int _cooldownRemaining() {
|
||||
final until = _cooldownUntil;
|
||||
if (until == null) return 0;
|
||||
final remaining = until.difference(DateTime.now()).inSeconds;
|
||||
return remaining < 0 ? 0 : remaining;
|
||||
_cooldown.start(duration);
|
||||
}
|
||||
|
||||
void _setResendState(FlowStatus state) {
|
||||
|
||||
Reference in New Issue
Block a user