From e8a0ce16bef18ed984819d4cff1ae53ef25236da Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Thu, 15 Aug 2024 01:09:10 -0700 Subject: [PATCH 1/2] Fix for perpetual Insert Cannula "Pod Already Paired" errors + Add optional mock error Preview handling code for testing + Minor updates to match OmniBLE versions --- .../ViewModels/InsertCannulaViewModel.swift | 6 ++++- OmniKitUI/Views/InsertCannulaView.swift | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/OmniKitUI/ViewModels/InsertCannulaViewModel.swift b/OmniKitUI/ViewModels/InsertCannulaViewModel.swift index ff80f13..cbfa702 100644 --- a/OmniKitUI/ViewModels/InsertCannulaViewModel.swift +++ b/OmniKitUI/ViewModels/InsertCannulaViewModel.swift @@ -130,6 +130,7 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { } @Published var state: InsertCannulaViewModelState = .ready + public var stateNeedsDeliberateUserAcceptance : Bool { switch state { case .ready: @@ -187,7 +188,10 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { self.state = .finished } case .failure(let error): - if self.autoRetryAttempted { + if case .podAlreadyPaired = error { + print("### insertCannula treating podAlreadyPaired as success to avoid looping!") + self.state = .finished + } else if self.autoRetryAttempted { self.autoRetryAttempted = false // allow for an auto retry on the next user attempt self.state = .error(error) } else { diff --git a/OmniKitUI/Views/InsertCannulaView.swift b/OmniKitUI/Views/InsertCannulaView.swift index bf8aec8..c5c593b 100644 --- a/OmniKitUI/Views/InsertCannulaView.swift +++ b/OmniKitUI/Views/InsertCannulaView.swift @@ -69,12 +69,14 @@ struct InsertCannulaView: View { if (self.viewModel.error == nil || self.viewModel.error?.recoverable == true) { actionButton .disabled(self.viewModel.state.isProcessing) + .animation(nil) .zIndex(1) } } .transition(AnyTransition.opacity.combined(with: .move(edge: .bottom))) .padding() } + .animation(.default) .alert(isPresented: $cancelModalIsPresented) { cancelPairingModal } .navigationBarTitle(LocalizedString("Insert Cannula", comment: "navigation bar title for insert cannula"), displayMode: .automatic) .navigationBarBackButtonHidden(true) @@ -107,8 +109,6 @@ struct InsertCannulaView: View { } } - - } @@ -131,9 +131,23 @@ struct InsertCannulaView: View { } class MockCannulaInserter: CannulaInserter { + let mockError: Bool = false + let mockPodAlreadyPairedError: Bool = false + func insertCannula(completion: @escaping (Result) -> Void) { - let mockDelay = TimeInterval(seconds: 3) - let result :Result = .success(mockDelay) + let result :Result + if mockError { + if mockPodAlreadyPairedError { + // A podAlreadyPaired "error" should be treated as an immediate success + result = .failure(OmnipodPumpManagerError.podAlreadyPaired) + } else { + // Others should display the error text and show Deactivate Pod & Retry options + result = .failure(OmnipodPumpManagerError.noPodPaired) + } + } else { + let mockDelay = TimeInterval(seconds: 3) + result = .success(mockDelay) + } completion(result) } From d9d7ce56fc54de365a2b799b31286b50154f8d5b Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Sat, 17 Aug 2024 00:23:03 -0700 Subject: [PATCH 2/2] Use a shorter and less confusing log message --- OmniKitUI/ViewModels/InsertCannulaViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OmniKitUI/ViewModels/InsertCannulaViewModel.swift b/OmniKitUI/ViewModels/InsertCannulaViewModel.swift index cbfa702..a550caa 100644 --- a/OmniKitUI/ViewModels/InsertCannulaViewModel.swift +++ b/OmniKitUI/ViewModels/InsertCannulaViewModel.swift @@ -189,7 +189,7 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { } case .failure(let error): if case .podAlreadyPaired = error { - print("### insertCannula treating podAlreadyPaired as success to avoid looping!") + print("### insertCannula treating podAlreadyPaired as success") self.state = .finished } else if self.autoRetryAttempted { self.autoRetryAttempted = false // allow for an auto retry on the next user attempt