@@ -30,6 +30,8 @@ protocol ManualDoseViewModelDelegate: AnyObject {
3030
3131 func addManuallyEnteredDose( startDate: Date , units: Double , insulinType: InsulinType ? ) async
3232 func insulinModel( for type: InsulinType ? ) -> InsulinModel
33+
34+ func fetchData( for baseTime: Date , disablingPreMeal: Bool , ensureDosingCoverageStart: Date ? ) async throws -> StoredDataAlgorithmInput
3335}
3436
3537@MainActor
@@ -227,7 +229,11 @@ final class ManualEntryDoseViewModel: ObservableObject {
227229 return
228230 }
229231
230- let state = await delegate. algorithmDisplayState
232+ let displayState = await delegate. algorithmDisplayState
233+ self . activeInsulin = displayState. activeInsulin? . quantity
234+ self . activeCarbs = displayState. activeCarbs? . quantity
235+
236+ let startDate = now ( )
231237
232238 let insulinModel = delegate. insulinModel ( for: selectedInsulinType)
233239
@@ -239,21 +245,15 @@ final class ManualEntryDoseViewModel: ObservableObject {
239245 insulinModel: insulinModel
240246 )
241247
242- self . activeInsulin = state. activeInsulin? . quantity
243- self . activeCarbs = state. activeCarbs? . quantity
244-
248+ do {
249+ let input = try await delegate. fetchData ( for: startDate, disablingPreMeal: false , ensureDosingCoverageStart: nil )
245250
246- if let input = state. input {
247251 self . glucoseValues = input. glucoseHistory
248252
249- do {
250- predictedGlucoseValues = try input
251- . addingDose ( dose: enteredBolusDose)
252- . predictGlucose ( )
253- } catch {
254- predictedGlucoseValues = [ ]
255- }
256- } else {
253+ predictedGlucoseValues = try input
254+ . addingDose ( dose: enteredBolusDose)
255+ . predictGlucose ( )
256+ } catch {
257257 predictedGlucoseValues = [ ]
258258 }
259259
0 commit comments