Skip to content

Commit

Permalink
fix(crash): AND-6751 fix activity details crash (#4091)
Browse files Browse the repository at this point in the history
  • Loading branch information
dserrano-bc committed Nov 10, 2022
1 parent 95ba0bd commit b27b044
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Expand Up @@ -18,6 +18,7 @@ import com.blockchain.componentlib.alert.SnackbarType
import com.blockchain.componentlib.viewextensions.gone
import com.blockchain.componentlib.viewextensions.visible
import com.blockchain.core.price.historic.HistoricRateFetcher
import com.blockchain.logging.RemoteLogger
import com.blockchain.preferences.CurrencyPrefs
import com.blockchain.presentation.koin.scopedInject
import com.google.android.material.snackbar.Snackbar
Expand Down Expand Up @@ -65,6 +66,7 @@ class ActivitiesFragment :
private val disposables = CompositeDisposable()
private val currencyPrefs: CurrencyPrefs by inject()
private val assetResources: AssetResources by inject()
private val remoteLogger: RemoteLogger by inject()
private val historicRateFetcher: HistoricRateFetcher by scopedInject()

private var state: ActivitiesState? = null
Expand Down Expand Up @@ -99,20 +101,37 @@ class ActivitiesFragment :
showBottomSheet(AccountSelectSheet.newInstance(this))
}
ActivitiesSheet.CRYPTO_ACTIVITY_DETAILS -> {
newState.selectedCurrency?.asAssetInfoOrThrow()?.let {
showBottomSheet(
CryptoActivityDetailsBottomSheet.newInstance(
it, newState.selectedTxId,
newState.activityType
try {
newState.selectedCurrency?.asAssetInfoOrThrow()?.let { assetInfo ->
showBottomSheet(
CryptoActivityDetailsBottomSheet.newInstance(
asset = assetInfo,
txHash = newState.selectedTxId,
activityType = newState.activityType
)
)
}
} catch (e: IllegalArgumentException) {
remoteLogger.logException(
throwable = e,
logMessage = "Failed to cast AssetInfo for ${newState.selectedCurrency?.networkTicker}"
)
showDetailsLoadingError()
}
}
ActivitiesSheet.FIAT_ACTIVITY_DETAILS -> {
newState.selectedCurrency?.asFiatCurrencyOrThrow()?.let {
showBottomSheet(
FiatActivityDetailsBottomSheet.newInstance(it, newState.selectedTxId)
try {
newState.selectedCurrency?.asFiatCurrencyOrThrow()?.let {
showBottomSheet(
FiatActivityDetailsBottomSheet.newInstance(it, newState.selectedTxId)
)
}
} catch (e: IllegalArgumentException) {
remoteLogger.logException(
throwable = e,
logMessage = "Failed to cast FiatCurrency for ${newState.selectedCurrency?.networkTicker}"
)
showDetailsLoadingError()
}
}
null -> {
Expand Down
Expand Up @@ -30,7 +30,6 @@ import com.blockchain.nabu.datamanagers.OrderState
import com.blockchain.nabu.datamanagers.RecurringBuyFailureReason
import com.blockchain.presentation.koin.scopedInject
import com.google.android.material.snackbar.Snackbar
import info.blockchain.balance.AssetCatalogue
import info.blockchain.balance.AssetInfo
import info.blockchain.wallet.multiaddress.TransactionSummary
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
Expand Down Expand Up @@ -72,7 +71,6 @@ class CryptoActivityDetailsBottomSheet : MviBottomSheet<ActivityDetailsModel,
DialogSheetActivityDetailsBinding.inflate(inflater, container, false)

override val model: ActivityDetailsModel by scopedInject()
private val assetCatalogue: AssetCatalogue by inject()
private val compositeDisposable = CompositeDisposable()

private val listAdapter: ActivityDetailsDelegateAdapter by lazy {
Expand All @@ -89,9 +87,8 @@ class CryptoActivityDetailsBottomSheet : MviBottomSheet<ActivityDetailsModel,
}

private val asset: AssetInfo by lazy {
arguments?.getString(ARG_CRYPTO_ASSET)?.let {
assetCatalogue.assetInfoFromNetworkTicker(it)
} ?: throw IllegalArgumentException("Crypto asset should not be null")
arguments?.getSerializable(ARG_CRYPTO_ASSET) as? AssetInfo
?: throw IllegalArgumentException("Crypto asset cast failed")
}

private val activityType by lazy {
Expand Down Expand Up @@ -591,7 +588,7 @@ class CryptoActivityDetailsBottomSheet : MviBottomSheet<ActivityDetailsModel,
): CryptoActivityDetailsBottomSheet {
return CryptoActivityDetailsBottomSheet().apply {
arguments = Bundle().apply {
putString(ARG_CRYPTO_ASSET, asset.networkTicker)
putSerializable(ARG_CRYPTO_ASSET, asset)
putString(ARG_TRANSACTION_HASH, txHash)
putSerializable(ARG_ACTIVITY_TYPE, activityType)
}
Expand Down

0 comments on commit b27b044

Please sign in to comment.