Skip to content

Commit

Permalink
Fix: Generate address qr in suspended thread
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowHatpro committed Apr 9, 2023
1 parent 2d2a8aa commit c7e6191
Showing 1 changed file with 29 additions and 13 deletions.
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

0 comments on commit c7e6191

Please sign in to comment.