-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented vault creation & restore (#9)
* implemented vault creation & restore screens * fix writing * Updated * cleanup vaultservice * revert doesICloudBackupExist
- Loading branch information
1 parent
8e275ae
commit a4005c1
Showing
13 changed files
with
210 additions
and
51 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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import AlertKit | ||
import Factory | ||
import SwiftData | ||
import SwiftUI | ||
|
||
struct PasswordLoginView: View { | ||
|
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
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,67 @@ | ||
import AlertKit | ||
import Factory | ||
import SwiftData | ||
import SwiftUI | ||
|
||
struct VaultSelectionView: View { | ||
@Query(sort: \Vault.createdAt) var vaults: [Vault] | ||
|
||
@State private var moveToNextScreen: Bool = false | ||
|
||
let cryptoService = Container.shared.cryptoService() | ||
let vaultService = Container.shared.vaultService() | ||
let stateService = Container.shared.stateService() | ||
|
||
let formatter = RelativeDateTimeFormatter() | ||
|
||
var body: some View { | ||
VStack { | ||
ScrollViewReader { _ in | ||
List(vaults) { vault in | ||
HStack { | ||
VStack(alignment: .leading, spacing: 4) { | ||
Text(vault.name) | ||
.fontWeight(.semibold) | ||
|
||
Text("Created \(formatter.localizedString(for: Date(timeIntervalSince1970: vault.createdAt!.timeIntervalSince1970), relativeTo: Date.now))") | ||
.foregroundStyle(.gray) | ||
.font(.subheadline) | ||
} | ||
|
||
Spacer() | ||
|
||
VStack(alignment: .trailing) { | ||
Text("\(vault.encryptedTokens?.count ?? 0)") | ||
.font(.system(size: 20)) | ||
.padding(.horizontal, 8) | ||
.padding(.vertical, 4) | ||
.background(Color(.gray).opacity(0.6)) | ||
.cornerRadius(8) | ||
} | ||
} | ||
.contentShape(Rectangle()) | ||
.onTapGesture { | ||
guard let vaultId = vault.vaultId else { | ||
AlertKitAPI.present( | ||
title: "Unable to access vault", | ||
icon: .error, | ||
style: .iOS17AppleMusic, | ||
haptic: .error | ||
) | ||
return | ||
} | ||
|
||
stateService.setVaultId(vaultId: vaultId) | ||
moveToNextScreen = true | ||
} | ||
.padding(CGFloat(4)) | ||
} | ||
.listStyle(.plain) | ||
} | ||
} | ||
.navigationDestination(isPresented: $moveToNextScreen) { | ||
RestoreBackupView() | ||
} | ||
.navigationTitle("Vaults") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Factory | ||
import SwiftUI | ||
|
||
struct VaultSetupView: View { | ||
let vaultService = Container.shared.vaultService() | ||
|
||
@State private var vaultName: String = "My Vault" | ||
@State private var isCreatingVault: Bool = false | ||
@State private var nextBtnPressed: Bool = false | ||
|
||
var body: some View { | ||
VStack { | ||
Image(systemName: "lock.shield") | ||
.font(.system(size: 44)) | ||
.padding(.bottom, 16) | ||
|
||
Text("A vault contains all of your Two-Factor Authentication (2FA) tokens and is secured with your own password.") | ||
.fixedSize(horizontal: false, vertical: true) | ||
.multilineTextAlignment(.center) | ||
|
||
Text("Your vault name") | ||
.padding(.top, 32) | ||
|
||
Group { | ||
TextField("", text: $vaultName) | ||
.multilineTextAlignment(.center) | ||
.background(Color.clear) | ||
} | ||
.frame(height: 48) | ||
.background(Color(.systemGray6)) | ||
.cornerRadius(8) | ||
|
||
Spacer() | ||
|
||
Button { | ||
nextBtnPressed = true | ||
} label: { | ||
if !isCreatingVault { | ||
Text("Next") | ||
.foregroundStyle(Color(red: 0.04, green: 0, blue: 0.11)) | ||
.bold() | ||
.frame(minWidth: 0, maxWidth: .infinity) | ||
.frame(height: 32) | ||
} else { | ||
ProgressView() | ||
.tint(Color(red: 0.04, green: 0, blue: 0.11)) | ||
.frame(minWidth: 0, maxWidth: .infinity) | ||
.frame(height: 32) | ||
} | ||
} | ||
.padding(.top, 64) | ||
.buttonStyle(.borderedProminent) | ||
} | ||
.padding(.vertical, 32) | ||
.padding(.horizontal, 24) | ||
.background(Color(red: 0.04, green: 0, blue: 0.11).ignoresSafeArea()) | ||
.navigationTitle("Vault") | ||
.navigationBarTitleDisplayMode(.inline) | ||
.navigationDestination(isPresented: $nextBtnPressed) { | ||
PasswordSetupView(vaultName: vaultName) | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.