animation

This commit is contained in:
callebtc
2025-08-30 15:00:20 +02:00
parent 2a7c004db2
commit c14762f82e
3 changed files with 47 additions and 14 deletions
@@ -126,6 +126,10 @@ object NostrProtocol {
if (powSettings.enabled && powSettings.difficulty > 0) { if (powSettings.enabled && powSettings.difficulty > 0) {
Log.d(TAG, "PoW enabled for geohash event: difficulty=${powSettings.difficulty}") Log.d(TAG, "PoW enabled for geohash event: difficulty=${powSettings.difficulty}")
try {
// Start mining state for animated indicators
PoWPreferenceManager.startMining()
// Mine the event before signing // Mine the event before signing
val minedEvent = NostrProofOfWork.mineEvent( val minedEvent = NostrProofOfWork.mineEvent(
event = event, event = event,
@@ -140,6 +144,10 @@ object NostrProtocol {
} else { } else {
Log.w(TAG, "❌ PoW mining failed, proceeding without PoW") Log.w(TAG, "❌ PoW mining failed, proceeding without PoW")
} }
} finally {
// Always stop mining state when done (success or failure)
PoWPreferenceManager.stopMining()
}
} }
return@withContext senderIdentity.signEvent(event) return@withContext senderIdentity.signEvent(event)
@@ -26,6 +26,10 @@ object PoWPreferenceManager {
private val _powDifficulty = MutableStateFlow(DEFAULT_POW_DIFFICULTY) private val _powDifficulty = MutableStateFlow(DEFAULT_POW_DIFFICULTY)
val powDifficulty: StateFlow<Int> = _powDifficulty.asStateFlow() val powDifficulty: StateFlow<Int> = _powDifficulty.asStateFlow()
// Mining state for animated indicators
private val _isMining = MutableStateFlow(false)
val isMining: StateFlow<Boolean> = _isMining.asStateFlow()
private lateinit var sharedPrefs: SharedPreferences private lateinit var sharedPrefs: SharedPreferences
private var isInitialized = false private var isInitialized = false
@@ -121,4 +125,25 @@ object PoWPreferenceManager {
32 to "Maximum (~8h)" 32 to "Maximum (~8h)"
) )
} }
/**
* Get current mining state
*/
fun isMining(): Boolean {
return _isMining.value
}
/**
* Start mining state - triggers animated indicators
*/
fun startMining() {
_isMining.value = true
}
/**
* Stop mining state - stops animated indicators
*/
fun stopMining() {
_isMining.value = false
}
} }
@@ -23,11 +23,11 @@ import com.bitchat.android.nostr.PoWPreferenceManager
@Composable @Composable
fun PoWStatusIndicator( fun PoWStatusIndicator(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
isMining: Boolean = false,
style: PoWIndicatorStyle = PoWIndicatorStyle.COMPACT style: PoWIndicatorStyle = PoWIndicatorStyle.COMPACT
) { ) {
val powEnabled by PoWPreferenceManager.powEnabled.collectAsState() val powEnabled by PoWPreferenceManager.powEnabled.collectAsState()
val powDifficulty by PoWPreferenceManager.powDifficulty.collectAsState() val powDifficulty by PoWPreferenceManager.powDifficulty.collectAsState()
val isMining by PoWPreferenceManager.isMining.collectAsState()
val colorScheme = MaterialTheme.colorScheme val colorScheme = MaterialTheme.colorScheme
val isDark = colorScheme.background.red + colorScheme.background.green + colorScheme.background.blue < 1.5f val isDark = colorScheme.background.red + colorScheme.background.green + colorScheme.background.blue < 1.5f