Skip to content

Commit ca9d455

Browse files
Tweak some assertions per review #2643
1 parent fae3d49 commit ca9d455

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Library/ViewModels/RewardsCollectionViewModel.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,31 @@ private func rewardShipsTo(
602602
}
603603

604604
private func shippingRule(forReward reward: Reward, selectedLocation location: Location?) -> ShippingRule? {
605+
guard let selectedLocation = location else {
606+
return nil
607+
}
608+
609+
// Whether or not this is a "shippable" reward.
610+
// "No Reward", digital rewards and local pickup rewards are not shippable.
611+
let hasShipping = reward.isRestrictedShippingPreference || reward.isUnRestrictedShippingPreference
612+
605613
guard let rules = reward.shippingRulesExpanded else {
606-
let hasShipping = reward.isRestrictedShippingPreference || reward.isUnRestrictedShippingPreference
607614
assert(
608615
!hasShipping,
609-
"This reward is shippable, but no shipping rules were set. The backer may not be charged correctly for shipping."
616+
"This reward is shippable, but no shipping rules were included on the reward. The backer may not be able to complete this pledge."
617+
)
618+
619+
return nil
620+
}
621+
622+
guard let rule = rules.first(where: { $0.location.id == selectedLocation.id }) else {
623+
assert(
624+
!hasShipping,
625+
"This reward is shippable, but no shipping rule matched the selected location. The backer may not be able to complete this pledge."
610626
)
611627

612628
return nil
613629
}
614630

615-
return rules.first(where: { $0.location.id == location?.id })
631+
return rule
616632
}

0 commit comments

Comments
 (0)