Skip to content

Commit

Permalink
feat: ios: confirmation dialog when importing dd keys (#1987)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Rybalko <[email protected]>
  • Loading branch information
krodak and prybalko authored Aug 10, 2023
1 parent c26f649 commit d481bc8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
16 changes: 14 additions & 2 deletions ios/PolkadotVault/Modals/Alerts/VerticalActionsBottomModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ struct VerticalActionsBottomModalViewModel {
let content: String?
let dismissActionLabel: LocalizedStringKey
let mainActionLabel: LocalizedStringKey
var mainActionStyle: ActionButtonStyle = .primaryDestructive()
var contentAlignment: TextAlignment = .center

static let removeGeneralVerifier = VerticalActionsBottomModalViewModel(
title: Localizable.Settings.Modal.GeneralVerifier.Label.title.string,
content: Localizable.Settings.Modal.GeneralVerifier.Label.content.string,
dismissActionLabel: Localizable.Settings.Modal.GeneralVerifier.Action.cancel.key,
mainActionLabel: Localizable.Settings.Modal.GeneralVerifier.Action.remove.key
)

static let confirmDerivedKeysCreation = VerticalActionsBottomModalViewModel(
title: Localizable.AddDerivedKeys.Modal.Label.title.string,
content: Localizable.AddDerivedKeys.Modal.Label.content.string,
dismissActionLabel: Localizable.AddDerivedKeys.Modal.Action.cancel.key,
mainActionLabel: Localizable.AddDerivedKeys.Modal.Action.confirm.key,
mainActionStyle: .primary(),
contentAlignment: .center
)
}

struct VerticalActionsBottomModal: View {
Expand Down Expand Up @@ -48,19 +59,20 @@ struct VerticalActionsBottomModal: View {
content: {
VStack(alignment: .leading, spacing: Spacing.medium) {
Text(viewModel.title)
.multilineTextAlignment(viewModel.contentAlignment)
.font(PrimaryFont.titleL.font)
if let content = viewModel.content {
Text(content)
.font(PrimaryFont.bodyL.font)
.lineSpacing(Spacing.extraExtraSmall)
.multilineTextAlignment(.leading)
.multilineTextAlignment(viewModel.contentAlignment)
.foregroundColor(Asset.textAndIconsSecondary.swiftUIColor)
}
VStack {
PrimaryButton(
action: { animateDismissal(mainAction()) },
text: viewModel.mainActionLabel,
style: .primaryDestructive()
style: viewModel.mainActionStyle
)
SecondaryButton(
action: animateDismissal(dismissAction()),
Expand Down
4 changes: 4 additions & 0 deletions ios/PolkadotVault/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,7 @@
"AddDerivedKeys.Error.AlreadyImported" = "Some are hidden from the list because they have already been imported.";
"AddDerivedKeys.Error.DerivedKeyForNetwork.Content" = "Derived key %@ could not be created: %@";
"AddDerivedKeys.Error.DerivedKeyForNetwork.Title" = "There was an issue importing keys.";
"AddDerivedKeys.Modal.Label.Title" = "Please confirm derived key import with the PIN code";
"AddDerivedKeys.Modal.Label.Content" = "Please confirm that you scanned the QR code back into the app. Once confirmed, the imported key will be added to the key set.";
"AddDerivedKeys.Modal.Action.Confirm" = "Confirm with PIN code";
"AddDerivedKeys.Modal.Action.Cancel" = "Cancel";
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ struct AddDerivedKeysView: View {
)
.clearModalBackground()
}
.fullScreenModal(
isPresented: $viewModel.isPresentingAddKeysConfirmation
) {
VerticalActionsBottomModal(
viewModel: .confirmDerivedKeysCreation,
mainAction: viewModel.onConfirmTap(),
isShowingBottomAlert: $viewModel.isPresentingAddKeysConfirmation
)
.clearModalBackground()
}
}

@ViewBuilder
Expand Down Expand Up @@ -183,6 +193,7 @@ extension AddDerivedKeysView {
private let seedsMediator: SeedsMediating
let dataModel: AddDerivedKeysData
@Binding var isPresented: Bool
@Published var isPresentingAddKeysConfirmation: Bool = false
@Published var isPresentingDerivationPath: Bool = false
@Published var isPresentingError: Bool = false
@Published var presentableError: ErrorBottomModalViewModel = .importDynamicDerivedKeys(content: "")
Expand All @@ -204,33 +215,38 @@ extension AddDerivedKeysView {
}

func onDoneTap() {
let success = { [weak self] in
self?.isPresented = false
self?.onCompletion(.onDone)
}
if !dynamicDerivationsPreview.keySet.derivations.isEmpty {
derivedKeysService.createDerivedKeys(
dynamicDerivationsPreview.keySet.seedName,
seedsMediator.getSeed(seedName: dynamicDerivationsPreview.keySet.seedName),
keysToImport: dynamicDerivationsPreview.keySet.derivations
) { [weak self] result in
switch result {
case .success:
success()
case let .failure(error):
self?.presentableError = .importDynamicDerivedKeys(content: error.localizedDescription)
self?.isPresentingError = true
}
}
isPresentingAddKeysConfirmation = true
} else {
success()
onSuccess()
}
}

func onConfirmTap() {
derivedKeysService.createDerivedKeys(
dynamicDerivationsPreview.keySet.seedName,
seedsMediator.getSeed(seedName: dynamicDerivationsPreview.keySet.seedName),
keysToImport: dynamicDerivationsPreview.keySet.derivations
) { [weak self] result in
switch result {
case .success:
self?.onSuccess()
case let .failure(error):
self?.presentableError = .importDynamicDerivedKeys(content: error.localizedDescription)
self?.isPresentingError = true
}
}
}

func onBackTap() {
isPresented = false
onCompletion(.onCancel)
}

private func onSuccess() {
isPresented = false
onCompletion(.onDone)
}
}
}

Expand Down

0 comments on commit d481bc8

Please sign in to comment.