From 0b22928d9a34252a0ecc4c83c64234070094a286 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 26 Jan 2026 09:19:43 -0800 Subject: [PATCH] =?UTF-8?q?fix(android):=20=E6=B7=BB=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E8=AE=B0=E5=BD=95=E4=BF=9D=E5=AD=98=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复问题: - saveTransactionRecord() 调用没有错误处理,保存失败会静默 - 如果保存失败,交易已广播但没有本地记录 改进: - 添加 try-catch 捕获保存异常 - 保存失败时提示用户"交易已广播但保存记录失败" - 添加成功日志便于调试 影响: - 确保本地发起的交易 100% 被记录或提示失败原因 Co-Authored-By: Claude Sonnet 4.5 --- .../presentation/viewmodel/MainViewModel.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) 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 8b6d838b..8127ec64 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 @@ -1471,20 +1471,26 @@ class MainViewModel @Inject constructor( // 保存交易记录到本地数据库 val state = _transferState.value android.util.Log.d("MainViewModel", "[BROADCAST] Saving transaction record: shareId=${state.shareId}, tokenType=${state.tokenType}") - repository.saveTransactionRecord( - shareId = state.shareId, - fromAddress = tx.from, - toAddress = tx.to, - amount = state.amount, - tokenType = state.tokenType, - txHash = hash, - gasPrice = tx.gasPrice.toString() - ) + try { + repository.saveTransactionRecord( + shareId = state.shareId, + fromAddress = tx.from, + toAddress = tx.to, + amount = state.amount, + tokenType = state.tokenType, + txHash = hash, + gasPrice = tx.gasPrice.toString() + ) + android.util.Log.d("MainViewModel", "[BROADCAST] Transaction record saved successfully") - // 启动后台确认交易状态 - confirmTransactionInBackground(hash, rpcUrl) + // 启动后台确认交易状态 + confirmTransactionInBackground(hash, rpcUrl) - _uiState.update { it.copy(isLoading = false, successMessage = "交易已广播!") } + _uiState.update { it.copy(isLoading = false, successMessage = "交易已广播!") } + } catch (e: Exception) { + android.util.Log.e("MainViewModel", "[BROADCAST] Failed to save transaction record: ${e.message}", e) + _uiState.update { it.copy(isLoading = false, error = "交易已广播但保存记录失败: ${e.message}") } + } }, onFailure = { e -> android.util.Log.e("MainViewModel", "[BROADCAST] FAILED: ${e.message}", e)