Skip to content

Commit 800bdc6

Browse files
ovitrifclaude
andcommitted
fix: convert remaining toast calls to toaster API
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 81f0b31 commit 800bdc6

1 file changed

Lines changed: 25 additions & 30 deletions

File tree

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
2828
import dagger.hilt.android.qualifiers.ApplicationContext
2929
import kotlinx.coroutines.CoroutineDispatcher
3030
import kotlinx.coroutines.CoroutineScope
31-
import kotlinx.coroutines.Dispatchers
3231
import kotlinx.coroutines.Job
3332
import kotlinx.coroutines.TimeoutCancellationException
3433
import kotlinx.coroutines.async
@@ -812,14 +811,13 @@ class AppViewModel @Inject constructor(
812811
testTag: String? = null,
813812
) {
814813
_sendUiState.update { it.copy(isAddressInputValid = false) }
815-
var description = context.getString(descriptionRes)
816-
descriptionArgs.forEach { (key, value) ->
817-
description = description.replace("{$key}", value)
818-
}
819-
toast(
820-
type = Toast.ToastType.ERROR,
821-
title = context.getString(titleRes),
822-
description = description,
814+
toaster.error(
815+
title = ToastText(titleRes),
816+
body = if (descriptionArgs.isEmpty()) {
817+
ToastText(descriptionRes)
818+
} else {
819+
ToastText(descriptionRes, descriptionArgs)
820+
},
823821
testTag = testTag,
824822
)
825823
}
@@ -998,10 +996,9 @@ class AppViewModel @Inject constructor(
998996

999997
// TODO Workaround for https://github.com/synonymdev/bitkit-core/issues/63
1000998
if (Bip21Utils.isDuplicatedBip21(result)) {
1001-
toast(
1002-
type = Toast.ToastType.ERROR,
1003-
title = context.getString(R.string.other__scan_err_decoding),
1004-
description = context.getString(R.string.other__scan__error__generic),
999+
toaster.error(
1000+
title = ToastText(R.string.other__scan_err_decoding),
1001+
body = ToastText(R.string.other__scan__error__generic),
10051002
testTag = "DuplicatedBip21Toast",
10061003
)
10071004
return@withContext
@@ -1036,20 +1033,18 @@ class AppViewModel @Inject constructor(
10361033
private suspend fun onScanOnchain(invoice: OnChainInvoice, scanResult: String) {
10371034
val validatedAddress = runCatching { validateBitcoinAddress(invoice.address) }
10381035
.getOrElse {
1039-
toast(
1040-
type = Toast.ToastType.ERROR,
1041-
title = context.getString(R.string.other__scan_err_decoding),
1042-
description = context.getString(R.string.wallet__error_invalid_bitcoin_address),
1036+
toaster.error(
1037+
title = ToastText(R.string.other__scan_err_decoding),
1038+
body = ToastText(R.string.wallet__error_invalid_bitcoin_address),
10431039
testTag = "InvalidAddressToast",
10441040
)
10451041
return
10461042
}
10471043

10481044
if (NetworkValidationHelper.isNetworkMismatch(validatedAddress.network.toLdkNetwork(), Env.network)) {
1049-
toast(
1050-
type = Toast.ToastType.ERROR,
1051-
title = context.getString(R.string.other__scan_err_decoding),
1052-
description = context.getString(R.string.other__scan__error__generic),
1045+
toaster.error(
1046+
title = ToastText(R.string.other__scan_err_decoding),
1047+
body = ToastText(R.string.other__scan__error__generic),
10531048
testTag = "InvalidAddressToast",
10541049
)
10551050
return
@@ -1110,10 +1105,9 @@ class AppViewModel @Inject constructor(
11101105
// Check on-chain balance before proceeding to amount screen
11111106
val maxSendOnchain = walletRepo.balanceState.value.maxSendOnchainSats
11121107
if (maxSendOnchain == 0uL) {
1113-
toast(
1114-
type = Toast.ToastType.ERROR,
1115-
title = context.getString(R.string.other__pay_insufficient_savings),
1116-
description = context.getString(R.string.other__pay_insufficient_savings_description),
1108+
toaster.error(
1109+
title = ToastText(R.string.other__pay_insufficient_savings),
1110+
body = ToastText(R.string.other__pay_insufficient_savings_description),
11171111
testTag = "InsufficientSavingsToast",
11181112
)
11191113
return
@@ -1122,11 +1116,12 @@ class AppViewModel @Inject constructor(
11221116
// Check if on-chain invoice amount exceeds available balance
11231117
if (invoice.amountSatoshis > 0uL && invoice.amountSatoshis > maxSendOnchain) {
11241118
val shortfall = invoice.amountSatoshis - maxSendOnchain
1125-
toast(
1126-
type = Toast.ToastType.ERROR,
1127-
title = context.getString(R.string.other__pay_insufficient_savings),
1128-
description = context.getString(R.string.other__pay_insufficient_savings_amount_description)
1129-
.replace("{amount}", formatMoneyValue(shortfall)),
1119+
toaster.error(
1120+
title = ToastText(R.string.other__pay_insufficient_savings),
1121+
body = ToastText(
1122+
R.string.other__pay_insufficient_savings_amount_description,
1123+
mapOf("amount" to formatMoneyValue(shortfall)),
1124+
),
11301125
testTag = "InsufficientSavingsToast",
11311126
)
11321127
return

0 commit comments

Comments
 (0)