Skip to content

Commit

Permalink
Make sure the Recovery Key option is shown on the IdentityConfirmatio…
Browse files Browse the repository at this point in the history
…nScreen 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.
  • Loading branch information
pixlwave authored Jan 23, 2025
1 parent 88e63b2 commit a70189d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
await self?.updateWithSessionSecurityState(state)
}
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)
}
.store(in: &cancellables)
}

// MARK: - Public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit a70189d

Please sign in to comment.