Make sure the Recovery Key option is shown on the IdentityConfirmationScreen when available. (#3699)

There was a race condition where 2 different states could be processed at the same time.

* Fix unit test
The view model wasn't stored, so relying the current value publisher didn't have time to fire before deinit.
This commit is contained in:
Doug 2025-01-23 12:39:53 +00:00 committed by GitHub
parent 88e63b297e
commit a70189d318
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 11 deletions

View File

@ -25,18 +25,13 @@ class IdentityConfirmationScreenViewModel: IdentityConfirmationScreenViewModelTy
super.init(initialViewState: IdentityConfirmationScreenViewState(learnMoreURL: appSettings.encryptionURL))
userSession.sessionSecurityStatePublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] state in
Task {
Task { [weak self] in
for await state in userSession.sessionSecurityStatePublisher.values {
// We need to call this inside an AsyncSequence otherwise there's a race condition when the method suspends.
await self?.updateWithSessionSecurityState(state)
}
}
.store(in: &cancellables)
Task {
await updateWithSessionSecurityState(userSession.sessionSecurityStatePublisher.value)
}
}
// MARK: - Public

View File

@ -104,6 +104,8 @@ struct IdentityConfirmationScreen: View {
// MARK: - Previews
struct IdentityConfirmationScreen_Previews: PreviewProvider, TestablePreview {
static var viewModel = makeViewModel()
static var previews: some View {
NavigationStack {
IdentityConfirmationScreen(context: viewModel.context)
@ -113,7 +115,7 @@ struct IdentityConfirmationScreen_Previews: PreviewProvider, TestablePreview {
})
}
private static var viewModel: IdentityConfirmationScreenViewModel {
static func makeViewModel() -> IdentityConfirmationScreenViewModel {
let clientProxy = ClientProxyMock(.init())
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
userSession.sessionSecurityStatePublisher = CurrentValuePublisher<SessionSecurityState, Never>(.init(verificationState: .unverified, recoveryState: .enabled))