Commit 7565b580 authored by pokkst's avatar pokkst

Make sure when setting max button when UTXOs are selected to set the SendRequest to emptyWallet

parent b43dc5f8
......@@ -1050,7 +1050,30 @@ class UIHelper {
sendType.setSelection(0)
MainActivity.INSTANCE.prefs.edit().putString("sendType", MainActivity.INSTANCE.walletHelper.sendType).apply()
var coins = balance.text.toString().replace(" " + MainActivity.INSTANCE.walletHelper.displayUnits, "")
var coins = if(MainActivity.INSTANCE.walletHelper.selectedUtxos.size == 0) {
balance.text.toString().replace(" " + MainActivity.INSTANCE.walletHelper.displayUnits, "")
} else {
var balBch: Double = java.lang.Double.parseDouble(MainActivity.INSTANCE.walletHelper.getMaxValueOfSelectedUtxos().toPlainString())
val unit = MainActivity.INSTANCE.walletHelper.displayUnits
when (unit) {
MonetaryFormat.CODE_BTC -> {
formatBalanceNoUnit(balBch, "#,###.########")
}
MonetaryFormat.CODE_MBTC -> {
balBch *= 1000
formatBalanceNoUnit(balBch, "#,###.#####")
}
MonetaryFormat.CODE_UBTC -> {
balBch *= 1000000
formatBalanceNoUnit(balBch, "#,###.##")
}
"sats" -> {
balBch *= 100000000
formatBalanceNoUnit(balBch, "#,###")
}
else -> formatBalanceNoUnit(balBch, "#,###.########")
}
}
coins = coins.replace(",", "")
println("Setting...")
MainActivity.INSTANCE.runOnUiThread { amountText.text = coins }
......@@ -1529,6 +1552,12 @@ class UIHelper {
return "$formattedStr ${MainActivity.INSTANCE.walletHelper.displayUnits}"
}
fun formatBalanceNoUnit(amount: Double, pattern: String): String {
val formatter = DecimalFormat(pattern, DecimalFormatSymbols(Locale.US))
val formattedStr = formatter.format(amount)
return "$formattedStr"
}
private fun clickScanQR(requestCode: Int) {
val qrHelper = QRHelper()
qrHelper.startQRScan(MainActivity.INSTANCE, requestCode)
......
......@@ -410,32 +410,48 @@ class WalletHelper {
val cachedAddOpReturn = addOpReturn
if (useTor) {
if (coinAmt == getBalance(walletKit!!.wallet()) || coinAmt.isGreaterThan(getBalance(walletKit!!.wallet()))) {
req = SendRequest.emptyWallet(parameters, recipientAddress, torProxy)
/*
Bitcoincashj requires emptying the wallet to only have a single output for some reason.
So, we cache the original setting above, then set the real setting to false here.
After doing the if(addOpReturn) check below, we restore it to its actual setting.
*/
addOpReturn = false
if(selectedUtxos.size == 0) {
if (coinAmt == getBalance(walletKit!!.wallet())) {
req = SendRequest.emptyWallet(parameters, recipientAddress, torProxy)
/*
Bitcoincashj requires emptying the wallet to only have a single output for some reason.
So, we cache the original setting above, then set the real setting to false here.
After doing the if(addOpReturn) check below, we restore it to its actual setting.
*/
addOpReturn = false
} else {
req = SendRequest.to(parameters, recipientAddress, coinAmt, torProxy)
}
} else {
req = SendRequest.to(parameters, recipientAddress, coinAmt, torProxy)
if (coinAmt == getMaxValueOfSelectedUtxos()) {
req = SendRequest.emptyWallet(parameters, recipientAddress, torProxy)
addOpReturn = false
} else {
req = SendRequest.to(parameters, recipientAddress, coinAmt, torProxy)
}
}
} else {
if (coinAmt == getBalance(walletKit!!.wallet()) || coinAmt.isGreaterThan(getBalance(walletKit!!.wallet()))) {
req = SendRequest.emptyWallet(parameters, recipientAddress)
/*
Bitcoincashj requires emptying the wallet to only have a single output for some reason.
So, we cache the original setting above, then set the real setting to false here.
After doing the if(addOpReturn) check below, we restore it to its actual setting.
*/
addOpReturn = false
if(selectedUtxos.size == 0) {
if (coinAmt == getBalance(walletKit!!.wallet())) {
req = SendRequest.emptyWallet(parameters, recipientAddress)
/*
Bitcoincashj requires emptying the wallet to only have a single output for some reason.
So, we cache the original setting above, then set the real setting to false here.
After doing the if(addOpReturn) check below, we restore it to its actual setting.
*/
addOpReturn = false
} else {
req = SendRequest.to(parameters, recipientAddress, coinAmt)
}
} else {
req = SendRequest.to(parameters, recipientAddress, coinAmt)
if (coinAmt == getMaxValueOfSelectedUtxos()) {
req = SendRequest.emptyWallet(parameters, recipientAddress)
addOpReturn = false
} else {
req = SendRequest.to(parameters, recipientAddress, coinAmt)
}
}
}
......@@ -809,6 +825,18 @@ class WalletHelper {
return tx.hashAsString
}
fun getMaxValueOfSelectedUtxos(): Coin {
var utxoAmount = 0.0
for(x in 0 until selectedUtxos.size)
{
val utxo = selectedUtxos[x]
utxoAmount += java.lang.Double.parseDouble(utxo.value.toPlainString())
}
val str = this.uiHelper.formatBalanceNoUnit(utxoAmount, "#.########")
return Coin.parseCoin(str)
}
companion object {
var addOpReturn: Boolean = false
var encrypted: Boolean = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment