π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[auth][perf] Avoid redundant totp computation
Neeraj Gupta7354f69dc3a7
diff --git a/auth/lib/ui/code_widget.dart b/auth/lib/ui/code_widget.dartindex cb073e5dea..4c3e748e3a 100644--- a/auth/lib/ui/code_widget.dart+++ b/auth/lib/ui/code_widget.dart@@ -49,6 +49,7 @@ class _CodeWidgetState extends State<CodeWidget> {late bool _shouldShowLargeIcon;late bool _hideCode;bool isMaskingEnabled = false;+ int _codeTimeStep = -1;@overridevoid initState() {@@ -57,11 +58,22 @@ class _CodeWidgetState extends State<CodeWidget> {_hideCode = isMaskingEnabled;_everySecondTimer =Timer.periodic(const Duration(milliseconds: 500), (Timer t) {- String newCode = _getCurrentOTP();- if (newCode != _currentCode.value) {- _currentCode.value = newCode;- if (widget.code.type.isTOTPCompatible) {- _nextCode.value = _getNextTotp();+ int newStep = 0;+ if (widget.code.type != Type.hotp) {+ newStep = (((DateTime.now().millisecondsSinceEpoch ~/ 1000).round()) ~/+ widget.code.period)+ .floor();+ } else {+ newStep = widget.code.counter;+ }+ if (_codeTimeStep != newStep) {+ _codeTimeStep = newStep;+ String newCode = _getCurrentOTP();+ if (newCode != _currentCode.value) {+ _currentCode.value = newCode;+ if (widget.code.type.isTOTPCompatible) {+ _nextCode.value = _getNextTotp();+ }}}});