Skip to content

Remote Bolus Dev#8

Merged
ps2 merged 11 commits into
ps2:devfrom
gestrich:dev_otp
Mar 12, 2022
Merged

Remote Bolus Dev#8
ps2 merged 11 commits into
ps2:devfrom
gestrich:dev_otp

Conversation

@gestrich

@gestrich gestrich commented May 23, 2021

Copy link
Copy Markdown

This PR includes changes to the Nightscout module to support remote/bolus in dev. See the workspace PR for more details on the overall effort. Comments added inline for review.

@gestrich gestrich force-pushed the dev_otp branch 3 times, most recently from cf61811 to 5c1f4dd Compare June 12, 2021 19:50
@gestrich gestrich force-pushed the dev_otp branch 6 times, most recently from e47ff65 to f84b6f5 Compare June 20, 2021 15:59
@@ -21,12 +21,22 @@ public final class NightscoutService: Service {

public weak var serviceDelegate: ServiceDelegate?

@gestrich gestrich Sep 3, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue was discussed in LoopKit/Loop#1536.

But the gist is that a lazy getter poses issue on the first run that prevents the token from uploading. Since the Nightscout service is not setup the first time this is called, these values will be nil. That will prevent calls that use these values from working until you kill app and restart.

My solution here was a didSet which will keep the uploader in sync with the url/apiSecret. I think a clean solution would be to hook in to the flow that updates these credentials a little deeper.

}

public var isOnboarded: Bool

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otpManager is our wrapper around OneTimePassword that validates our OTP codes from push notifications.

@@ -63,6 +69,8 @@ public final class NightscoutService: Service {
self.lockedObjectIdCache = Locked(ObjectIdCache())
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inject the store to help with unit testing.

@@ -122,6 +130,14 @@ public final class NightscoutService: Service {
try? KeychainManager().setNightscoutCredentials()
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the override issue mentioned above.

Limitation - this wouldn't handle the case of changing the site url or apiSecret.

return passwordsString.split(separator: ",").map({String($0)})
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manages overall OTP operations, using the store above (keychain) to track OTP secret and the last 2 OTP codes.

}
}

public func validateOTP(otpToValidate: String) -> Bool {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hang onto the last 2 codes as we need to make sure a user can't reuse an OTP code per OTP guidelines.

//Already used
return false
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the last 2 codes should guarantee the same code is not used twice.

return true

}

@gestrich gestrich Sep 3, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For option in UI to reset the secret key. I don't think you would really need to this in practice though.

let generator = Generator(factor: .timer(period: TimeInterval(self.tokenPeriod)), secret: secretKeyData, algorithm: algorithm, digits: passwordDigitCount)!
return Token(name: "\(secretKeyName)", issuer: "Loop", generator: generator)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpful for unit tests.

@@ -0,0 +1,79 @@
//

@gestrich gestrich Sep 3, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View model for the view that shows the OTP QR and code.

@@ -0,0 +1,51 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View for the OTP QR and code.

@@ -39,6 +41,14 @@ struct ServiceStatusView: View, HorizontalSizeClassOverride {
Text(String(describing: viewModel.status))
}
.padding()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a SwiftUI expert yet - I haven't figured out how to remove the blue text and get a chevron in place. Any suggestions welcome but not sure also if this is a blocker yet.

Screen Shot 2021-09-03 at 5 08 13 PM

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue seems to be that this button needs to be in a SwiftUI List to get the default chevron button styling. I experimented with that in commit 9ac625a5c488e918dea8f573fe26302716c3873a. That caused a different set of issues including the fact this List has a different background color than our our lists in Settings (inverted). I figured out how to change the row colors but not the background behind the list. Also the list would stay highlighted after popping back to this view, without adding a hack from Stack Overflow.

I opted for a simpler approach - With the latest update, I added a chevron image directly to the row and make sure the button text color is correct (non-blue). This is not ideal to not use the system scheme but seems pretty close to the desired layout.

Screen Shot 2021-09-12 at 9 51 50 AM

@gestrich gestrich marked this pull request as ready for review September 3, 2021 21:09
@ps2 ps2 merged commit 320f47b into ps2:dev Mar 12, 2022
gestrich pushed a commit to gestrich/NightscoutService that referenced this pull request Jan 31, 2024
Updated translations from Lokalise on Sun Oct 22 11:55:50 CDT 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants