Просмотр исходного кода

Ensure shortcuts bolus does not exceed max bolus setting in app

- Even if recommended insulin is selected as the cap for shortcut boluses, do not allow boluses to exceed the app's max bolus setting
- Better notification text to notify users what maximums are in place for bolus safeguards
- Important TODO added to refactor/update insulinRequired to pull from Determined in Core Data rather than suggested (this MUST be done before releasing)
Auggie Fisher 1 год назад
Родитель
Сommit
1611043ec5
1 измененных файлов с 11 добавлено и 2 удалено
  1. 11 2
      FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift

+ 11 - 2
FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift

@@ -4,6 +4,8 @@ import Foundation
 
 @available(iOS 16.0,*) final class BolusIntentRequest: BaseIntentsRequest {
     private var suggestion: Determination? {
+        //TODO: CRITICAL
+        /// This MUST update to use the latest determination's insulinRequired from Core Data
         fileStorage.retrieve(OpenAPS.Enact.suggested, as: Determination.self)
     }
 
@@ -21,7 +23,7 @@ import Foundation
         case .limitBolusMax:
             if Decimal(bolusAmount) > settingsManager.pumpSettings.maxBolus {
                 return LocalizedStringResource(
-                    "The bolus cannot be larger than the pump setting max bolus.",
+                    "The bolus cannot be larger than the pump setting max bolus (\(settingsManager.pumpSettings.maxBolus.description)).",
                     table: "ShortcutsDetail"
                 )
             } else {
@@ -33,7 +35,14 @@ import Foundation
             let insulinSuggestion = suggestion?.insulinForManualBolus ?? 0
             if Decimal(bolusAmount) > insulinSuggestion {
                 return LocalizedStringResource(
-                    "The bolus cannot be larger than the suggested insulin.",
+                    "The bolus cannot be larger than the suggested insulin (\(insulinSuggestion.description)).",
+                    table: "ShortcutsDetail"
+                )
+            }
+            // Also make sure that no matter what, the bolus doesn't exceed the max setting in Trio
+            else if Decimal(bolusAmount) > settingsManager.pumpSettings.maxBolus {
+                return LocalizedStringResource(
+                    "The bolus cannot be larger than the pump setting max bolus (\(settingsManager.pumpSettings.maxBolus.description)).",
                     table: "ShortcutsDetail"
                 )
             } else {