fix(android): 修复参与者列表在keygen开始后继续增加的bug
问题: 发起者端参与方显示4/3(2-of-3 MPC) 原因: session_started事件后仍继续处理participant_joined事件 修复方案: 1. 在participant_joined处理中检查sessionStatus 2. 如果已是IN_PROGRESS或COMPLETED则忽略新的participant_joined事件 3. session_started时只补全不完整的列表,不覆盖 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
613f85f1c2
commit
7b8105d76c
|
|
@ -343,8 +343,10 @@ class MainViewModel @Inject constructor(
|
||||||
val currentSessionId = _currentSessionId.value
|
val currentSessionId = _currentSessionId.value
|
||||||
if (currentSessionId != null && event.sessionId == currentSessionId) {
|
if (currentSessionId != null && event.sessionId == currentSessionId) {
|
||||||
android.util.Log.d("MainViewModel", "Session started event for keygen initiator, triggering keygen")
|
android.util.Log.d("MainViewModel", "Session started event for keygen initiator, triggering keygen")
|
||||||
// Initialize participant list with all N parties (keygen requires all parties)
|
// Ensure participant list has exactly N parties (fill if incomplete, don't add more)
|
||||||
_sessionParticipants.value = (1..event.thresholdN).map { "参与方 $it" }
|
if (_sessionParticipants.value.size < event.thresholdN) {
|
||||||
|
_sessionParticipants.value = (1..event.thresholdN).map { "参与方 $it" }
|
||||||
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
startKeygenAsInitiator(
|
startKeygenAsInitiator(
|
||||||
sessionId = currentSessionId,
|
sessionId = currentSessionId,
|
||||||
|
|
@ -359,6 +361,10 @@ class MainViewModel @Inject constructor(
|
||||||
val joinKeygenInfo = pendingJoinKeygenInfo
|
val joinKeygenInfo = pendingJoinKeygenInfo
|
||||||
if (joinKeygenInfo != null && event.sessionId == joinKeygenInfo.sessionId) {
|
if (joinKeygenInfo != null && event.sessionId == joinKeygenInfo.sessionId) {
|
||||||
android.util.Log.d("MainViewModel", "Session started event for keygen joiner, triggering keygen")
|
android.util.Log.d("MainViewModel", "Session started event for keygen joiner, triggering keygen")
|
||||||
|
// Ensure participant list has exactly N parties
|
||||||
|
if (_joinKeygenParticipants.value.size < event.thresholdN) {
|
||||||
|
_joinKeygenParticipants.value = (1..event.thresholdN).map { "参与方 $it" }
|
||||||
|
}
|
||||||
startKeygenAsJoiner()
|
startKeygenAsJoiner()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -366,8 +372,10 @@ class MainViewModel @Inject constructor(
|
||||||
val joinSignInfo = pendingJoinSignInfo
|
val joinSignInfo = pendingJoinSignInfo
|
||||||
if (joinSignInfo != null && event.sessionId == joinSignInfo.sessionId) {
|
if (joinSignInfo != null && event.sessionId == joinSignInfo.sessionId) {
|
||||||
android.util.Log.d("MainViewModel", "Session started event for sign joiner, triggering sign")
|
android.util.Log.d("MainViewModel", "Session started event for sign joiner, triggering sign")
|
||||||
// Initialize participant list with T parties (sign requires T parties)
|
// Ensure participant list has exactly T parties
|
||||||
_coSignParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
|
if (_coSignParticipants.value.size < event.thresholdT) {
|
||||||
|
_coSignParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
|
||||||
|
}
|
||||||
startSignAsJoiner()
|
startSignAsJoiner()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -376,8 +384,10 @@ class MainViewModel @Inject constructor(
|
||||||
android.util.Log.d("MainViewModel", "Checking for sign initiator: signSessionId=$signSessionId, eventSessionId=${event.sessionId}")
|
android.util.Log.d("MainViewModel", "Checking for sign initiator: signSessionId=$signSessionId, eventSessionId=${event.sessionId}")
|
||||||
if (signSessionId != null && event.sessionId == signSessionId) {
|
if (signSessionId != null && event.sessionId == signSessionId) {
|
||||||
android.util.Log.d("MainViewModel", "Session started event for sign initiator, triggering sign")
|
android.util.Log.d("MainViewModel", "Session started event for sign initiator, triggering sign")
|
||||||
// Initialize participant list with T parties (sign requires T parties)
|
// Ensure participant list has exactly T parties
|
||||||
_signParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
|
if (_signParticipants.value.size < event.thresholdT) {
|
||||||
|
_signParticipants.value = (1..event.thresholdT).map { "参与方 $it" }
|
||||||
|
}
|
||||||
startSignAsInitiator(event.selectedParties)
|
startSignAsInitiator(event.selectedParties)
|
||||||
} else {
|
} else {
|
||||||
android.util.Log.d("MainViewModel", "NOT triggering sign initiator: signSessionId=$signSessionId, pendingSignInitiatorInfo=${pendingSignInitiatorInfo?.sessionId}")
|
android.util.Log.d("MainViewModel", "NOT triggering sign initiator: signSessionId=$signSessionId, pendingSignInitiatorInfo=${pendingSignInitiatorInfo?.sessionId}")
|
||||||
|
|
@ -386,6 +396,14 @@ class MainViewModel @Inject constructor(
|
||||||
"party_joined", "participant_joined" -> {
|
"party_joined", "participant_joined" -> {
|
||||||
android.util.Log.d("MainViewModel", "Processing participant_joined event...")
|
android.util.Log.d("MainViewModel", "Processing participant_joined event...")
|
||||||
|
|
||||||
|
// Don't add participants if keygen/sign has already started
|
||||||
|
// This prevents duplicate additions after session_started event
|
||||||
|
val currentStatus = repository.sessionStatus.value
|
||||||
|
if (currentStatus == SessionStatus.IN_PROGRESS || currentStatus == SessionStatus.COMPLETED) {
|
||||||
|
android.util.Log.d("MainViewModel", " Session already in progress/completed, ignoring participant_joined")
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
|
||||||
// Update participant count for initiator's CreateWallet screen
|
// Update participant count for initiator's CreateWallet screen
|
||||||
val currentSessionId = _currentSessionId.value
|
val currentSessionId = _currentSessionId.value
|
||||||
android.util.Log.d("MainViewModel", " Checking for initiator: currentSessionId=$currentSessionId, eventSessionId=${event.sessionId}")
|
android.util.Log.d("MainViewModel", " Checking for initiator: currentSessionId=$currentSessionId, eventSessionId=${event.sessionId}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue