Skip to content

Commit

Permalink
feat: ios: banana split recovery update (#2366)
Browse files Browse the repository at this point in the history
* feat: ios: banana split recovery flow update

* feat: ios: remaining changes

* feat: ios: pass seed name during recovery flow
  • Loading branch information
krodak authored Mar 11, 2024
1 parent 4533d9e commit 941879a
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 14 deletions.
7 changes: 5 additions & 2 deletions ios/PolkadotVault/Components/Buttons/CircleButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

import SwiftUI

struct CloseModalButton: View {
struct CircleButton: View {
private let image: ImageResource
private let action: () -> Void

init(
image: ImageResource = .xmarkButton,
action: @escaping () -> Void
) {
self.image = image
self.action = action
}

Expand All @@ -24,7 +27,7 @@ struct CloseModalButton: View {
Circle()
.frame(width: Sizes.xmarkButtonDiameter, height: Sizes.xmarkButtonDiameter, alignment: .center)
.foregroundColor(.fill18)
Image(.xmarkButton)
Image(image)
.foregroundColor(.textAndIconsPrimary)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ final class KeychainBananaSplitQueryProvider: KeychainBananaSplitQueryProviding
case let .fetch(seedName):
dictionary[kSecMatchLimit] = kSecMatchLimitOne
dictionary[kSecAttrAccount] = backupName(seedName)
dictionary[kSecReturnAttributes] = false
dictionary[kSecReturnData] = true
case let .check(seedName):
dictionary[kSecMatchLimit] = kSecMatchLimitOne
Expand All @@ -76,7 +75,6 @@ final class KeychainBananaSplitQueryProvider: KeychainBananaSplitQueryProviding
case let .fetch(seedName):
dictionary[kSecMatchLimit] = kSecMatchLimitOne
dictionary[kSecAttrAccount] = passphraseName(seedName)
dictionary[kSecReturnAttributes] = false
dictionary[kSecReturnData] = true
case let .delete(seedName):
dictionary[kSecAttrAccount] = passphraseName(seedName)
Expand Down
2 changes: 1 addition & 1 deletion ios/PolkadotVault/Modals/Backup/BackupModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct BackupModal: View {
.font(PrimaryFont.bodyM.font)
}
Spacer()
CloseModalButton(action: animateDismissal)
CircleButton(action: animateDismissal)
}
.padding(.leading, Spacing.large)
.padding(.trailing, Spacing.medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct ExportPrivateKeyModal: View {
.foregroundColor(.textAndIconsPrimary)
.font(PrimaryFont.titleS.font)
Spacer()
CloseModalButton(action: animateDismissal)
CircleButton(action: animateDismissal)
}
.padding([.leading], Spacing.large)
.padding([.trailing], Spacing.medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct NetworkSelectionModal: View {
.foregroundColor(.textAndIconsPrimary)
.font(PrimaryFont.titleS.font)
Spacer()
CloseModalButton(action: viewModel.resetAction)
CircleButton(action: viewModel.resetAction)
}
.padding(.leading, Spacing.large)
.padding(.trailing, Spacing.medium)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "qr_code.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import SwiftUI

struct BananaSplitQRCodeRecovery {
let seedName: String
let onRecoveryComplete: (CreateKeysForNetworksView.OnCompletionAction) -> Void
}

struct RecoverKeySetSeedPhraseView: View {
private enum Constants {
static let capsuleContainerID = "capsuleContainerID"
Expand Down Expand Up @@ -72,6 +77,11 @@ struct RecoverKeySetSeedPhraseView: View {
.padding(.top, Spacing.extraSmall)
.padding(.bottom, Spacing.extraExtraSmall)
Spacer()
HStack(alignment: .center, spacing: 0) {
Spacer()
CircleButton(image: .qrCode, action: viewModel.didTapQRCode)
.padding(Spacing.extraSmall)
}
}
.frame(minHeight: 156)
.containerBackground(CornerRadius.small)
Expand Down Expand Up @@ -118,6 +128,23 @@ struct RecoverKeySetSeedPhraseView: View {
)
.clearModalBackground()
}
.fullScreenModal(
isPresented: $viewModel.isShowingQRScanner,
onDismiss: {
focus = false
viewModel.onCameraDismiss()
}
) {
CameraView(
viewModel: .init(
isPresented: $viewModel.isShowingQRScanner,
bananaSplitQRCodeRecovery: .init(
seedName: viewModel.seedName,
onRecoveryComplete: viewModel.onCameraComplete(_:)
)
)
)
}
}
}
}
Expand Down Expand Up @@ -226,9 +253,11 @@ extension RecoverKeySetSeedPhraseView {
private var shouldSkipUpdate = false
private let service: RecoverKeySetServicing
private let onCompletion: (CreateKeysForNetworksView.OnCompletionAction) -> Void
private var flowCompleted: (CreateKeysForNetworksView.OnCompletionAction)?
let seedName: String
@Binding var isPresented: Bool
@Published var isPresentingDetails: Bool = false
@Published var isShowingQRScanner: Bool = false
@Published var isValidSeedPhrase: Bool = false
@Published var seedPhraseGrid: [GridElement] = []
@Published var userInput: String = Constants.invisibleNonEmptyCharacter
Expand Down Expand Up @@ -274,6 +303,25 @@ extension RecoverKeySetSeedPhraseView {
seedPhraseDraft.append(guess)
}

func didTapQRCode() {
isShowingQRScanner = true
}

func onCameraComplete(_ onComplete: CreateKeysForNetworksView.OnCompletionAction) {
isShowingQRScanner = false
flowCompleted = onComplete
}

func onCameraDismiss() {
guard let flowCompleted else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
self.isPresented = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
self.onCompletion(flowCompleted)
}
}
}

func onUserInput(_ word: String) {
guard !shouldSkipUpdate else { return }
defer { shouldSkipUpdate = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct DerivationMethodsInfoView: View {
.foregroundColor(.textAndIconsPrimary)
.font(PrimaryFont.titleS.font)
Spacer()
CloseModalButton(action: viewModel.animateDismissal)
CircleButton(action: viewModel.animateDismissal)
}
.padding(.leading, Spacing.large)
.padding(.trailing, Spacing.medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct BananaSplitPassphraseModal: View {
.foregroundColor(.textAndIconsPrimary)
.font(PrimaryFont.titleS.font)
Spacer()
CloseModalButton(action: viewModel.dismissActionSheet)
CircleButton(action: viewModel.dismissActionSheet)
}
Text(viewModel.passphrase)
.multilineTextAlignment(.leading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct ExportKeysSelectionModal: View {
.foregroundColor(.textAndIconsPrimary)
.font(PrimaryFont.titleS.font)
Spacer()
CloseModalButton(action: viewModel.cancelAction)
CircleButton(action: viewModel.cancelAction)
}
.padding(.leading, Spacing.large)
.padding(.trailing, Spacing.medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private extension ExportMultipleKeysModal {
.foregroundColor(.textAndIconsPrimary)
.font(PrimaryFont.titleS.font)
Spacer()
CloseModalButton(action: animateDismissal)
CircleButton(action: animateDismissal)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ManageKeySetsView: View {
.foregroundColor(.textAndIconsPrimary)
.font(PrimaryFont.titleS.font)
Spacer()
CloseModalButton(action: viewModel.onClose)
CircleButton(action: viewModel.onClose)
}
.padding(.bottom, Spacing.small)
// Spacer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct EnterBananaSplitPasswordView: View {
extension EnterBananaSplitPasswordView {
final class ViewModel: ObservableObject {
@Binding var isPresented: Bool
@Published var seedName: String = ""
@Published var seedName: String
@Published var password: String = ""
@Published var isNameValid: Bool = true
@Published var isPasswordValid: Bool = true
Expand All @@ -133,11 +133,13 @@ extension EnterBananaSplitPasswordView {

init(
seedsMediator: SeedsMediating = ServiceLocator.seedsMediator,
seedName: String = "",
isPresented: Binding<Bool>,
qrCodeData: [String],
onCompletion: @escaping (CreateKeysForNetworksView.OnCompletionAction) -> Void
) {
self.seedsMediator = seedsMediator
_seedName = .init(initialValue: seedName)
self.onCompletion = onCompletion
self.qrCodeData = qrCodeData
_isPresented = isPresented
Expand Down
12 changes: 12 additions & 0 deletions ios/PolkadotVault/Screens/Scan/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct CameraView: View {
) {
EnterBananaSplitPasswordView(
viewModel: .init(
seedName: viewModel.bananaSplitQRCodeRecovery?.seedName ?? "",
isPresented: $viewModel.isPresentingEnterBananaSplitPassword,
qrCodeData: model.bucket,
onCompletion: viewModel.onKeySetAddCompletion(_:)
Expand Down Expand Up @@ -262,16 +263,19 @@ extension CameraView {
private let dynamicDerivationsService: DynamicDerivationsService
private let seedsMediator: SeedsMediating
private let runtimePropertiesProvider: RuntimePropertiesProviding
let bananaSplitQRCodeRecovery: BananaSplitQRCodeRecovery?
private weak var cameraModel: CameraService?

init(
isPresented: Binding<Bool>,
bananaSplitQRCodeRecovery: BananaSplitQRCodeRecovery? = nil,
seedsMediator: SeedsMediating = ServiceLocator.seedsMediator,
scanService: ScanTabService = ScanTabService(),
dynamicDerivationsService: DynamicDerivationsService = DynamicDerivationsService(),
runtimePropertiesProvider: RuntimePropertiesProviding = RuntimePropertiesProvider()
) {
_isPresented = isPresented
self.bananaSplitQRCodeRecovery = bananaSplitQRCodeRecovery
self.seedsMediator = seedsMediator
self.scanService = scanService
self.dynamicDerivationsService = dynamicDerivationsService
Expand Down Expand Up @@ -372,6 +376,13 @@ extension CameraView {
}

func onKeySetAddCompletion(_ completionAction: CreateKeysForNetworksView.OnCompletionAction) {
if let onRecoveryComplete = bananaSplitQRCodeRecovery?.onRecoveryComplete {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
onRecoveryComplete(completionAction)
self.dismissView()
}
return
}
let message: String =
switch completionAction {
case let .createKeySet(seedName):
Expand All @@ -384,6 +395,7 @@ extension CameraView {
style: .info
)
isSnackbarPresented = true
resumeCamera()
}

func onEnterPasswordDismissal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct SettingsBackupModal: View {
.font(PrimaryFont.titleS.font)
}
Spacer()
CloseModalButton(action: viewModel.dismissModal)
CircleButton(action: viewModel.dismissModal)
}
.padding(.leading, Spacing.large)
.padding(.trailing, Spacing.medium)
Expand Down

0 comments on commit 941879a

Please sign in to comment.