A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: hide pricing flows on self hosted clients
Ammar Ahmeddae8b5c54249
diff --git a/apps/mobile/app/components/auth/login.js b/apps/mobile/app/components/auth/login.jsindex b3367cf30..86816d098 100644--- a/apps/mobile/app/components/auth/login.js+++ b/apps/mobile/app/components/auth/login.js@@ -19,14 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { strings } from "@notesnook/intl";import { useThemeColors } from "@notesnook/theme";+import { useRoute } from "@react-navigation/native";import React, { useEffect, useState } from "react";-import {- ScrollView,- TouchableOpacity,- View,- useWindowDimensions-} from "react-native";+import { TouchableOpacity, View, useWindowDimensions } from "react-native";import { SheetManager } from "react-native-actions-sheet";+import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";import { DDS } from "../../services/device-detection";import { eSendEvent } from "../../services/event-manager";import Navigation from "../../services/navigation";@@ -47,8 +44,7 @@ import { hideAuth } from "./common";import { ForgotPassword } from "./forgot-password";import { AuthHeader } from "./header";import { useLogin } from "./use-login";-import { useRoute } from "@react-navigation/native";-import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";+import SettingsService from "../../services/settings";const LoginSteps = {emailAuth: 1,@@ -81,7 +77,7 @@ export const Login = ({ changeMode }) => {}}, 5000);- if (!PremiumService.get()) {+ if (!PremiumService.get() && !SettingsService.getProperty("serverUrls")) {Navigation.navigate("PayWall", {context: "signup",state: route.params.state,diff --git a/apps/mobile/app/components/auth/signup.js b/apps/mobile/app/components/auth/signup.jsindex efbe730f3..a862c375b 100644--- a/apps/mobile/app/components/auth/signup.js+++ b/apps/mobile/app/components/auth/signup.js@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { strings } from "@notesnook/intl";import { useThemeColors } from "@notesnook/theme";+import { useRoute } from "@react-navigation/native";import React, { useRef, useState } from "react";import { TouchableOpacity, View, useWindowDimensions } from "react-native";import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";@@ -38,7 +39,6 @@ import Heading from "../ui/typography/heading";import Paragraph from "../ui/typography/paragraph";import { AuthHeader } from "./header";import { SignupContext } from "./signup-context";-import { useRoute } from "@react-navigation/native";const SignupSteps = {signup: 0,@@ -91,11 +91,13 @@ export const Signup = ({ changeMode, welcome }) => {setLastSynced(await db.lastSynced());clearMessage();setEmailVerifyMessage();- Navigation.navigate("PayWall", {- canGoBack: false,- state: route.params.state,- context: "signup"- });+ if (!SettingsService.getProperty("serverUrls")) {+ Navigation.navigate("PayWall", {+ canGoBack: false,+ state: route.params.state,+ context: "signup"+ });+ }return true;} catch (e) {setCurrentStep(SignupSteps.signup);diff --git a/apps/mobile/app/components/paywall/index.tsx b/apps/mobile/app/components/paywall/index.tsxindex 1b4dab2c8..7ae559af7 100644--- a/apps/mobile/app/components/paywall/index.tsx+++ b/apps/mobile/app/components/paywall/index.tsx@@ -60,6 +60,7 @@ import usePricingPlans, {PricingPlan} from "../../hooks/use-pricing-plans";import Navigation, { NavigationProps } from "../../services/navigation";+import PremiumService from "../../services/premium";import { getElevationStyle } from "../../utils/elevation";import { openLinkInBrowser } from "../../utils/functions";import { AppFontSize, defaultBorderRadius } from "../../utils/size";@@ -74,7 +75,6 @@ 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,@@ -114,15 +114,8 @@ const PayWall = (props: NavigationProps<"PayWall">) => {routeParams.state?.planId,routeParams.state?.productId);- console.log(- "selectPlan",- routeParams.state?.planId,- routeParams.state?.productId,- (pricingPlans.selectedProduct as any).productId- );}setStep(Steps.buy);- console.log("Buy step");}}, [routeParams.state]);@@ -949,7 +942,6 @@ const PricingPlanCard = ({regionalDiscount?.sku ||`notesnook.${plan.id}.${annualBilling ? "yearly" : "monthly"}`];- console.log(regionalDiscount?.sku);const price = pricingPlans?.getPrice(product as RNIap.Subscription,pricingPlans.hasTrialOffer(plan.id, product?.productId) ? 1 : 0,@@ -962,6 +954,7 @@ const PricingPlanCard = ({);useEffect(() => {+ if (pricingPlans?.isGithubRelease) return;pricingPlans?.getRegionalDiscount(plan.id,@@ -980,7 +973,7 @@ const PricingPlanCard = ({pricingPlans.isSubscribed();const isNotReady =- pricingPlans?.loadingPlans || (!price && !WebPlan?.price.gross);+ pricingPlans?.loadingPlans || (!price && !WebPlan?.price?.gross);return (<TouchableOpacity@@ -1112,7 +1105,7 @@ const PricingPlanCard = ({</View></View>- {pricingPlans?.loadingPlans || (!price && !WebPlan?.price.gross) ? (+ {pricingPlans?.loadingPlans || (!price && !WebPlan?.price?.gross) ? (<ActivityIndicator size="small" color={colors.primary.accent} />) : (<View>@@ -1120,7 +1113,7 @@ const PricingPlanCard = ({{isFreePlan? "0.00": price ||- `${WebPlan?.price.currency} ${WebPlan?.price.gross}`}{" "}+ `${WebPlan?.price?.currency} ${WebPlan?.price?.gross}`}{" "}<Paragraph>/{strings.month()}</Paragraph></Paragraph>diff --git a/apps/mobile/app/components/sheets/paywall/index.tsx b/apps/mobile/app/components/sheets/paywall/index.tsxindex 8d043fd85..d279477cf 100644--- a/apps/mobile/app/components/sheets/paywall/index.tsx+++ b/apps/mobile/app/components/sheets/paywall/index.tsx@@ -24,6 +24,7 @@ import AppIcon from "../../ui/AppIcon";import { Button } from "../../ui/button";import Heading from "../../ui/typography/heading";import Paragraph from "../../ui/typography/paragraph";+import SettingsService from "../../../services/settings";const isGithubRelease = Config.GITHUB_RELEASE === "true";const INDEX_TO_PLAN = {1: "essential",@@ -55,11 +56,11 @@ export default function PaywallSheet<Tid extends FeatureId>(props: {}, []);const isSubscribedOnWeb =- (PremiumService.get() &&+ PremiumService.get() &&+ (pricingPlans.user?.subscription?.provider ===+ SubscriptionProvider.PADDLE ||pricingPlans.user?.subscription?.provider ===- SubscriptionProvider.PADDLE) ||- pricingPlans.user?.subscription?.provider ===- SubscriptionProvider.STREETWRITERS;+ SubscriptionProvider.STREETWRITERS);const isCurrentPlatform =(pricingPlans.user?.subscription?.provider === SubscriptionProvider.APPLE &&@@ -194,25 +195,28 @@ export default function PaywallSheet<Tid extends FeatureId>(props: {width: "100%"}}onPress={() => {- if (- pricingPlans.user?.subscription.plan ===- SubscriptionPlan.LEGACY_PRO ||- !isCurrentPlatform- ) {- ToastManager.show({- message: strings.cannotChangePlan(),- context: "local"- });- return;- }+ if (PremiumService.get()) {+ if (+ pricingPlans.user?.subscription.plan ===+ SubscriptionPlan.LEGACY_PRO ||+ !isCurrentPlatform+ ) {+ ToastManager.show({+ message: strings.cannotChangePlan(),+ context: "local"+ });+ return;+ }- if (isSubscribedOnWeb) {- ToastManager.show({- message: strings.changePlanOnWeb(),- context: "local"- });- return;+ if (isSubscribedOnWeb) {+ ToastManager.show({+ message: strings.changePlanOnWeb(),+ context: "local"+ });+ return;+ }}+eSendEvent(eCloseSheet);if (!useUserStore.getState().user) {Navigation.navigate("Auth", {@@ -256,6 +260,7 @@ export default function PaywallSheet<Tid extends FeatureId>(props: {}PaywallSheet.present = <Tid extends FeatureId>(feature: FeatureResult<Tid>) => {+ if (SettingsService.getProperty("serverUrls")) return;presentSheet({component: <PaywallSheet feature={feature} />});diff --git a/apps/mobile/app/components/sheets/plan-limits/index.tsx b/apps/mobile/app/components/sheets/plan-limits/index.tsxindex 68ec57bcc..b7f50a9ea 100644--- a/apps/mobile/app/components/sheets/plan-limits/index.tsx+++ b/apps/mobile/app/components/sheets/plan-limits/index.tsx@@ -20,6 +20,7 @@ import Paragraph from "../../ui/typography/paragraph";import { SubscriptionPlan, SubscriptionProvider } from "@notesnook/core";import { useUserStore } from "../../../stores/use-user-store";import PremiumService from "../../../services/premium";+import SettingsService from "../../../services/settings";export function PlanLimits() {const { colors } = useThemeColors();@@ -84,10 +85,11 @@ export function PlanLimits() {</View>))}- {(user?.subscription?.provider === SubscriptionProvider.PADDLE ||+ {((user?.subscription?.provider === SubscriptionProvider.PADDLE ||user?.subscription?.provider === SubscriptionProvider.STREETWRITERS ||!isCurrentPlatform) &&- PremiumService.get() ? null : (+ PremiumService.get()) ||+ SettingsService.getProperty("serverUrls") ? null : (<Buttontitle={strings.changePlan()}onPress={() => {diff --git a/apps/mobile/app/components/side-menu/side-menu-home.tsx b/apps/mobile/app/components/side-menu/side-menu-home.tsxindex 894cbbd4c..cde5ac6e9 100644--- a/apps/mobile/app/components/side-menu/side-menu-home.tsx+++ b/apps/mobile/app/components/side-menu/side-menu-home.tsx@@ -24,10 +24,11 @@ import { FlatList, View } from "react-native";import { DraxProvider, DraxScrollView } from "react-native-drax";import { db } from "../../common/database";import Navigation from "../../services/navigation";+import SettingsService from "../../services/settings";import { useMenuStore } from "../../stores/use-menu-store";import { useSettingStore } from "../../stores/use-setting-store";import { useUserStore } from "../../stores/use-user-store";-import { SUBSCRIPTION_STATUS } from "../../utils/constants";+import { MenuItemsList } from "../../utils/menu-items";import { DefaultAppStyles } from "../../utils/styles";import ReorderableList from "../list/reorderable-list";import { MenuItemProperties } from "../sheets/menu-item-properties";@@ -36,7 +37,6 @@ import { ColorSection } from "./color-section";import { MenuItem } from "./menu-item";import { PinnedSection } from "./pinned-section";import { SideMenuHeader } from "./side-menu-header";-import { MenuItemsList } from "../../utils/menu-items";const pro = {title: strings.upgradePlan(),@@ -140,9 +140,10 @@ export function SideMenuHome() {paddingVertical: DefaultAppStyles.GAP_VERTICAL}}>- {subscriptionType === SubscriptionPlan.FREE ||- !subscriptionType ||- !user ? (+ {(subscriptionType === SubscriptionPlan.FREE ||+ !subscriptionType ||+ !user) &&+ !SettingsService.getProperty("serverUrls") ? (<Buttontitle={pro.title}style={{diff --git a/apps/mobile/app/hooks/use-feature-manager.ts b/apps/mobile/app/hooks/use-feature-manager.tsindex b06c3d665..ed625760e 100644--- a/apps/mobile/app/hooks/use-feature-manager.ts+++ b/apps/mobile/app/hooks/use-feature-manager.ts@@ -85,6 +85,7 @@ export default function useFeatureManager() {negativeText: strings.cancel(),positivePress: async () => {eSendEvent(eCloseSimpleDialog);+ if (SettingsService.getProperty("serverUrls")) return;Navigation.navigate("PayWall", {context: "logged-in"});diff --git a/apps/mobile/app/hooks/use-pricing-plans.ts b/apps/mobile/app/hooks/use-pricing-plans.tsindex fc9d31d39..f854bc93c 100644--- a/apps/mobile/app/hooks/use-pricing-plans.ts+++ b/apps/mobile/app/hooks/use-pricing-plans.ts@@ -25,6 +25,7 @@ import { DatabaseLogger, db } from "../common/database";import PremiumService from "../services/premium";import { useSettingStore } from "../stores/use-setting-store";import { useUserStore } from "../stores/use-user-store";+import SettingsService from "../services/settings";function numberWithCommas(x: string) {const parts = x.toString().split(".");parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");@@ -201,7 +202,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {if (productId?.includes("5year")) return false;if (isGithubRelease) {if (- user?.subscription.trialsAvailed?.some(+ user?.subscription?.trialsAvailed?.some((plan) => plan === planIdToIndex(planId || currentPlan))) {@@ -246,7 +247,10 @@ const usePricingPlans = (options?: PricingPlansOptions) => {});setPlans([...pricingPlans]);setUserCanRequestTrial(hasTrialOffer());- if (Config.GITHUB_RELEASE === "true") {+ if (+ Config.GITHUB_RELEASE === "true" &&+ !SettingsService.getProperty("serverUrls")+ ) {try {const products = WebPlanCache || (await db.pricing.products());WebPlanCache = products;@@ -264,7 +268,8 @@ const usePricingPlans = (options?: PricingPlansOptions) => {if (!product) return;if (Platform.OS === "android") {- if (isGithubRelease)+ if (isGithubRelease) {+ if (!(product as Plan)?.price) return null;return `${(product as Plan).price.currency} ${(product as Plan).period === "yearly"? ((product as Plan).price.gross / 12).toFixed(2)@@ -272,6 +277,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {? ((product as Plan).price.gross / (12 * 5)).toFixed(2): (product as Plan).price.gross}`;+ }const pricingPhaseListItem =(product as RNIap.SubscriptionAndroid)?.subscriptionOfferDetails?.[0]@@ -414,7 +420,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {offerIndex: number) => {if (isGithubRelease) {- return (product as Plan).period;+ return (product as Plan)?.period;}if (Platform.OS === "android") {@@ -444,7 +450,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {if (isGithubRelease) {return {duration: 1,- type: (product as Plan).period+ type: (product as Plan)?.period};}@@ -591,7 +597,8 @@ const usePricingPlans = (options?: PricingPlansOptions) => {) => {if (!product) return null;- if (isGithubRelease)+ if (isGithubRelease) {+ if (!(product as Plan)?.price) return null;return `${(product as Plan).price.currency} ${(product as Plan).period === "yearly"? ((product as Plan).price.gross / 12).toFixed(2)@@ -599,6 +606,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {? ((product as Plan).price.gross / (12 * 5)).toFixed(2): (product as Plan).price.gross}`;+ }const androidPricingPhase = (product as RNIap.SubscriptionAndroid)?.subscriptionOfferDetails?.[0].pricingPhases?.pricingPhaseList?.[diff --git a/apps/mobile/app/screens/settings/user-section.jsx b/apps/mobile/app/screens/settings/user-section.jsxindex 3857017e2..f399ce717 100644--- a/apps/mobile/app/screens/settings/user-section.jsx+++ b/apps/mobile/app/screens/settings/user-section.jsx@@ -43,6 +43,7 @@ import { planToDisplayName } from "../../utils/constants";import { AppFontSize } from "../../utils/size";import { DefaultAppStyles } from "../../utils/styles";import { SectionItem } from "./section-item";+import SettingsService from "../../services/settings";export const getTimeLeft = (t2) => {let daysRemaining = dayjs(t2).diff(dayjs(), "days");@@ -339,11 +340,13 @@ const SettingsUserSection = ({ item }) => {</Paragraph></TouchableOpacity>- {(user.subscription?.provider === SubscriptionProvider.PADDLE ||+ {((user.subscription?.provider ===+ SubscriptionProvider.PADDLE ||user.subscription?.provider ===SubscriptionProvider.STREETWRITERS ||!isCurrentPlatform) &&- PremiumService.get() ? null : (+ PremiumService.get()) ||+ SettingsService.getProperty("serverUrls") ? null : (<Buttontitle={user.subscription?.plan !== SubscriptionPlan.FREE