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: pricing fixes
Ammar Ahmed322f6b7aae8a
diff --git a/apps/mobile/app/components/premium/paywall.tsx b/apps/mobile/app/components/premium/paywall.tsxindex f2ceea066..53af33961 100644--- a/apps/mobile/app/components/premium/paywall.tsx+++ b/apps/mobile/app/components/premium/paywall.tsx@@ -1058,7 +1058,7 @@ const PricingPlanCard = ({</View></View>- {pricingPlans?.loading ? (+ {pricingPlans?.loadingPlans ? (<ActivityIndicator size="small" color={colors.primary.accent} />) : (<View>diff --git a/apps/mobile/app/components/sheets/buy-plan/index.tsx b/apps/mobile/app/components/sheets/buy-plan/index.tsxindex ce13df86b..a31c768ba 100644--- a/apps/mobile/app/components/sheets/buy-plan/index.tsx+++ b/apps/mobile/app/components/sheets/buy-plan/index.tsx@@ -179,7 +179,10 @@ export const BuyPlan = (props: {</Paragraph></View>- {pricingPlans.userCanRequestTrial ? (+ {pricingPlans.hasTrialOffer(+ props.planId,+ (pricingPlans.selectedProduct as RNIap.Product).productId+ ) ? (<Viewstyle={{flexDirection: "row",@@ -205,7 +208,13 @@ export const BuyPlan = (props: {</View>) : null}- {props.canActivateTrial ? (+ {pricingPlans.hasTrialOffer(+ props.planId,+ (pricingPlans.selectedProduct as RNIap.Product).productId+ ) ||+ (pricingPlans.selectedProduct as RNIap.Product).productId.includes(+ "5"+ ) ? (<Viewstyle={{gap: DefaultAppStyles.GAP_VERTICAL,diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsxindex 2aed3cdce..055a7b471 100644--- a/apps/mobile/app/hooks/use-app-events.tsx+++ b/apps/mobile/app/hooks/use-app-events.tsx@@ -232,6 +232,12 @@ const onUserSubscriptionStatusChanged = async (subscription.plan != SubscriptionPlan.FREE)) {PremiumService.subscriptions.clear();+ useUserStore.setState({+ user: {+ ...(useUserStore.getState().user as User),+ subscription: subscription+ }+ });Walkthrough.present("prouser", false, true);}await PremiumService.setPremiumStatus();@@ -319,6 +325,7 @@ async function saveEditorState() {const onSuccessfulSubscription = async (subscription: RNIap.ProductPurchase | RNIap.SubscriptionPurchase) => {+ if (Platform.OS === "android") return;await PremiumService.subscriptions.set(subscription);await PremiumService.subscriptions.verify(subscription);};diff --git a/apps/mobile/app/hooks/use-pricing-plans.ts b/apps/mobile/app/hooks/use-pricing-plans.tsindex 944b7a2e8..87d711cb7 100644--- a/apps/mobile/app/hooks/use-pricing-plans.ts+++ b/apps/mobile/app/hooks/use-pricing-plans.ts@@ -188,13 +188,15 @@ const usePricingPlans = (options?: PricingPlansOptions) => {const hasTrialOffer = (planId?: string, productId?: string) => {if (!selectedProductSku && !productId) return false;+ if (productId?.includes("5year")) return false;+return Platform.OS === "ios"- ? !!(+ ? (getProduct(planId || currentPlan,productId || selectedProductSku) as RNIap.SubscriptionIOS- )?.introductoryPrice+ )?.introductoryPricePaymentModeIOS === "FREETRIAL": (getProduct(planId || currentPlan,@@ -260,7 +262,6 @@ const usePricingPlans = (options?: PricingPlansOptions) => {}}};-loadPlans().then(() => loadPromoOffer());}, [options?.promoOffer, cancelPromo]);@@ -304,7 +305,7 @@ const usePricingPlans = (options?: PricingPlansOptions) => {}async function subscribe(- product: RNIap.Subscription,+ product: RNIap.Subscription | RNIap.Product,androidOfferToken?: string) {if (loading || !product || isGithubRelease) return;@@ -352,6 +353,12 @@ const usePricingPlans = (options?: PricingPlansOptions) => {]: undefined});+ if (+ (product as RNIap.SubscriptionIOS).introductoryPricePaymentModeIOS ===+ "FREETRIAL"+ ) {+ PremiumService.subscriptions.setTrialStatus(true);+ }} else {await RNIap.requestPurchase({andDangerouslyFinishTransactionAutomaticallyIOS: false,diff --git a/apps/mobile/app/screens/settings/app-lock.js b/apps/mobile/app/screens/settings/app-lock.jsdeleted file mode 100644index 77c2a5eaa..000000000--- a/apps/mobile/app/screens/settings/app-lock.js+++ /dev/null@@ -1,210 +0,0 @@-/*-This file is part of the Notesnook project (https://notesnook.com/)--Copyright (C) 2023 Streetwriters (Private) Limited--This program is free software: you can redistribute it and/or modify-it under the terms of the GNU General Public License as published by-the Free Software Foundation, either version 3 of the License, or-(at your option) any later version.--This program is distributed in the hope that it will be useful,-but WITHOUT ANY WARRANTY; without even the implied warranty of-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-GNU General Public License for more details.--You should have received a copy of the GNU General Public License-along with this program. If not, see <http://www.gnu.org/licenses/>.-*/--import { useThemeColors } from "@notesnook/theme";-import React from "react";-import { Platform, ScrollView, View } from "react-native";-import Animated from "react-native-reanimated";-import Icon from "react-native-vector-icons/MaterialCommunityIcons";-import { Pressable } from "../../components/ui/pressable";-import Seperator from "../../components/ui/seperator";-import Heading from "../../components/ui/typography/heading";-import Paragraph from "../../components/ui/typography/paragraph";-import BiometricService from "../../services/biometrics";-import { ToastManager, presentSheet } from "../../services/event-manager";-import SettingsService from "../../services/settings";-import { useSettingStore } from "../../stores/use-setting-store";-import { useUserStore } from "../../stores/use-user-store";-import { AppFontSize } from "../../utils/size";-import { strings } from "@notesnook/intl";-import { DefaultAppStyles } from "../../utils/styles";-const AppLock = () => {- const { colors } = useThemeColors();- const appLockMode = useSettingStore((state) => state.settings.appLockMode);-- const modes = [- {- title: "No privacy",- value: "none",- desc: "Your notes are always unlocked. Anyone who has access to your phone can read them.",- activeColor: colors.error.paragraph,- activeType: "error"- },- {- title: "Medium privacy",- value: "launch",- desc: "Your notes are locked when you exit the app but remain unlocked when you switch to other apps or background.",- activeColor: colors.primary.accent- },- {- title: "Maximum privacy (Recommended)",- value: "background",- desc: `Your notes are locked immediately when you switch to other apps or background. ${- Platform.OS === "ios"- ? "App contents are hidden in app switcher"- : "Screenshots are disabled and app contents are hidden in app switcher."- }`,- activeColor: colors.primary.accent- }- ];-- return (- <>- <Animated.View>- <>- <View- style={{- flexDirection: "row",- alignItems: "flex-end",- justifyContent: "space-between",- width: "95%",- paddingVertical: DefaultAppStyles.GAP_VERTICAL,- paddingHorizontal: 0,- alignSelf: "center",- minHeight: 125,- borderBottomWidth: 1,- borderBottomColor: colors.primary.border- }}- >- <Icon- name="shield-lock"- color={colors.secondary.icon}- size={100}- style={{- position: "absolute",- right: 0,- top: 6,- opacity: 0.2- }}- />-- <View- style={{- width: "100%"- }}- >- <Heading>{strings.protectNotes()}</Heading>- <Paragraph size={AppFontSize.md}>- {strings.protectNotesDesc()}- </Paragraph>- </View>- </View>-- <Seperator />- <ScrollView- style={{- paddingHorizontal: DefaultAppStyles.GAP,- width: "100%",- alignSelf: "center",- flexGrow: 1- }}- >- {modes.map((item) => (- <Pressable- key={item.title}- type={appLockMode === item.value ? "secondary" : "transparent"}- onPress={async () => {- if (- !(await BiometricService.isBiometryAvailable()) &&- !useUserStore.getState().user &&- item.value !== modes[0].value &&- !SettingsService.getProperty("appLockHasPasswordSecurity")- ) {- ToastManager.show({- heading: "Biometrics not enrolled",- type: "error",- message:- "To use app lock, you must enable biometrics such as Fingerprint lock or Face ID on your phone or create an account."- });- return;- }-- if (- !SettingsService.getProperty(- "appLockHasPasswordSecurity"- ) &&- item.value !== modes[0].value- ) {- const verified = await BiometricService.validateUser(- "Verify it's you"- );- if (verified) {- SettingsService.setProperty(- "biometricsAuthEnabled",- true- );- } else {- return;- }- }-- SettingsService.set({ appLockMode: item.value });- }}- style={{- justifyContent: "flex-start",- alignItems: "flex-start",- paddingHorizontal: DefaultAppStyles.GAP,- paddingVertical: DefaultAppStyles.GAP_VERTICAL,- marginTop: 0,- marginBottom: DefaultAppStyles.GAP_VERTICAL,- borderWidth: 1,- borderColor:- appLockMode === item.value- ? item.activeColor- : colors.secondary.background- }}- >- <Heading- color={- appLockMode === item.value- ? item.activeColor- : colors.primary.heading- }- style={{ maxWidth: "95%" }}- size={AppFontSize.md}- >- {item.title}- </Heading>- <Paragraph- color={- appLockMode === item.value- ? item.activeColor- : colors.secondary.paragraph- }- style={{ maxWidth: "95%" }}- size={AppFontSize.sm}- >- {item.desc}- </Paragraph>- </Pressable>- ))}- </ScrollView>- </>- </Animated.View>- </>- );-};--AppLock.present = async () => {- presentSheet({- component: <AppLock />- });-};--export default AppLock;diff --git a/apps/mobile/app/screens/settings/appearance.js b/apps/mobile/app/screens/settings/appearance.jsdeleted file mode 100644index f4349db56..000000000--- a/apps/mobile/app/screens/settings/appearance.js+++ /dev/null@@ -1,108 +0,0 @@-/*-This file is part of the Notesnook project (https://notesnook.com/)--Copyright (C) 2023 Streetwriters (Private) Limited--This program is free software: you can redistribute it and/or modify-it under the terms of the GNU General Public License as published by-the Free Software Foundation, either version 3 of the License, or-(at your option) any later version.--This program is distributed in the hope that it will be useful,-but WITHOUT ANY WARRANTY; without even the implied warranty of-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-GNU General Public License for more details.--You should have received a copy of the GNU General Public License-along with this program. If not, see <http://www.gnu.org/licenses/>.-*/--import React from "react";-import { View } from "react-native";-import Icon from "react-native-vector-icons/MaterialCommunityIcons";-import { Pressable } from "../../components/ui/pressable";-import { DDS } from "../../services/device-detection";-import PremiumService from "../../services/premium";-import SettingsService from "../../services/settings";-import { useThemeColors } from "@notesnook/theme";-import {- RGB_Linear_Shade,- hexToRGBA,- switchAccentColor-} from "../../utils/colors";-import { AppFontSize } from "../../utils/size";--export const AccentColorPicker = () => {- const { colors, isDark } = useThemeColors();- function changeAccentColor(color) {- switchAccentColor(color);- }-- return (- <View- style={{- flexDirection: "row",- flexWrap: "wrap",- alignItems: "center",- width: "100%"- }}- >- {[- "#FF5722",- "#FFA000",- "#1B5E20",- "#008837",- "#757575",- "#0560ff",- "#009688",- "#2196F3",- "#880E4F",- "#9C27B0",- "#FF1744",- "#B71C1C"- ].map((item) => (- <Pressable- key={item}- customColor={- colors.primary.accent === item- ? RGB_Linear_Shade(!isDark ? -0.2 : 0.2, hexToRGBA(item, 1))- : item- }- customSelectedColor={item}- alpha={!isDark ? -0.1 : 0.1}- opacity={1}- onPress={async () => {- await PremiumService.verify(async () => {- changeAccentColor(item);- SettingsService.set({- theme: {- accent: item,- dark: SettingsService.get().theme.dark- }- });- });- }}- style={{- flexDirection: "row",- justifyContent: "center",- alignItems: "center",- marginRight: 10,- marginVertical: 5,- width: DDS.isLargeTablet() ? 40 : 50,- height: DDS.isLargeTablet() ? 40 : 50,- borderRadius: 100- }}- >- {colors.primary.accent === item ? (- <Icon- size={DDS.isLargeTablet() ? AppFontSize.lg : AppFontSize.xxl}- color="white"- name="check"- />- ) : null}- </Pressable>- ))}- <View style={{ width: 50 }} />- </View>- );-};diff --git a/apps/mobile/app/screens/settings/components.tsx b/apps/mobile/app/screens/settings/components.tsxindex 486f085fb..81e04d5e7 100644--- a/apps/mobile/app/screens/settings/components.tsx+++ b/apps/mobile/app/screens/settings/components.tsx@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import React, { ReactElement } from "react";import { AttachmentDialog } from "../../components/attachments";-import { AccentColorPicker } from "./appearance";import DebugLogs from "./debug";import { ConfigureToolbar } from "./editor/configure-toolbar";import { Licenses } from "./licenses";@@ -47,7 +46,6 @@ import { ChangePassword } from "../../components/auth/change-password";import { ChangeEmail } from "./change-email";export const components: { [name: string]: ReactElement } = {- colorpicker: <AccentColorPicker />,homeselector: <HomePicker />,autobackups: <BackupReminderPicker />,subscription: <Subscription />,diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsxindex 61ddf04d5..df38c15ec 100644--- a/apps/mobile/app/screens/settings/settings-data.tsx+++ b/apps/mobile/app/screens/settings/settings-data.tsx@@ -483,11 +483,9 @@ export const settingsGroups: SettingSection[] = [db.fs().cancel("offline-mode");return;}- PremiumService.verify(() => {- SettingsService.setProperty("offlineMode", true);- db.attachments.cacheAttachments().catch(() => {- /* empty */- });+ SettingsService.setProperty("offlineMode", true);+ db.attachments.cacheAttachments().catch(() => {+ /* empty */});}},@@ -821,12 +819,10 @@ export const settingsGroups: SettingSection[] = [useHook: useVaultStatus,hidden: (current) => (current as VaultStatusType)?.exists,modifer: () => {- PremiumService.verify(() => {- openVault({- item: {},- novault: false,- title: strings.createVault()- });+ openVault({+ item: {},+ novault: false,+ title: strings.createVault()});}},diff --git a/apps/mobile/app/services/premium.js b/apps/mobile/app/services/premium.tssimilarity index 78%rename from apps/mobile/app/services/premium.jsrename to apps/mobile/app/services/premium.tsindex 60c89fadf..ab623e564 100644--- a/apps/mobile/app/services/premium.js+++ b/apps/mobile/app/services/premium.ts@@ -17,38 +17,29 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { CHECK_IDS, SubscriptionPlan } from "@notesnook/core";+import {+ SubscriptionPlan,+ SubscriptionStatus,+ SubscriptionType+} from "@notesnook/core";import { Platform } from "react-native";import Config from "react-native-config";import * as RNIap from "react-native-iap";import { db } from "../common/database";import { MMKV } from "../common/database/mmkv";import { useUserStore } from "../stores/use-user-store";-import { itemSkus, SUBSCRIPTION_STATUS } from "../utils/constants";-import { eOpenPremiumDialog, eShowGetPremium } from "../utils/events";-import { eSendEvent, presentSheet, ToastManager } from "./event-manager";-+import { itemSkus } from "../utils/constants";+import { presentSheet, ToastManager } from "./event-manager";import { strings } from "@notesnook/intl";import SettingsService from "./settings";-/**- * @type {RNIap.Subscription[]}- */-let subs = [];-/**- * @type {RNIap.Product[]}- */-let products = [];-let user = null;--function getUser() {- return user;-}+let subs: RNIap.Subscription[] = [];+let products: RNIap.Product[] = [];async function setPremiumStatus() {let userstore = useUserStore.getState();try {- user = await db.user.getUser();+ const user = await db.user.getUser();if (!user) {userstore.setPremium(get());} else {@@ -69,19 +60,6 @@ async function setPremiumStatus() {} catch (e) {}}-function getMontlySub() {- let _product = subs.find(- (p) => p.productId === "com.streetwriters.notesnook.sub.mo"- );- if (!_product) {- _product = {- localizedPrice: "$4.49"- };- }-- return _product;-}-async function loadProductsAndSubs() {try {if (!subs || subs.length === 0) {@@ -112,6 +90,14 @@ async function loadProductsAndSubs() {function get() {// if (__DEV__ || Config.isTesting === "true") return true;+ if (+ SubscriptionType.BASIC !==+ useUserStore.getState().user?.subscription.type &&+ (!useUserStore.getState().user?.subscription?.plan ||+ useUserStore.getState().user?.subscription?.plan ===+ SubscriptionPlan.FREE)+ )+ return true;return (useUserStore.getState().user?.subscription?.plan !== undefined &&@@ -119,23 +105,6 @@ function get() {);}-async function verify(callback, error) {- try {- if (!get()) {- if (error) {- error();- return;- }- eSendEvent(eOpenPremiumDialog);- return;- }- if (!callback) console.warn("You must provide a callback function");- await callback();- } catch (e) {- console.error(e);- }-}-const showVerifyEmailDialog = () => {presentSheet({title: strings.confirmEmail(),@@ -170,7 +139,7 @@ const showVerifyEmailDialog = () => {} catch (e) {ToastManager.show({heading: strings.failedToSendVerificationEmail(),- message: e.message,+ message: (e as Error).message,type: "error",context: "local"});@@ -181,6 +150,10 @@ const showVerifyEmailDialog = () => {};const subscriptions = {+ trialStatus: false,+ setTrialStatus: (status: boolean) => {+ subscriptions.trialStatus = status;+ },/**** @returns {RNIap.Purchase} subscription@@ -189,21 +162,23 @@ const subscriptions = {if (Platform.OS === "android") return;let _subscriptions = MMKV.getString("subscriptionsIOS");if (!_subscriptions) return [];- return JSON.parse(_subscriptions);+ return JSON.parse(_subscriptions) as (+ | RNIap.SubscriptionPurchase+ | RNIap.ProductPurchase+ )[];},/**** @param {RNIap.Purchase} subscription* @returns*/- set: async (subscription) => {+ set: async (+ subscription: RNIap.SubscriptionPurchase | RNIap.ProductPurchase+ ) => {if (Platform.OS === "android") return;- let _subscriptions = MMKV.getString("subscriptionsIOS");- if (_subscriptions) {- _subscriptions = JSON.parse(_subscriptions);- } else {- _subscriptions = [];- }+ const _subscriptions = subscriptions.get();+ if (!_subscriptions) return;+let index = _subscriptions.findIndex((s) => s.transactionId === subscription.transactionId);@@ -214,14 +189,11 @@ const subscriptions = {}MMKV.setString("subscriptionsIOS", JSON.stringify(_subscriptions));},- remove: async (transactionId) => {+ remove: async (transactionId: string) => {if (Platform.OS === "android") return;- let _subscriptions = MMKV.getString("subscriptionsIOS");- if (_subscriptions) {- _subscriptions = JSON.parse(_subscriptions);- } else {- _subscriptions = [];- }+ const _subscriptions = subscriptions.get();+ if (!_subscriptions) return;+let index = _subscriptions.findIndex((s) => s.transactionId === transactionId);@@ -234,7 +206,9 @@ const subscriptions = {** @param {RNIap.Purchase} subscription*/- verify: async (subscription) => {+ verify: async (+ subscription: RNIap.SubscriptionPurchase | RNIap.ProductPurchase+ ) => {if (Platform.OS === "android") return;if (subscription.transactionReceipt) {@@ -245,6 +219,7 @@ const subscriptions = {method: "POST",body: JSON.stringify({receipt_data: subscription.transactionReceipt,+ trial_status: subscriptions.trialStatus,user_id: user.id}),headers: {@@ -276,9 +251,12 @@ const subscriptions = {}}},- clear: async (_subscription) => {+ clear: async (+ _subscription?: RNIap.SubscriptionPurchase | RNIap.ProductPurchase+ ) => {if (Platform.OS === "android") return;let _subscriptions = subscriptions.get();+ if (!_subscriptions) return;let subscription = null;if (_subscription) {subscription = _subscription;@@ -291,20 +269,17 @@ const subscriptions = {purchase: subscription});await RNIap.clearTransactionIOS();- await subscriptions.remove(subscription.transactionId);+ await subscriptions.remove(subscription.transactionId as string);}}};const PremiumService = {- verify,setPremiumStatus,get,showVerifyEmailDialog,loadProductsAndSubs: loadProductsAndSubs,- getUser,- subscriptions,- getMontlySub+ subscriptions};export default PremiumService;