-
Notifications
You must be signed in to change notification settings - Fork 988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MBL-1893 && MBL-1877: Separate rewards from project query #2173
Changes from all commits
b9133a8
aca8860
2d96c82
5303933
df8d8d5
c0c0bad
38497bb
a4c4625
94df6a6
5c08ff9
db789ed
e4a78e5
840ebfe
ffdffbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import DeletePaymentSourceMutation | |
import ErroredBackingsQuery | ||
import FetchCategoryQuery | ||
import FetchProjectQuery | ||
import FetchProjectRewardsQuery | ||
import FetchProjectsQuery | ||
import GetBackingQuery | ||
import GetCommentQuery | ||
|
@@ -52,6 +53,7 @@ import com.kickstarter.features.pledgedprojectsoverview.data.PledgedProjectsOver | |
import com.kickstarter.libs.utils.extensions.isNotNull | ||
import com.kickstarter.libs.utils.extensions.toBoolean | ||
import com.kickstarter.libs.utils.extensions.toProjectSort | ||
import com.kickstarter.mock.factories.RewardFactory | ||
import com.kickstarter.models.Backing | ||
import com.kickstarter.models.Category | ||
import com.kickstarter.models.Checkout | ||
|
@@ -208,6 +210,7 @@ interface ApolloClientTypeV2 { | |
fun createOrUpdateBackingAddress(eventInput: CreateOrUpdateBackingAddressData): Observable<Boolean> | ||
fun completeOrder(orderInput: CompleteOrderInput): Observable<CompleteOrderPayload> | ||
fun getPledgedProjectsOverviewPledges(inputData: PledgedProjectsOverviewQueryData): Observable<PledgedProjectsOverviewEnvelope> | ||
fun getRewardsFromProject(slug: String): Observable<List<Reward>> | ||
} | ||
|
||
private const val PAGE_SIZE = 25 | ||
|
@@ -714,6 +717,45 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient | |
}.subscribeOn(Schedulers.io()) | ||
} | ||
|
||
override fun getRewardsFromProject(slug: String): Observable<List<Reward>> { | ||
return Observable.defer { | ||
val ps = PublishSubject.create<List<Reward>>() | ||
val query = FetchProjectRewardsQuery.builder() | ||
.slug(slug) | ||
.build() | ||
|
||
this.service.query(query) | ||
.enqueue(object : ApolloCall.Callback<FetchProjectRewardsQuery.Data>() { | ||
override fun onFailure(e: ApolloException) { | ||
ps.onError(e) | ||
} | ||
|
||
override fun onResponse(response: Response<FetchProjectRewardsQuery.Data>) { | ||
if (response.hasErrors()) { | ||
ps.onError(Exception(response.errors?.first()?.message)) | ||
} | ||
response.data?.let { data -> | ||
val rwList = data.project()?.rewards()?.nodes()?.map { | ||
rewardTransformer( | ||
rewardGr = it.fragments().reward(), | ||
allowedAddons = it.allowedAddons().pageInfo().startCursor()?.isNotEmpty() ?: false, | ||
rewardItems = complexRewardItemsTransformer(it.items()?.fragments()?.rewardItems()), | ||
simpleShippingRules = it.simpleShippingRulesExpanded() | ||
) | ||
} ?: emptyList() | ||
// - API does not provide the Reward no reward, we need to add it first | ||
val minPledge = data.project()?.minPledge()?.toDouble() ?: 1.0 | ||
val modifiedRewards = rwList.toMutableList() | ||
modifiedRewards.add(0, RewardFactory.noReward().toBuilder().minimum(minPledge).build()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding reward no reward to the list of rewards. It is not provided by the API, but the minimum value to be pledged is configured in a project level. |
||
ps.onNext(modifiedRewards.toList()) | ||
} | ||
ps.onComplete() | ||
} | ||
}) | ||
return@defer ps | ||
} | ||
} | ||
|
||
private fun getAddOnsFromProject(addOnsGr: GetProjectAddOnsQuery.AddOns): List<Reward> { | ||
return addOnsGr.nodes()?.map { node -> | ||
val shippingRulesGr = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,7 +223,8 @@ fun RewardCarouselScreen( | |
id = R.string.Back_it_because_you_believe_in_it | ||
), | ||
onRewardSelectClicked = { onRewardSelected(reward) }, | ||
isCTAButtonVisible = project.isAllowedToPledge() | ||
isCTAButtonVisible = project.isAllowedToPledge(), | ||
yourSelectionIsVisible = project.backing()?.isBacked(reward) ?: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blue pill was not visible when the baked reward is a "Reward no reward" |
||
) | ||
} else { | ||
KSRewardCard( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,7 +150,6 @@ class AddOnsViewModel(val environment: Environment, bundle: Bundle? = null) : Vi | |
bonusAmount = b.amount() | ||
} else { | ||
backedAddOns = b.addOns() ?: emptyList() | ||
currentUserReward = b.reward() ?: currentUserReward | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was causing the issue mentioned here |
||
bonusAmount = b.bonusAmount() | ||
} | ||
} | ||
|
@@ -229,10 +228,14 @@ class AddOnsViewModel(val environment: Environment, bundle: Bundle? = null) : Vi | |
holder[it.id()] = it | ||
} | ||
|
||
// Take the backed AddOns, update with the backed AddOn information which will contain the backed quantity | ||
backedAddOns.map { | ||
holder[it.id()] = it | ||
currentSelection[it.id()] = it.quantity() ?: 0 | ||
// Take the backed AddOns, update with matching addOn ID with the quantity information | ||
backedAddOns.map { backedAddOn -> | ||
val aux = holder[backedAddOn.id()] | ||
if (aux != null) { | ||
val updated = aux.toBuilder().quantity(backedAddOn.quantity()).build() | ||
holder[backedAddOn.id()] = updated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before we were using the information from the baked object, now we update the "quantity" field alone to not loose the "shipping rules" field |
||
} | ||
currentSelection[backedAddOn.id()] = backedAddOn.quantity() ?: 0 | ||
} | ||
|
||
return holder.values.toList() | ||
|
@@ -278,7 +281,7 @@ class AddOnsViewModel(val environment: Environment, bundle: Bundle? = null) : Vi | |
val selectedAddOns = mutableListOf<Reward>() | ||
addOns.forEach { | ||
val amount = currentSelection[it.id()] | ||
if (amount != null) { | ||
if (amount != null && amount > 0) { | ||
selectedAddOns.add(it.toBuilder().quantity(amount).build()) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,6 @@ class CrowdfundCheckoutViewModel(val environment: Environment, bundle: Bundle? = | |
fun provideBundle(arguments: Bundle?) { | ||
val pData = arguments?.getParcelable(ArgumentsKey.PLEDGE_PLEDGE_DATA) as PledgeData? | ||
pledgeReason = arguments?.getSerializable(ArgumentsKey.PLEDGE_PLEDGE_REASON) as PledgeReason? | ||
val flowContext = pledgeReason?.let { PledgeFlowContext.forPledgeReason(it) } | ||
|
||
if (pData != null) { | ||
pledgeData = pData | ||
|
@@ -158,12 +157,11 @@ class CrowdfundCheckoutViewModel(val environment: Environment, bundle: Bundle? = | |
sharedPreferences | ||
) | ||
|
||
when (flowContext) { | ||
PledgeFlowContext.NEW_PLEDGE, | ||
PledgeFlowContext.CHANGE_REWARD -> getPledgeInfoFrom(pData) | ||
PledgeFlowContext.MANAGE_REWARD, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Manage_Reward" is used for both updating selected reward and changing reward, it describes the fact of having to present to the user RewardsCarousel not granular enough. |
||
PledgeFlowContext.FIX_ERRORED_PLEDGE | ||
-> { | ||
when (pledgeReason) { | ||
PledgeReason.PLEDGE, | ||
PledgeReason.UPDATE_REWARD -> getPledgeInfoFrom(pData) | ||
PledgeReason.UPDATE_PAYMENT, | ||
PledgeReason.FIX_PLEDGE -> { | ||
backing?.let { getPledgeInfoFrom(it) } | ||
} | ||
else -> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crash was due to using the reward and addOns from the backing object, where shipping locations information is not available