Skip to content

Commit c2bc1f7

Browse files
committed
Round up the bolus value
1 parent 5444599 commit c2bc1f7

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

LoopFollow/Helpers/TextFieldWithToolBar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public struct TextFieldWithToolBar: UIViewRepresentable {
206206
let value = quantity.doubleValue(for: unit)
207207
let formatter = NumberFormatter()
208208
formatter.minimumFractionDigits = unit.preferredFractionDigits
209-
formatter.maximumFractionDigits = unit.preferredFractionDigits
209+
formatter.maximumFractionDigits = max(unit.preferredFractionDigits, 3)
210210
formatter.numberStyle = .decimal
211211
return formatter.string(from: NSNumber(value: value)) ?? ""
212212
}

LoopFollow/Remote/TRC/BolusView.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ struct BolusView: View {
5151

5252
private func roundedToStep(_ value: Double) -> Double {
5353
guard stepU > 0 else { return value }
54-
let stepped = (value / stepU).rounded() * stepU
54+
55+
let stepped = (value / stepU).rounded(.up) * stepU
56+
5557
let p = pow(10.0, Double(stepFractionDigits))
5658
return (stepped * p).rounded() / p
5759
}
@@ -87,6 +89,9 @@ struct BolusView: View {
8789
bolusFieldIsFocused = false
8890
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
8991
if bolusAmount.doubleValue(for: .internationalUnit()) > 0.0 {
92+
let steppedAmount = roundedToStep(self.bolusAmount.doubleValue(for: .internationalUnit()))
93+
bolusAmount = HKQuantity(unit: .internationalUnit(), doubleValue: steppedAmount)
94+
9095
alertType = .confirmBolus
9196
showAlert = true
9297
}
@@ -138,7 +143,7 @@ struct BolusView: View {
138143
title: Text("Old Calculation Warning"),
139144
message: Text(alertMessage ?? ""),
140145
primaryButton: .default(Text("Use Anyway")) {
141-
if let rec = deviceRecBolus.value, rec >= stepU {
146+
if let rec = deviceRecBolus.value {
142147
applyRecommendedBolus(rec)
143148
}
144149
},
@@ -156,7 +161,6 @@ struct BolusView: View {
156161
@ViewBuilder
157162
private func recommendedBlocks(now: Date) -> some View {
158163
if let rec = deviceRecBolus.value,
159-
rec >= stepU,
160164
let t = enactedOrSuggested.value
161165
{
162166
let ageSec = max(0, now.timeIntervalSince1970 - t)
@@ -214,7 +218,6 @@ struct BolusView: View {
214218
}
215219

216220
private func applyRecommendedBolus(_ rec: Double) {
217-
guard rec >= stepU else { return }
218221
let maxU = maxBolus.value.doubleValue(for: .internationalUnit())
219222
let clamped = min(rec, maxU)
220223
let stepped = roundedToStep(clamped)

0 commit comments

Comments
 (0)