Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use single timer for all totp views #56

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Combine
import Factory
import SwiftUI

Expand All @@ -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<Timer.TimerPublisher>
let otpService = Container.shared.otpService()

var body: some View {
Expand Down
5 changes: 4 additions & 1 deletion Chronos/App/Tabs/Tokens/Row/TokenRowView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AlertKit
import Combine
import EFQRCode
import Factory
import SwiftUI
Expand All @@ -18,6 +19,8 @@ struct TokenRowView: View {

let tokenPair: TokenPair

let timer: Publishers.Autoconnect<Timer.TimerPublisher>

var token: Token {
return tokenPair.token
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion Chronos/App/Tabs/Tokens/TokensTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading