Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
Expand Down Expand Up @@ -44,6 +46,7 @@ internal fun ReceiveScreen(
var QR by remember {
mutableStateOf<ImageBitmap?>(null)
}
val qrUIState: QRUIState = viewModel.QRState.collectAsState(QRUIState.NoQR).value

LaunchedEffect(address){
withContext(Dispatchers.IO){
Expand Down Expand Up @@ -86,12 +89,13 @@ internal fun ReceiveScreen(
height = Dimension.fillToConstraints
}
) {
Log.i(TAG, "New receive address is $address")
if (address != "") {
if (qrUIState == QRUIState.Loading) {
CircularProgressIndicator()
} else if (qrUIState == QRUIState.QR) {
QR?.let {
Image(
bitmap = it,
contentDescription = "Bitcoindevkit website QR code",
contentDescription = "QR Code",
Modifier.size(250.dp)
)
Spacer(modifier = Modifier.padding(vertical = 8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class WalletViewModel(
val address: LiveData<String>
get() = _address

var QRState: MutableStateFlow<QRUIState> = MutableStateFlow(QRUIState.NoQR)

private val _isRefreshing: MutableStateFlow<Boolean> = MutableStateFlow(false)
val isRefreshing: StateFlow<Boolean>
get() = _isRefreshing.asStateFlow()
Expand Down Expand Up @@ -119,8 +121,13 @@ class WalletViewModel(
}

fun updateLastUnusedAddress() {
val address = Wallet.getLastUnusedAddress().address
_address.value = address
viewModelScope.launch {
QRState.value = QRUIState.Loading
val address = Wallet.getLastUnusedAddress().address
delay(800)
QRState.value = QRUIState.QR
_address.value = address
}
}

private suspend fun updateBalance() {
Expand Down Expand Up @@ -284,6 +291,12 @@ class WalletViewModel(
}
}

sealed class QRUIState {
object NoQR : QRUIState()
object Loading : QRUIState()
object QR : QRUIState()
}

enum class CurrencyType {
SATS,
BTC,
Expand Down