fix: prevent app from crashing when attempting to create a transaction before wallet is opened
Some checks failed
/ build-native-libraries-arm64-v8a (push) Has been cancelled
/ build-apk-arm64-v8a (push) Has been cancelled

This commit is contained in:
acx 2025-04-13 11:48:16 +02:00
parent d9957c4214
commit c45793e689
No known key found for this signature in database
GPG key ID: 318D49FCE95DEA5A
2 changed files with 13 additions and 3 deletions

View file

@ -128,7 +128,16 @@ class SendActivity : MoneroActivity() {
} }
sendMaxButton.setOnClickListener { viewModel.setSendingMax(!isSendAll) } sendMaxButton.setOnClickListener { viewModel.setSendingMax(!isSendAll) }
createButton.setOnClickListener { createButton.setOnClickListener {
val outputsValid = checkDestsValidity(isSendAll) val wallet = walletService?.getWallet()
if (wallet == null) {
Toast.makeText(
this,
getString(R.string.cannot_create_transaction_no_wallet),
Toast.LENGTH_SHORT
).show()
return@setOnClickListener
}
val outputsValid = checkDestsValidity(wallet, isSendAll)
if (outputsValid) { if (outputsValid) {
Toast.makeText(this, getString(R.string.creating_tx), Toast.LENGTH_SHORT).show() Toast.makeText(this, getString(R.string.creating_tx), Toast.LENGTH_SHORT).show()
createButton.isEnabled = false createButton.isEnabled = false
@ -237,7 +246,7 @@ class SendActivity : MoneroActivity() {
sendTx(pendingTx) sendTx(pendingTx)
} }
private fun checkDestsValidity(sendAll: Boolean): Boolean { private fun checkDestsValidity(wallet: Wallet, sendAll: Boolean): Boolean {
val dests = rawDests val dests = rawDests
for (dest in dests) { for (dest in dests) {
val address = dest.component1() val address = dest.component1()
@ -252,7 +261,7 @@ class SendActivity : MoneroActivity() {
return false return false
} }
val amountRaw = Wallet.getAmountFromString(amount) val amountRaw = Wallet.getAmountFromString(amount)
val balance = walletService!!.getWalletOrThrow().unlockedBalance val balance = wallet.unlockedBalance
if (amountRaw >= balance || amountRaw <= 0) { if (amountRaw >= balance || amountRaw <= 0) {
Toast.makeText( Toast.makeText(
this, this,

View file

@ -62,6 +62,7 @@
<string name="receive">Receive</string> <string name="receive">Receive</string>
<string name="creating_tx">Creating transaction…</string> <string name="creating_tx">Creating transaction…</string>
<string name="creating_tx_failed_invalid_outputs">Invalid destination combination</string> <string name="creating_tx_failed_invalid_outputs">Invalid destination combination</string>
<string name="cannot_create_transaction_no_wallet">Cannot create transaction - wallet is not opened yet</string>
<string name="sending_tx">Sending transaction…</string> <string name="sending_tx">Sending transaction…</string>
<string name="sent_tx">Sent transaction!</string> <string name="sent_tx">Sent transaction!</string>
<string name="no_camera_permission">No camera permission</string> <string name="no_camera_permission">No camera permission</string>