Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Generate address qr in suspended thread #279

Merged
Merged
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 @@ -9,9 +9,13 @@ import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.unit.dp
Expand All @@ -23,6 +27,8 @@ import com.goldenraven.padawanwallet.theme.*
import com.goldenraven.padawanwallet.ui.PadawanAppBar
import com.goldenraven.padawanwallet.ui.standardBorder
import com.goldenraven.padawanwallet.utils.addressToQR
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

private const val TAG = "ReceiveScreen"

Expand All @@ -32,6 +38,15 @@ internal fun ReceiveScreen(
viewModel: WalletViewModel
) {
val address by viewModel.address.observeAsState("Generate new address")
var QR by remember {
mutableStateOf<ImageBitmap?>(null)
}

LaunchedEffect(address){
withContext(Dispatchers.IO){
QR = addressToQR(address)
}
}

ConstraintLayout(
modifier = Modifier
Expand Down Expand Up @@ -63,21 +78,22 @@ internal fun ReceiveScreen(
height = Dimension.fillToConstraints
}
) {
val QR: ImageBitmap? = addressToQR(address)
Log.i(TAG, "New receive address is $address")
if (address != "No address yet" && QR != null) {
Image(
bitmap = QR,
contentDescription = "Bitcoindevkit website QR code",
Modifier.size(250.dp)
)
Spacer(modifier = Modifier.padding(vertical = 8.dp))
SelectionContainer {
Text(
text = address,
fontFamily = ShareTechMono,
fontSize = 12.sp
if (address != "No address yet") {
QR?.let {
Image(
bitmap = it,
contentDescription = "Bitcoindevkit website QR code",
Modifier.size(250.dp)
)
Spacer(modifier = Modifier.padding(vertical = 8.dp))
SelectionContainer {
Text(
text = address,
fontFamily = ShareTechMono,
fontSize = 12.sp
)
}
}
}
}
Expand Down