Skip to content

Displaying Secret Key in Edit Token section #369

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions Authenticator/Source/TokenEditForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
//

import OneTimePassword
import Base32

struct TokenEditForm: Component {
private let persistentToken: PersistentToken

private var issuer: String
private var name: String
private var secret: String

private var isValid: Bool {
return !(issuer.isEmpty && name.isEmpty)
Expand All @@ -39,6 +41,7 @@ struct TokenEditForm: Component {

init(persistentToken: PersistentToken) {
self.persistentToken = persistentToken
secret = MF_Base32Codec.base32String(from: persistentToken.token.generator.secret)
issuer = persistentToken.token.issuer
name = persistentToken.token.name
}
Expand All @@ -52,6 +55,7 @@ extension TokenEditForm: TableViewModelRepresentable {
case name(String)
case cancel
case submit
case secret(String)
}

typealias HeaderModel = TokenFormHeaderModel<Action>
Expand All @@ -70,6 +74,7 @@ extension TokenEditForm {
rightBarButton: BarButtonViewModel(style: .done, action: .submit, enabled: isValid),
sections: [
[
tokenRowModel,
issuerRowModel,
nameRowModel,
],
Expand All @@ -78,6 +83,16 @@ extension TokenEditForm {
)
}

private var tokenRowModel: RowModel {
return .textFieldRow(
identity: "token.secret",
viewModel: TextFieldRowViewModel(
secret: secret,
changeAction: Action.secret
)
)
}

private var issuerRowModel: RowModel {
return .textFieldRow(
identity: "token.issuer",
Expand Down Expand Up @@ -112,6 +127,8 @@ extension TokenEditForm {

mutating func update(with action: Action) -> Effect? {
switch action {
case let .secret(secret):
self.secret = secret
case let .issuer(issuer):
self.issuer = issuer
case let .name(name):
Expand Down