Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix crash

Ammar Ahmed3b0dce6c6fd9
diff --git a/apps/mobile/app/components/paywall/index.tsx b/apps/mobile/app/components/paywall/index.tsx
index 61c6143f8..1b4dab2c8 100644
--- a/apps/mobile/app/components/paywall/index.tsx
+++ b/apps/mobile/app/components/paywall/index.tsx
@@ -74,6 +74,7 @@ import { IconButton } from "../ui/icon-button";
import { SvgView } from "../ui/svg";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
+import PremiumService from "../../services/premium";
const Steps = {
select: 1,
@@ -334,7 +335,7 @@ const PayWall = (props: NavigationProps<"PayWall">) => {
(
pricingPlans.selectedProduct as RNIap.Subscription
)?.productId ||
- (pricingPlans.selectedProduct as Plan).period,
+ (pricingPlans.selectedProduct as Plan)?.period,
billingType: annualBilling ? "annual" : "monthly"
}
});
@@ -978,17 +979,21 @@ const PricingPlanCard = ({
pricingPlans?.user?.subscription?.productId?.includes(plan.id) &&
pricingPlans.isSubscribed();
+ const isNotReady =
+ pricingPlans?.loadingPlans || (!price && !WebPlan?.price.gross);
+
return (
<TouchableOpacity
activeOpacity={0.8}
onPress={() => {
+ if (isNotReady) return;
const currentPlanSubscribed =
- pricingPlans?.user?.subscription?.productId ===
+ PremiumService.get() &&
+ (pricingPlans?.user?.subscription?.productId ===
(product as RNIap.Subscription)?.productId ||
- pricingPlans?.user?.subscription?.productId.startsWith(
- (product as RNIap.Subscription)?.productId
- );
-
+ pricingPlans?.user?.subscription?.productId.startsWith(
+ (product as RNIap.Subscription)?.productId
+ ));
pricingPlans?.selectPlan(
plan.id,
currentPlanSubscribed
diff --git a/apps/mobile/app/hooks/use-pricing-plans.ts b/apps/mobile/app/hooks/use-pricing-plans.ts
index dc0e8b4d5..fc9d31d39 100644
--- a/apps/mobile/app/hooks/use-pricing-plans.ts
+++ b/apps/mobile/app/hooks/use-pricing-plans.ts
@@ -255,35 +255,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {
}
setLoadingPlans(false);
};
-
- const loadPromoOffer = async () => {
- if (cancelPromo) {
- setIsPromoOffer(false);
- return;
- }
- if (options?.promoOffer?.promoCode) {
- const promoCode = options.promoOffer.promoCode;
- let skuId: string;
- if (promoCode.startsWith("com.streetwriters.notesnook")) {
- skuId = promoCode;
- } else {
- skuId = await db.offers?.getCode(
- promoCode.split(":")[0],
- Platform.OS as "ios" | "android" | "web"
- );
- }
-
- const plan = pricingPlans.find((p) =>
- p.subscriptionSkuList.includes(skuId)
- );
- if (plan) {
- setCurrentPlan(plan.id);
- setSelectedProductSku(skuId);
- setIsPromoOffer(true);
- }
- }
- };
- loadPlans().then(() => loadPromoOffer());
+ loadPlans();
}, [options?.promoOffer, cancelPromo]);
function getLocalizedPrice(