From 9eda07d233283277a4a428472df31350e6b3a176 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 6 Jun 2025 11:01:14 +0500 Subject: [PATCH] web: fix infinite rerenders on checkout screen --- apps/web/src/dialogs/buy-dialog/paddle.tsx | 25 ++++++++++------------ apps/web/src/dialogs/buy-dialog/plans.ts | 9 ++++---- apps/web/src/views/auth.tsx | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/apps/web/src/dialogs/buy-dialog/paddle.tsx b/apps/web/src/dialogs/buy-dialog/paddle.tsx index bce67b392..ef0fde672 100644 --- a/apps/web/src/dialogs/buy-dialog/paddle.tsx +++ b/apps/web/src/dialogs/buy-dialog/paddle.tsx @@ -34,21 +34,18 @@ import { ScrollContainer } from "@notesnook/ui"; import useMobile from "../../hooks/use-mobile"; import { logger } from "../../utils/logger"; import { isFeatureSupported } from "../../utils/feature-check"; +import { isDev } from "./plans"; -// const isDev = false; // import.meta.env.DEV; -const VENDOR_ID = import.meta.env.DEV || IS_TESTING ? 1506 : 128190; -const PADDLE_ORIGIN = - import.meta.env.DEV || IS_TESTING - ? "https://sandbox-buy.paddle.com" - : "https://buy.paddle.com"; -const SUBSCRIPTION_MANAGEMENT_URL = - import.meta.env.DEV || IS_TESTING - ? "https://sandbox-subscription-management.paddle.com" - : "https://subscription-management.paddle.com"; -const CHECKOUT_SERVICE_ORIGIN = - import.meta.env.DEV || IS_TESTING - ? "https://sandbox-checkout-service.paddle.com" - : "https://checkout-service.paddle.com"; +const VENDOR_ID = isDev ? 1506 : 128190; +const PADDLE_ORIGIN = isDev + ? "https://sandbox-buy.paddle.com" + : "https://buy.paddle.com"; +const SUBSCRIPTION_MANAGEMENT_URL = isDev + ? "https://sandbox-subscription-management.paddle.com" + : "https://subscription-management.paddle.com"; +const CHECKOUT_SERVICE_ORIGIN = isDev + ? "https://sandbox-checkout-service.paddle.com" + : "https://checkout-service.paddle.com"; const SUBSCRIBED_EVENTS: PaddleEvents[] = [ PaddleEvents["Checkout.Loaded"], diff --git a/apps/web/src/dialogs/buy-dialog/plans.ts b/apps/web/src/dialogs/buy-dialog/plans.ts index 16ef8f9c7..4be5c9df5 100644 --- a/apps/web/src/dialogs/buy-dialog/plans.ts +++ b/apps/web/src/dialogs/buy-dialog/plans.ts @@ -18,7 +18,6 @@ along with this program. If not, see . */ import { useEffect, useState } from "react"; - import { Period, Plan } from "./types"; type PlanMetadata = { @@ -26,8 +25,10 @@ type PlanMetadata = { subtitle: string; }; +export const isDev = import.meta.env.DEV || IS_TESTING; + export const EDUCATION_PLAN: Plan = { - id: import.meta.env.DEV || IS_TESTING ? "50305" : "658759", + id: isDev ? "50305" : "658759", period: "education", country: "US", currency: "USD", @@ -43,7 +44,7 @@ export const DEFAULT_PLANS: Plan[] = [ currency: "USD", discount: { type: "regional", amount: 0, recurring: false }, originalPrice: { gross: 4.49, net: 0, tax: 0 }, - id: import.meta.env.DEV || IS_TESTING ? "9822" : "648884", + id: isDev ? "9822" : "648884", price: { gross: 4.49, net: 0, tax: 0 } }, { @@ -51,7 +52,7 @@ export const DEFAULT_PLANS: Plan[] = [ country: "PK", currency: "USD", discount: { type: "regional", amount: 0, recurring: false }, - id: import.meta.env.DEV || IS_TESTING ? "50305" : "658759", + id: isDev ? "50305" : "658759", price: { gross: 49.99, net: 0, tax: 0 }, originalPrice: { gross: 49.99, net: 0, tax: 0 } }, diff --git a/apps/web/src/views/auth.tsx b/apps/web/src/views/auth.tsx index 06e8c310f..5c3b65326 100644 --- a/apps/web/src/views/auth.tsx +++ b/apps/web/src/views/auth.tsx @@ -201,7 +201,7 @@ export function HeadlessAuth(props: AuthProps) { performance.mark("load:auth"); setIsReady(true); }); - }, [route, openURL]); + }, [route]); if (!isReady) return <>;