From 7362d80b4b3718a1634f151bfb33a153d676c04f Mon Sep 17 00:00:00 2001 From: Joel-David Date: Wed, 31 Jul 2024 23:49:36 +0800 Subject: [PATCH] Use single timer --- Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift | 3 ++- Chronos/App/Tabs/Tokens/Row/TokenRowView.swift | 5 ++++- Chronos/App/Tabs/Tokens/TokensTab.swift | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift b/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift index 1ce05df..358885a 100644 --- a/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift +++ b/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift @@ -1,3 +1,4 @@ +import Combine import Factory import SwiftUI @@ -8,7 +9,7 @@ struct TOTPRowView: View { @State private var secsLeft = 0 @State private var progress: Double = 1.0 - let timer = Timer.publish(every: 0.5, on: .main, in: .common).autoconnect() + let timer: Publishers.Autoconnect let otpService = Container.shared.otpService() var body: some View { diff --git a/Chronos/App/Tabs/Tokens/Row/TokenRowView.swift b/Chronos/App/Tabs/Tokens/Row/TokenRowView.swift index cb43e38..bc3df3c 100644 --- a/Chronos/App/Tabs/Tokens/Row/TokenRowView.swift +++ b/Chronos/App/Tabs/Tokens/Row/TokenRowView.swift @@ -1,4 +1,5 @@ import AlertKit +import Combine import EFQRCode import Factory import SwiftUI @@ -18,6 +19,8 @@ struct TokenRowView: View { let tokenPair: TokenPair + let timer: Publishers.Autoconnect + var token: Token { return tokenPair.token } @@ -55,7 +58,7 @@ struct TokenRowView: View { HStack { switch token.type { case TokenTypeEnum.TOTP: - TOTPRowView(token: token) + TOTPRowView(token: token, timer: timer) case TokenTypeEnum.HOTP: HOTPRowView(token: token, encryptedToken: encryptedToken) } diff --git a/Chronos/App/Tabs/Tokens/TokensTab.swift b/Chronos/App/Tabs/Tokens/TokensTab.swift index 836eee9..40ac0fd 100644 --- a/Chronos/App/Tabs/Tokens/TokensTab.swift +++ b/Chronos/App/Tabs/Tokens/TokensTab.swift @@ -49,10 +49,12 @@ struct TokensTab: View { let cryptoService = Container.shared.cryptoService() let stateService = Container.shared.stateService() + let timer = Timer.publish(every: 0.5, on: .main, in: .common).autoconnect() + var body: some View { NavigationStack { List(filteredAndSortedTokenPairs) { tokenPair in - TokenRowView(tokenPair: tokenPair) + TokenRowView(tokenPair: tokenPair, timer: timer) } .onAppear { Task {