From 43ad014f54c50fc2fa1cda3e1d6e24229637ad02 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 3 Jan 2023 10:00:21 -0300 Subject: [wallet] Fix crash when exchange is missing currency Can happen when exchange info in wallet-core was not yet fully loaded #7480 --- .../main/java/net/taler/wallet/exchanges/ExchangeAdapter.kt | 11 ++++++++--- .../taler/wallet/withdraw/manual/ManualWithdrawFragment.kt | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'wallet') diff --git a/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeAdapter.kt b/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeAdapter.kt index 5b0d947..e0cf5be 100644 --- a/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeAdapter.kt +++ b/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeAdapter.kt @@ -34,8 +34,9 @@ import net.taler.wallet.exchanges.ExchangeAdapter.ExchangeItemViewHolder @Serializable data class ExchangeItem( val exchangeBaseUrl: String, - val currency: String, - val paytoUris: List + // can be null before exchange info in wallet-core was fully loaded + val currency: String? = null, + val paytoUris: List, ) { val name: String get() = cleanExchange(exchangeBaseUrl) } @@ -79,7 +80,11 @@ internal class ExchangeAdapter( fun bind(item: ExchangeItem) { urlView.text = item.name - currencyView.text = context.getString(R.string.exchange_list_currency, item.currency) + currencyView.text = if (item.currency == null) { + context.getString(R.string.settings_version_unknown) + } else { + context.getString(R.string.exchange_list_currency, item.currency) + } if (selectOnly) { itemView.setOnClickListener { listener.onExchangeSelected(item) } overflowIcon.visibility = GONE diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt index 148b8c0..aae8c95 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/manual/ManualWithdrawFragment.kt @@ -67,7 +67,8 @@ class ManualWithdrawFragment : Fragment() { } private fun onCheckFees() { - if (ui.amountView.text?.isEmpty() != false) { + val currency = exchangeItem.currency + if (currency == null || ui.amountView.text?.isEmpty() != false) { ui.amountLayout.error = getString(R.string.withdraw_amount_error) return } @@ -79,7 +80,7 @@ class ManualWithdrawFragment : Fragment() { ui.amountLayout.error = getString(R.string.withdraw_amount_error) return } - val amount = Amount.fromDouble(exchangeItem.currency, value) + val amount = Amount.fromDouble(currency, value) ui.amountView.hideKeyboard() withdrawManager.getWithdrawalDetails(exchangeItem.exchangeBaseUrl, amount) -- cgit v1.2.3