// // KeyView.swift // OTP // // Created by Shadowfacts on 8/21/21. // import SwiftUI import OTPKit struct KeyView: View { let key: TOTPKey let currentCode: TOTPCode @State private var copying = false private var formattedCode: String { let code = currentCode.code let mid = code.index(code.startIndex, offsetBy: code.count / 2) return "\(code[code.startIndex.. Double { let seconds = round(date.timeIntervalSince(currentCode.validFrom)) let progress = 1 - seconds / Double(key.period) return progress } private func copy() { UIPasteboard.general.string = currentCode.code withAnimation(.easeInOut(duration: 0.5)) { copying = true } withAnimation(.easeInOut(duration: 0.5).delay(0.65)) { copying = false } } } struct KeyView_Previews: PreviewProvider { static var key: TOTPKey { TOTPKey(urlComponents: URLComponents(string: "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example")!)! } static var code: TOTPCode { OTPGenerator.generate(key: key) } static var previews: some View { KeyView(key: key, currentCode: code) } }