Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor: Simplify uppercase algorithm logic using copyWith

Prateek Sunal323aabaaca6f
diff --git a/mobile/apps/auth/lib/models/code.dart b/mobile/apps/auth/lib/models/code.dart
index e982e04493..c4edfee1fb 100644
--- a/mobile/apps/auth/lib/models/code.dart
+++ b/mobile/apps/auth/lib/models/code.dart
@@ -98,7 +98,7 @@ class Code {
updatedAlgo,
updatedType,
updatedCounter,
- "otpauth://${updatedType.name}/$updateIssuer:$updateAccount?algorithm=${updatedAlgo.name}"
+ "otpauth://${updatedType.name}/$updateIssuer:$updateAccount?algorithm=${updatedAlgo.name.toUpperCase()}"
"&digits=$updatedDigits&issuer=$encodedIssuer"
"&period=$updatePeriod&secret=$updatedSecret${updatedType == Type.hotp ? "&counter=$updatedCounter" : ""}",
generatedID: generatedID,
@@ -115,8 +115,6 @@ class Code {
int digits, {
Algorithm algorithm = Algorithm.sha1,
int period = defaultPeriod,
- int counter = 0,
- int? generatedID,
}) {
final String encodedIssuer = Uri.encodeQueryComponent(issuer);
return Code(
@@ -127,9 +125,8 @@ class Code {
secret,
algorithm,
type,
- counter,
- "otpauth://${type.name}/$issuer:$account?algorithm=${algorithm.name.toUpperCase()}&digits=$digits&issuer=$encodedIssuer&period=$period&secret=$secret${type == Type.hotp ? "&counter=$counter" : ""}",
- generatedID: generatedID,
+ 0,
+ "otpauth://${type.name}/$issuer:$account?algorithm=${algorithm.name.toUpperCase()}&digits=$digits&issuer=$encodedIssuer&period=$period&secret=$secret",
display: display ?? CodeDisplay(),
);
}
diff --git a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
index 8d4e5f0d15..60cc814a9a 100644
--- a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
+++ b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
@@ -458,24 +458,27 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
}
}
- // When editing, preserve original type/algorithm/digits/period/counter
- // When creating new, apply isStreamCode logic and use UI values
- final Code newCode = Code.fromAccountAndSecret(
- widget.code != null
- ? widget.code!.type
- : (isStreamCode ? Type.steam : _type),
- account,
- issuer,
- secret,
- display,
- widget.code != null
- ? widget.code!.digits
- : (isStreamCode ? Code.steamDigits : digits!),
- algorithm: widget.code?.algorithm ?? _algorithm,
- period: widget.code?.period ?? period!,
- counter: widget.code?.counter ?? 0,
- generatedID: widget.code?.generatedID,
- );
+ final Code newCode = widget.code == null
+ ? Code.fromAccountAndSecret(
+ isStreamCode ? Type.steam : _type,
+ account,
+ issuer,
+ secret,
+ display,
+ isStreamCode ? Code.steamDigits : digits!,
+ algorithm: _algorithm,
+ period: period!,
+ )
+ : widget.code!.copyWith(
+ account: account,
+ issuer: issuer,
+ secret: secret,
+ display: display,
+ algorithm: _algorithm,
+ digits: digits!,
+ type: _type,
+ period: period,
+ );
// Verify the validity of the code
getOTP(newCode);