Skip to content

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

fix premium not working when subscription is cancelled

ammarahm-ed9d59f39f322d
diff --git a/apps/mobile/src/services/PremiumService.js b/apps/mobile/src/services/PremiumService.js
index 89cd945c7..f05b833c4 100644
--- a/apps/mobile/src/services/PremiumService.js
+++ b/apps/mobile/src/services/PremiumService.js
@@ -1,19 +1,19 @@
-import { CHECK_IDS } from 'notes-core/common';
+import {CHECK_IDS} from 'notes-core/common';
import * as RNIap from 'react-native-iap';
-import { useUserStore } from '../provider/stores';
-import { itemSkus } from '../utils';
-import { db } from '../utils/DB';
+import {useUserStore} from '../provider/stores';
+import {itemSkus, SUBSCRIPTION_STATUS} from '../utils';
+import {db} from '../utils/DB';
import {
eOpenPremiumDialog,
eOpenProgressDialog,
- eShowGetPremium
+ eShowGetPremium,
} from '../utils/Events';
-import { MMKV } from '../utils/mmkv';
-import { eSendEvent, ToastEvent } from './EventManager';
+import {MMKV} from '../utils/mmkv';
+import {eSendEvent, ToastEvent} from './EventManager';
let premiumStatus = 0;
let products = [];
-let user = null
+let user = null;
function getUser() {
return user;
@@ -25,10 +25,10 @@ async function setPremiumStatus() {
user = await db.user.getUser();
if (!user) {
premiumStatus = null;
- userstore.setPremium(get())
+ userstore.setPremium(get());
} else {
premiumStatus = user.subscription.type;
- userstore.setPremium(get())
+ userstore.setPremium(get());
userstore.setUser(user);
}
} catch (e) {
@@ -46,17 +46,10 @@ function getProducts() {
}
function get() {
-
- return (
- premiumStatus === 1 ||
- premiumStatus === 2 ||
- premiumStatus === 5 ||
- premiumStatus === 6
- );
+ return SUBSCRIPTION_STATUS.BASIC !== premiumStatus;
}
async function verify(callback, error) {
-
try {
if (!premiumStatus) {
if (error) {
@@ -65,16 +58,13 @@ async function verify(callback, error) {
}
eSendEvent(eOpenPremiumDialog);
return;
- } else {
- if (!callback) console.warn('You must provide a callback function');
- await callback();
}
- } catch (e) {
- // show error dialog TODO
- }
+ if (!callback) console.warn('You must provide a callback function');
+ await callback();
+ } catch (e) {}
}
-const onUserStatusCheck = async (type) => {
+const onUserStatusCheck = async type => {
let status = get();
let message = null;
@@ -135,8 +125,8 @@ const showVerifyEmailDialog = () => {
try {
let lastEmailTime = await MMKV.getItem('lastEmailTime');
if (
- lastEmailTime
- && Date.now() - JSON.parse(lastEmailTime) < 60000 * 2
+ lastEmailTime &&
+ Date.now() - JSON.parse(lastEmailTime) < 60000 * 2
) {
ToastEvent.show({
heading: 'Please wait before requesting another email',
@@ -177,5 +167,5 @@ export default {
onUserStatusCheck,
showVerifyEmailDialog,
getProducts,
- getUser
+ getUser,
};
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 1b99ff514..6418b221b 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -60,6 +60,7 @@ import {
MenuItemsList,
preloadImages,
SUBSCRIPTION_PROVIDER,
+ SUBSCRIPTION_STATUS,
SUBSCRIPTION_STATUS_STRINGS,
} from '../../utils';
import {
@@ -836,11 +837,7 @@ const SettingsUserSection = () => {
</View>
</View>
<View>
- {user.subscription.type === 1 ||
- user.subscription.type === 2 ||
- user.subscription.type === 5 ||
- user.subscription.type === 6 ||
- user.subscription.type === 7 ? (
+ {user.subscription.type !== SUBSCRIPTION_STATUS.BASIC ? (
<View>
<Seperator />
<Paragraph
@@ -877,8 +874,9 @@ const SettingsUserSection = () => {
) : null}
{user.isEmailConfirmed &&
- user.subscription.type !== 5 &&
- user.subscription.type !== 2 && (
+ user.subscription.type !== SUBSCRIPTION_STATUS.PREMIUM &&
+ user.subscription.type !== SUBSCRIPTION_STATUS.BETA &&
+ user.subscription.type !== SUBSCRIPTION_STATUS.PREMIUM_CANCELLED && (
<>
<Seperator />
<Button
@@ -913,9 +911,8 @@ const SettingsUserSection = () => {
</View>
{user?.subscription?.provider &&
- user.subscription.type !== 6 &&
- user.subscription.type !== 7 &&
- user.subscription.type !== 0 &&
+ user.subscription.type !== SUBSCRIPTION_STATUS.PREMIUM_EXPIRED &&
+ user.subscription.type !== SUBSCRIPTION_STATUS.BASIC &&
SUBSCRIPTION_PROVIDER[user?.subscription?.provider] ? (
<Button
title={