From 855d5ffa5b8b4ceca4258d83bc71939d029dd933 Mon Sep 17 00:00:00 2001 From: mtgriego Date: Tue, 16 Apr 2024 14:28:14 -0700 Subject: [PATCH] fix issue where add-ons were not displayed if non of the rewards were shippable (#2019) (#2020) --- .../viewmodels/projectpage/AddOnsViewModel.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/kickstarter/viewmodels/projectpage/AddOnsViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/projectpage/AddOnsViewModel.kt index c0c350b039..17727bdd0f 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/projectpage/AddOnsViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/projectpage/AddOnsViewModel.kt @@ -119,6 +119,8 @@ class AddOnsViewModel(val environment: Environment) : ViewModel() { ) shippingRules = shippingRulesEnvelope.shippingRules() }.addToDisposable(disposables) + } ?: run { + shippingRulesObservable.onNext(listOf()) } } } @@ -153,8 +155,12 @@ class AddOnsViewModel(val environment: Environment) : ViewModel() { return this.currentConfig.observable() .map { it.countryCode() } .map { countryCode -> - shippingRules.firstOrNull { it.location()?.country() == countryCode } - ?: shippingRules.first() + if (shippingRules.isNotEmpty()) { + shippingRules.firstOrNull { it.location()?.country() == countryCode } + ?: shippingRules.first() + } else { + ShippingRule.builder().build() + } } }