diff --git a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt index 0924ee63..d2838a25 100644 --- a/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt +++ b/backend/mpc-system/services/service-party-android/app/src/main/java/com/durian/tssparty/presentation/viewmodel/MainViewModel.kt @@ -502,8 +502,25 @@ class MainViewModel @Inject constructor( if (joinResult.sessionStatus == "in_progress") { android.util.Log.d("MainViewModel", "Session already in_progress, triggering keygen immediately") startKeygenAsJoiner() + } else { + // Otherwise, wait for session_started event + // But also poll session status after a delay in case we missed the event + // This handles the race condition where session_started is sent before we're ready + viewModelScope.launch { + delay(2000) // Wait 2 seconds + val joinInfo = pendingJoinKeygenInfo + if (joinInfo != null && joinInfo.sessionId == sessionInfo.sessionId) { + android.util.Log.d("MainViewModel", "Checking session status after delay...") + val statusResult = repository.getSessionStatus(sessionInfo.sessionId) + statusResult.onSuccess { status -> + if (status.status == "in_progress" && pendingJoinKeygenInfo != null) { + android.util.Log.d("MainViewModel", "Session is now in_progress (detected via polling), triggering keygen") + startKeygenAsJoiner() + } + } + } + } } - // Otherwise, wait for session_started event }, onFailure = { e -> android.util.Log.e("MainViewModel", "gRPC join failed", e)