Skip to content

Commit

Permalink
add three day grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Aug 8, 2023
1 parent 958c2b6 commit f78d7af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/routes/settings/Plus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import eify from "~/utils/eify";
import party from "~/assets/party.gif";
import { LoadingShimmer } from "~/components/BalanceBox";
import { useI18n } from "~/i18n/context";
import { subscriptionValid } from "~/utils/subscriptions";

function Perks(props: { alreadySubbed?: boolean }) {
const i18n = useI18n();
Expand Down Expand Up @@ -114,10 +115,7 @@ function PlusCTA() {
);
}

if (
state.subscription_timestamp &&
state.subscription_timestamp < Math.ceil(Date.now() / 1000)
) {
if (!subscriptionValid(state.subscription_timestamp)) {
setError(
new Error(
i18n.t("settings.plus.error_expired_subscription")
Expand Down
10 changes: 3 additions & 7 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { checkBrowserCompatibility } from "~/logic/browserCompatibility";
import eify from "~/utils/eify";
import { timeout } from "~/utils/timeout";
import { ParsedParams } from "~/logic/waila";
import { subscriptionValid } from "~/utils/subscriptions";

const MegaStoreContext = createContext<MegaStore>();

Expand Down Expand Up @@ -81,13 +82,8 @@ export const Provider: ParentComponent = (props) => {
existing_tab_detected: false,
subscription_timestamp: undefined as number | undefined,
get mutiny_plus(): boolean {
// No subscription
if (!state.subscription_timestamp) return false;

// Expired
if (state.subscription_timestamp < Math.ceil(Date.now() / 1000))
return false;
else return true;
// Make sure the subscription hasn't expired
return subscriptionValid(state.subscription_timestamp);
},
needs_password: false,
load_stage: "fresh" as LoadStage,
Expand Down
7 changes: 7 additions & 0 deletions src/utils/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const GRACE = 60 * 60 * 24 * 3; // 3 days

export function subscriptionValid(subscriptionExpiresTimestamp?: number) {
if (!subscriptionExpiresTimestamp) return false;

return subscriptionExpiresTimestamp + GRACE > Math.ceil(Date.now() / 1000);
}

0 comments on commit f78d7af

Please sign in to comment.