Skip to content

Commit

Permalink
handle better a negative scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed Nov 28, 2023
1 parent 09738ac commit a5b1a1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 1 addition & 4 deletions DuckDuckGo/SyncSettingsViewController+PDFRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ extension SyncSettingsViewController {

navigationController?.visibleViewController?.presentShareSheet(withItems: [code],
fromView: view,
overrideInterfaceStyle: .dark) { [weak self] _, success, _, _ in
guard success else { return }
self?.navigationController?.visibleViewController?.dismiss(animated: true)
}
overrideInterfaceStyle: .dark) { _, _, _, _ in }
}

}
Expand Down
10 changes: 7 additions & 3 deletions DuckDuckGo/SyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class SyncSettingsViewController: UIHostingController<SyncSettingsView> {
if let presentedViewController = navigationController?.presentedViewController {
if !(presentedViewController is UIHostingController<SyncSettingsView>) {
presentedViewController.dismiss(animated: true, completion: nil)
endConnectMode()
}
}
}
Expand Down Expand Up @@ -212,6 +213,7 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate {
}

func syncCodeEntered(code: String) async -> Bool {
var shouldShowSyncEnabled = true
do {
guard let syncCode = try? SyncCode.decodeBase64String(code) else {
return false
Expand All @@ -226,19 +228,21 @@ extension SyncSettingsViewController: ScanOrPasteCodeViewModelDelegate {
showPreparingSync()
if syncService.account == nil {
try await syncService.createAccount(deviceName: deviceName, deviceType: deviceType)
self.dismissVCAndShowRecoveryPDF()
shouldShowSyncEnabled = false
rootView.model.syncEnabled(recoveryCode: recoveryCode)
}
try await syncService.transmitRecoveryKey(connectKey)
self.rootView.model.isSyncingDevices = true

self.rootView.model.$devices
.removeDuplicates()
.dropFirst()
.prefix(1)
.sink { [weak self] _ in
guard let self else { return }
self.dismissVCAndShowRecoveryPDF()
self.rootView.model.isSyncingDevices = false
if shouldShowSyncEnabled {
self.dismissVCAndShowRecoveryPDF()
}
}.store(in: &cancellables)

return true
Expand Down

0 comments on commit a5b1a1e

Please sign in to comment.