@@ -30,6 +30,8 @@ protocol ManualDoseViewModelDelegate: AnyObject {
30
30
31
31
func addManuallyEnteredDose( startDate: Date , units: Double , insulinType: InsulinType ? ) async
32
32
func insulinModel( for type: InsulinType ? ) -> InsulinModel
33
+
34
+ func fetchData( for baseTime: Date , disablingPreMeal: Bool , ensureDosingCoverageStart: Date ? ) async throws -> StoredDataAlgorithmInput
33
35
}
34
36
35
37
@MainActor
@@ -227,7 +229,11 @@ final class ManualEntryDoseViewModel: ObservableObject {
227
229
return
228
230
}
229
231
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 ( )
231
237
232
238
let insulinModel = delegate. insulinModel ( for: selectedInsulinType)
233
239
@@ -239,21 +245,15 @@ final class ManualEntryDoseViewModel: ObservableObject {
239
245
insulinModel: insulinModel
240
246
)
241
247
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 )
245
250
246
- if let input = state. input {
247
251
self . glucoseValues = input. glucoseHistory
248
252
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 {
257
257
predictedGlucoseValues = [ ]
258
258
}
259
259
0 commit comments