-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #604 from Adamant-im/dev/trello.com/c/R8cyJtgT
[trello.com/c/R8cyJtgT] Added formats to generated keys
- Loading branch information
Showing
19 changed files
with
452 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Adamant/Modules/Settings/PKGenerator/PKGeneratorFactory.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// PKGeneratorFactory.swift | ||
// Adamant | ||
// | ||
// Created by Andrew G on 28.11.2024. | ||
// Copyright © 2024 Adamant. All rights reserved. | ||
// | ||
|
||
import Swinject | ||
import SwiftUI | ||
|
||
struct PKGeneratorFactory { | ||
private let parent: Assembler | ||
private let assemblies = [PKGeneratorAssembly()] | ||
|
||
init(parent: Assembler) { | ||
self.parent = parent | ||
} | ||
|
||
func makeViewController() -> UIViewController { | ||
let assembler = Assembler(assemblies, parent: parent) | ||
let viewModel = { assembler.resolver.resolve(PKGeneratorViewModel.self)! } | ||
return UIHostingController(rootView: PKGeneratorView(viewModel: viewModel)) | ||
} | ||
} | ||
|
||
private struct PKGeneratorAssembly: Assembly { | ||
func assemble(container: Container) { | ||
container.register(PKGeneratorViewModel.self) { | ||
.init( | ||
dialogService: $0.resolve(DialogService.self)!, | ||
walletServiceCompose: $0.resolve(WalletServiceCompose.self)! | ||
) | ||
}.inObjectScope(.transient) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Adamant/Modules/Settings/PKGenerator/PKGeneratorState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PKGeneratorState.swift | ||
// Adamant | ||
// | ||
// Created by Andrew G on 28.11.2024. | ||
// Copyright © 2024 Adamant. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
struct PKGeneratorState { | ||
var passphrase: String | ||
var keys: [KeyInfo] | ||
var buttonDescription: AttributedString | ||
var isLoading: Bool | ||
|
||
static let `default` = Self( | ||
passphrase: .empty, | ||
keys: .init(), | ||
buttonDescription: .init(), | ||
isLoading: false | ||
) | ||
} | ||
|
||
extension PKGeneratorState { | ||
struct KeyInfo: Identifiable { | ||
var id: String { title } | ||
|
||
let title: String | ||
let description: String | ||
let icon: UIImage | ||
let key: String | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
Adamant/Modules/Settings/PKGenerator/PKGeneratorView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// | ||
// PKGeneratorView.swift | ||
// Adamant | ||
// | ||
// Created by Andrew G on 28.11.2024. | ||
// Copyright © 2024 Adamant. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import CommonKit | ||
|
||
struct PKGeneratorView: View { | ||
@StateObject private var viewModel: PKGeneratorViewModel | ||
|
||
var body: some View { | ||
List { | ||
if !viewModel.state.keys.isEmpty { | ||
keysSection | ||
} | ||
|
||
inputSection | ||
} | ||
.withoutListBackground() | ||
.background(Color(.adamant.secondBackgroundColor)) | ||
.navigationTitle(String.adamant.pkGenerator.title) | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
|
||
init(viewModel: @escaping () -> PKGeneratorViewModel) { | ||
_viewModel = .init(wrappedValue: viewModel()) | ||
} | ||
} | ||
|
||
private extension PKGeneratorView { | ||
var loadingBackground: some View { | ||
HStack { | ||
Spacer() | ||
|
||
if viewModel.state.isLoading { | ||
ProgressView() | ||
} | ||
} | ||
} | ||
|
||
var keysSection: some View { | ||
Section { | ||
ForEach(viewModel.state.keys, content: keyView) | ||
.listRowBackground(Color(uiColor: .adamant.cellColor)) | ||
} | ||
} | ||
|
||
var inputSection: some View { | ||
Section { | ||
Group { | ||
Text(viewModel.state.buttonDescription) | ||
.multilineTextAlignment(.center) | ||
.padding(.vertical, 5) | ||
|
||
AdamantSecureField( | ||
placeholder: .adamant.qrGenerator.passphrasePlaceholder, | ||
text: $viewModel.state.passphrase | ||
) | ||
|
||
Button(action: { viewModel.generateKeys() }) { | ||
Text(String.adamant.pkGenerator.generateButton) | ||
.foregroundStyle(Color(uiColor: .adamant.primary)) | ||
.padding(.horizontal, 30) | ||
.background(loadingBackground) | ||
.expanded(axes: .horizontal) | ||
} | ||
}.listRowBackground(Color(uiColor: .adamant.cellColor)) | ||
} | ||
} | ||
|
||
func keyView(_ keyInfo: PKGeneratorState.KeyInfo) -> some View { | ||
NavigationButton(action: { viewModel.onTap(key: keyInfo.key) }) { | ||
HStack { | ||
Image(uiImage: keyInfo.icon) | ||
.renderingMode(.template) | ||
.resizable() | ||
.frame(squareSize: 25) | ||
.foregroundStyle(Color(uiColor: .adamant.tableRowIcons)) | ||
|
||
VStack(alignment: .leading) { | ||
Text(keyInfo.title) | ||
Text(keyInfo.description) | ||
.foregroundStyle(Color(uiColor: .adamant.secondary)) | ||
.font(.system(size: 12, weight: .ultraLight)) | ||
} | ||
|
||
Spacer(minLength: .zero) | ||
|
||
Text(keyInfo.key).lineLimit(1) | ||
.foregroundStyle(Color(uiColor: .adamant.secondary)) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.