()
| 12 | }; |
| 13 | |
| 14 | export const usePlusSale = (): UsePlusSale => { |
| 15 | const { isAuthReady } = useAuthContext(); |
| 16 | const { isPlus } = usePlusSubscription(); |
| 17 | const { value, isLoading } = useConditionalFeature({ |
| 18 | feature: featurePlusSale, |
| 19 | shouldEvaluate: isAuthReady && !isPlus, |
| 20 | }); |
| 21 | const { discountId, label, endDate } = value; |
| 22 | |
| 23 | const hasNotEnded = !!endDate && Date.now() < new Date(endDate).getTime(); |
| 24 | const isActive = |
| 25 | !isLoading && |
| 26 | !!discountId && |
| 27 | // A payload configured without copy would advertise an empty badge. |
| 28 | !!label && |
| 29 | !isPlus && |
| 30 | hasNotEnded && |
| 31 | // StoreKit purchases go through Apple, which can't honour a Paddle discount. |
| 32 | !iOSSupportsPlusPurchase(); |
| 33 | |
| 34 | return { |
| 35 | ...value, |
| 36 | isActive, |
| 37 | discountId: isActive ? discountId : undefined, |
| 38 | }; |
| 39 | }; |
no test coverage detected