Skip to content

Commit

Permalink
feat(mfi-v2-ui): feature gates
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s committed Sep 21, 2023
1 parent 06a1127 commit 33dc991
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/marginfi-v2-ui/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Badge } from "@mui/material";
import { useFirebaseAccount } from "../useFirebaseAccount";
import { groupedNumberFormatterDyn, numeralFormatter } from "@mrgnlabs/mrgn-common";
import { useWalletContext } from "../useWalletContext";
import { Features, isActive } from "~/utils/featureGates";

// @todo implement second pretty navbar row
const Navbar: FC = () => {
Expand Down Expand Up @@ -143,7 +144,7 @@ const Navbar: FC = () => {
</Link>
</Badge>

<Badge
{isActive(Features.STAKE) && <Badge
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
Expand All @@ -163,7 +164,7 @@ const Navbar: FC = () => {
>
stake
</Link>
</Badge>
</Badge>}

<Badge
anchorOrigin={{
Expand Down
2 changes: 1 addition & 1 deletion apps/marginfi-v2-ui/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server";

export const config = {
matcher: ["/", "/index"],
matcher: ["/", "/index", "/stake", "/swap", "/bridge", "/earn", "/points"],
};

export function middleware(req: NextRequest) {
Expand Down
17 changes: 16 additions & 1 deletion apps/marginfi-v2-ui/src/pages/stake.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { JupiterProvider } from "@jup-ag/react-hook";
import { createJupiterStore } from "@mrgnlabs/marginfi-v2-ui-state";
import { useConnection } from "@solana/wallet-adapter-react";
import { useEffect } from "react";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { PageHeader } from "~/components/PageHeader";
import { StakingStats } from "~/components/Staking";
import { StakingCard } from "~/components/Staking/StakingCard/StakingCard";
import { useWalletContext } from "~/components/useWalletContext";
import { createLstStore } from "~/store/lstStore";
import { usePrevious } from "~/utils";
import { Features, isActive } from "~/utils/featureGates";

export const useLstStore = createLstStore();
export const useJupiterStore = createJupiterStore();

const StakePage = () => {
const { wallet, walletAddress } = useWalletContext();
const { connection } = useConnection();
const [mounted, setMounted] = useState(false);

const router = useRouter();

useEffect(() => {
if (router.pathname.startsWith('/stake') && !isActive(Features.STAKE)) {
router.push('/');
} else {
setMounted(true);
}
}, [router]);

const [fetchLstState, setIsRefreshingStore, userDataFetched, resetUserData] = useLstStore((state) => [
state.fetchLstState,
Expand Down Expand Up @@ -48,6 +61,8 @@ const StakePage = () => {
}
}, [walletAddress, userDataFetched, resetUserData]);

if (!mounted) return null;

return (
<JupiterProvider connection={connection}>
<PageHeader>stake</PageHeader>
Expand Down
14 changes: 14 additions & 0 deletions apps/marginfi-v2-ui/src/utils/featureGates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enum Features {
STAKE = 'stake',
}

function isActive(feature: Features) {
const featureGatesRaw = process.env.NEXT_PUBLIC_FEATURE_GATES as string | undefined;
if (!featureGatesRaw) return false;

const featureGates = JSON.parse(featureGatesRaw) as Record<string, boolean>;

return !!featureGates[feature];
}

export { Features, isActive };
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"NEXT_PUBLIC_MARGINFI_FEATURES_CREATE_CAMPAIGN",
"NEXT_PUBLIC_OMNI_TABLE_ID",
"NEXT_PUBLIC_FIREBASE_PROJECT_ID",
"NEXT_PUBLIC_FEATURE_GATES",
"FIREBASE_CLIENT_EMAIL",
"FIREBASE_PRIVATE_KEY",
"NEXT_PUBLIC_FIREBASE_DATABASE_URL",
Expand Down

0 comments on commit 33dc991

Please sign in to comment.