From 9bbff141acc7f87d096800bd8b3fb4a2fa62374b Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Mon, 8 May 2023 21:32:01 +0200 Subject: [PATCH] PM-1748 Fix watchOS issue where the TOTP code wasn't being regenerated after always on display. Also, blurred totp code and timer value when entering in Always On Display --- .../Models/Mocks/CipherMock.swift | 2 +- .../ViewModels/CipherDetailsViewModel.swift | 24 +++++++++++-------- .../Views/CipherDetailsView.swift | 8 +++++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/watchOS/bitwarden/bitwarden WatchKit Extension/Models/Mocks/CipherMock.swift b/src/watchOS/bitwarden/bitwarden WatchKit Extension/Models/Mocks/CipherMock.swift index 543e6a99e..7d22dc39a 100644 --- a/src/watchOS/bitwarden/bitwarden WatchKit Extension/Models/Mocks/CipherMock.swift +++ b/src/watchOS/bitwarden/bitwarden WatchKit Extension/Models/Mocks/CipherMock.swift @@ -2,7 +2,7 @@ import Foundation struct CipherMock { static let ciphers:[Cipher] = [ - Cipher(id: "0", name: "1933", userId: "123123", login: Login(username: "thisisatest@testing.com", totp: "otpauth://account?period=10&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)), + Cipher(id: "0", name: "MySite", userId: "123123", login: Login(username: "test@testing.com", totp: "otpauth://account?period=10&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)), Cipher(id: "1", name: "GitHub", userId: "123123", login: Login(username: "thisisatest@testing.com", totp: "LLLLLLLLLLLLLLLL", uris: cipherLoginUris)), Cipher(id: "2", name: "No user", userId: "123123", login: Login(username: nil, totp: "otpauth://account?period=10&digits=8&algorithm=sha256&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)), Cipher(id: "3", name: "Site 2", userId: "123123", login: Login(username: "longtestemail000000@fastmailasdfasdf.com", totp: "otpauth://account?period=10&digits=7&algorithm=sha512&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)), diff --git a/src/watchOS/bitwarden/bitwarden WatchKit Extension/ViewModels/CipherDetailsViewModel.swift b/src/watchOS/bitwarden/bitwarden WatchKit Extension/ViewModels/CipherDetailsViewModel.swift index bfed0a30b..41663d9dd 100644 --- a/src/watchOS/bitwarden/bitwarden WatchKit Extension/ViewModels/CipherDetailsViewModel.swift +++ b/src/watchOS/bitwarden/bitwarden WatchKit Extension/ViewModels/CipherDetailsViewModel.swift @@ -34,30 +34,34 @@ class CipherDetailsViewModel: ObservableObject{ self.counter = self.period - mod self.progress = Double(self.counter) / Double(self.period) } + if mod == 0 || self.totpFormatted == "" { do { - var totpF = try TotpService.shared.GetCodeAsync(key: self.key) ?? "" - if totpF.count > 4 { - let halfIndex = totpF.index(totpF.startIndex, offsetBy: totpF.count / 2) - totpF = "\(totpF[totpF.startIndex.. 4 { + let halfIndex = totpF.index(totpF.startIndex, offsetBy: totpF.count / 2) + totpF = "\(totpF[totpF.startIndex..