Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions scripts/seed-data/communities/nouns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ export function createNounsCommunityConfig(
],
nftTokens: [
{
address: '0x9C8fF314C9Bc7F6e59A9d9225Fb22946427eDC03',
symbol: 'Nouns',
address: '0xD094D5D45c06c1581f5f429462eE7cCe72215616',
symbol: 'nOGs',
type: 'erc721',
network: 'eth',
network: 'base',
},
],
},
Expand Down Expand Up @@ -188,4 +188,3 @@ export function createNounsCommunityConfig(
},
};
}

2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default async function RootLayout({
}
>
<SpeedInsights />
<Providers>
<Providers systemConfig={systemConfig}>
{sidebarLayout(children, systemConfig)}
<ContextDebugger />
</Providers>
Expand Down
7 changes: 5 additions & 2 deletions src/common/components/organisms/NogsGateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isUndefined } from "lodash";
import { mapNetworkToAlchemy } from "@/common/lib/utils/tokenGates";
import { getNftTokens } from "@/common/lib/utils/tokenGates";
import { useTokenGate } from "@/common/lib/hooks/useTokenGate";
import { useSystemConfigContext } from "@/common/providers/SystemConfigProvider";
import { type SystemConfig } from "@/config";

type NogsGateButtonProps = ButtonProps & {
Expand Down Expand Up @@ -49,12 +50,14 @@ const NogsGateButton = ({ systemConfig, ...props }: NogsGateButtonProps) => {

const [modalOpen, setModalOpen] = useState(false);
const { user } = usePrivy();
const contextConfig = useSystemConfigContext();
const effectiveConfig = systemConfig ?? contextConfig ?? undefined;

// Use token gate hook for ERC20 token gating
const { erc20Token, gatingSatisfied, walletAddress } = useTokenGate(systemConfig);
const { erc20Token, gatingSatisfied, walletAddress } = useTokenGate(effectiveConfig);

// Extract NFT tokens from config - memoize to prevent infinite re-renders
const nftTokens = useMemo(() => getNftTokens(systemConfig), [systemConfig]);
const nftTokens = useMemo(() => getNftTokens(effectiveConfig), [effectiveConfig]);

// Optional debug logs
useEffect(() => {
Expand Down
6 changes: 4 additions & 2 deletions src/common/lib/hooks/useTokenGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { zeroAddress, type Address } from "viem";
import { useAppStore } from "@/common/data/stores/app";
import { getPrimaryErc20Token, getChainForNetwork, formatTokenBalance } from "@/common/lib/utils/tokenGates";
import { MIN_SPACE_TOKENS_FOR_UNLOCK } from "@/common/constants/gates";
import { useSystemConfigContext } from "@/common/providers/SystemConfigProvider";
import type { SystemConfig } from "@/config";

/**
Expand All @@ -15,7 +16,9 @@ import type { SystemConfig } from "@/config";
*/
export function useTokenGate(systemConfig?: SystemConfig) {
const { user } = usePrivy();
const erc20Token = getPrimaryErc20Token(systemConfig);
const contextConfig = useSystemConfigContext();
const effectiveConfig = systemConfig ?? contextConfig ?? undefined;
const erc20Token = getPrimaryErc20Token(effectiveConfig);
const walletAddress = user?.wallet?.address as Address | undefined;

const { data: balanceData, isLoading, isFetching } = useBalance({
Expand Down Expand Up @@ -44,4 +47,3 @@ export function useTokenGate(systemConfig?: SystemConfig) {
hasNogs,
};
}

26 changes: 26 additions & 0 deletions src/common/providers/SystemConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";

import React, { createContext, useContext } from "react";
import type { SystemConfig } from "@/config";

const SystemConfigContext = createContext<SystemConfig | null>(null);

type SystemConfigProviderProps = {
children: React.ReactNode;
systemConfig: SystemConfig;
};

export function SystemConfigProvider({
children,
systemConfig,
}: SystemConfigProviderProps) {
return (
<SystemConfigContext.Provider value={systemConfig}>
{children}
</SystemConfigContext.Provider>
);
}

export function useSystemConfigContext(): SystemConfig | null {
return useContext(SystemConfigContext);
}
14 changes: 11 additions & 3 deletions src/common/providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import MobilePreviewProvider from "./MobilePreviewProvider";
import { SharedDataProvider } from "./SharedDataProvider";
import { MiniKitContextProvider } from "./MiniKitProvider";
import { GlobalErrorHandler } from "./GlobalErrorHandler";
import { SystemConfigProvider } from "./SystemConfigProvider";
import type { SystemConfig } from "@/config";

const RarelyUpdatedProviders = React.memo(
function RarelyUpdatedProviders({
Expand All @@ -38,9 +40,15 @@ const RarelyUpdatedProviders = React.memo(
},
);

export default function Providers({ children }: { children: React.ReactNode }) {
export default function Providers({
children,
systemConfig,
}: {
children: React.ReactNode;
systemConfig: SystemConfig;
}) {
return (
<>
<SystemConfigProvider systemConfig={systemConfig}>
<GlobalErrorHandler />
<VersionCheckProivder>
<Privy>
Expand All @@ -65,6 +73,6 @@ export default function Providers({ children }: { children: React.ReactNode }) {
</Query>
</Privy>
</VersionCheckProivder>
</>
</SystemConfigProvider>
);
}