Skip to content

Commit

Permalink
Fix VITE_FEATURE_GATING_DAPP_ENABLED feature flag (#938)
Browse files Browse the repository at this point in the history
Respect the `VITE_FEATURE_GATING_DAPP_ENABLED` feature flag when
redirecting to `/access` or `/welcome` page.
  • Loading branch information
nkuba authored Feb 18, 2025
2 parents a039422 + eb814f8 commit 949e3d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
6 changes: 5 additions & 1 deletion dapp/src/pages/AccessPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from "react"
import { useAppNavigate } from "#/hooks"
import GateModal from "#/components/GateModal"
import { featureFlags } from "#/constants"
import { Navigate } from "react-router-dom"

export default function AccessPage() {
const navigate = useAppNavigate()

return (
return featureFlags.GATING_DAPP_ENABLED ? (
<GateModal
closeModal={() => {
navigate("/dashboard")
}}
/>
) : (
<Navigate to="/welcome" />
)
}
21 changes: 15 additions & 6 deletions dapp/src/pages/AccessPage/loader.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { featureFlags } from "#/constants"
import { getAccessCodeFromLocalStorage } from "#/hooks/useAccessCode"
import { acreApi, router, shouldDisplayWelcomeModal } from "#/utils"
import { LoaderFunction } from "react-router-dom"

const resolveSuccessRedirect = (
url: string,
redirectToOnSuccess: null | string = null,
) =>
shouldDisplayWelcomeModal()
? router.redirectWithSearchParams(url, "/welcome")
: !redirectToOnSuccess ||
router.redirectWithSearchParams(url, redirectToOnSuccess)

export const redirectToAccessPageLoader = async (
url: string,
redirectToOnSuccess: null | string = null,
redirectToOnFail: null | string = null,
) => {
if (!featureFlags.GATING_DAPP_ENABLED) {
return resolveSuccessRedirect(url, redirectToOnSuccess)
}

try {
const encodedCode = getAccessCodeFromLocalStorage()

Expand All @@ -15,12 +29,7 @@ export const redirectToAccessPageLoader = async (
: false

if (isValid) {
const shouldRedirectToWelcomeModal = shouldDisplayWelcomeModal()

return shouldRedirectToWelcomeModal
? router.redirectWithSearchParams(url, "/welcome")
: !redirectToOnSuccess ||
router.redirectWithSearchParams(url, redirectToOnSuccess)
return resolveSuccessRedirect(url, redirectToOnSuccess)
}

return redirectToOnFail
Expand Down
4 changes: 1 addition & 3 deletions dapp/src/router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const mainLayoutLoader: LoaderFunction = ({ request }) => {
const embedApp = referralProgram.getEmbeddedApp(request.url)

if (referralProgram.isEmbedApp(embedApp)) {
const shouldRedirectToWelcomeModal = !shouldDisplayWelcomeModal()

return shouldRedirectToWelcomeModal
return shouldDisplayWelcomeModal()
? routerUtils.redirectWithSearchParams(request.url, "/welcome")
: routerUtils.redirectWithSearchParams(request.url, "/dashboard")
}
Expand Down

0 comments on commit 949e3d9

Please sign in to comment.