Skip to content

Commit

Permalink
feat: add coinjoin error handling on enter amount screen
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Jan 12, 2024
1 parent 33859a5 commit 4553882
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<string name="exchange_rate_template" translatable="false">%1$s DASH = %2$s</string>
<string name="send_coins_error_dusty_send">The amount is too small to send</string>
<string name="send_coins_error_insufficient_money">Insufficient funds</string>
<string name="send_coins_error_insufficient_mixed_money">Insufficient mixed funds. Please wait for mixing to complete.</string>
<string name="syncing">Syncing</string>
<string name="no_connection">No internet connection</string>
<string name="rate_not_available">Not available</string>
Expand Down
8 changes: 7 additions & 1 deletion wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ class SendCoinsFragment: Fragment(R.layout.send_coins_fragment) {
errorMessage = when (dryRunException) {
is Wallet.DustySendRequested -> getString(R.string.send_coins_error_dusty_send)
is InsufficientMoneyException -> if (!requirePinForBalance || userAuthorizedDuring) {
getString(R.string.send_coins_error_insufficient_money)
getString(
if (viewModel.isCoinJoinInsufficentMoneyException) {
R.string.send_coins_error_insufficient_mixed_money
} else {
R.string.send_coins_error_insufficient_money
}
)
} else {
""
}
Expand Down
11 changes: 8 additions & 3 deletions wallet/src/de/schildbach/wallet/ui/send/SendCoinsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
import org.bitcoinj.coinjoin.CoinJoinCoinSelector
import org.bitcoinj.core.Address
import org.bitcoinj.core.Coin
import org.bitcoinj.core.InsufficientMoneyException
Expand Down Expand Up @@ -124,6 +122,13 @@ class SendCoinsViewModel @Inject constructor(
val contactData: LiveData<UsernameSearchResult>
get() = _contactData

private var coinJoinMode: CoinJoinMode = CoinJoinMode.NONE

val isCoinJoinInsufficentMoneyException: Boolean
get() {
return coinJoinMode != CoinJoinMode.NONE && !currentAmount.isGreaterThan(wallet.getBalance(MaxOutputAmountCoinSelector()))
}

init {
blockchainStateDao.observeState()
.filterNotNull()
Expand All @@ -134,11 +139,11 @@ class SendCoinsViewModel @Inject constructor(

coinJoinConfig.observeMode()
.map { mode ->
coinJoinMode = mode
if (mode == CoinJoinMode.NONE) {
MaxOutputAmountCoinSelector()
} else {
MaxOutputAmountCoinJoinCoinSelector(wallet)
// MaxOutputAmountCoinSelector()
}
}
.flatMapLatest { coinSelector ->
Expand Down

0 comments on commit 4553882

Please sign in to comment.