Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ld config fix #1157

Merged
merged 2 commits into from
Jun 8, 2022
Merged
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ I18_RELOAD_ON_PRERENDER=false
STATS_API_URL=https://mainnet.api.daostats.io
TOASTS_NOTIFICATIONS_TIMEOUT=20000
APP_DOMAIN=.astrodao.com
NEXT_PUBLIC_LAUNCHDARKLY_ID=620ac654be1f0913f65d9ca4
#NEXT_PUBLIC_LAUNCHDARKLY_ID=620ac654be1f0913f65d9ca4
NEAR_CONTRACT_NAME=sputnikv2.testnet
TOKEN_FACTORY_CONTRACT_NAME=tokens.testnet

2 changes: 2 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ declare global {
TOASTS_NOTIFICATIONS_TIMEOUT: number;
I18_RELOAD_ON_PRERENDER: boolean;

NEXT_PUBLIC_LAUNCHDARKLY_ID: string;

NEAR_ENV: string;
}
}
Expand Down
34 changes: 22 additions & 12 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { FunctionComponent, useEffect } from 'react';
import React, { useEffect, useMemo } from 'react';
import Head from 'next/head';
import { appWithTranslation } from 'next-i18next';
import type { AppContext, AppProps } from 'next/app';
import { withLDProvider } from 'launchdarkly-react-client-sdk';
import { LDProvider } from 'launchdarkly-react-client-sdk';

import nextI18NextConfig from 'next-i18next.config';
import { appConfig as applicationConfig } from 'config';

import { ModalProvider } from 'components/modal';
import { PageLayout } from 'astro_2.0/components/PageLayout';
Expand All @@ -24,6 +23,7 @@ import { DAO_COOKIE, DEFAULT_OPTIONS } from 'constants/cookies';
import { AppMonitoring } from 'astro_2.0/features/AppMonitoring/AppMonitoring';
import ErrorBoundary from 'astro_2.0/components/ErrorBoundary';
import { useAppInitialize } from 'hooks/useAppInitialize';
import { configService } from 'services/ConfigService';

function App({ Component, pageProps }: AppProps): JSX.Element | null {
const router = useRouter();
Expand All @@ -35,12 +35,27 @@ function App({ Component, pageProps }: AppProps): JSX.Element | null {

useIntercomAdjust();

if (!initialized) {
const ldProps = useMemo(() => {
if (initialized) {
const { appConfig } = configService.get();

return {
clientSideID: appConfig.LAUNCHDARKLY_ID as string,
reactOptions: {
useCamelCaseFlagKeys: true,
},
};
}

return null;
}, [initialized]);

if (!initialized || !ldProps) {
return null;
}

return (
<>
<LDProvider {...ldProps}>
<AppMonitoring />
<WrappedWalletContext>
<ModalProvider>
Expand All @@ -61,7 +76,7 @@ function App({ Component, pageProps }: AppProps): JSX.Element | null {
</SocketProvider>
</ModalProvider>
</WrappedWalletContext>
</>
</LDProvider>
);
}

Expand All @@ -73,9 +88,4 @@ App.getInitialProps = async ({ ctx }: AppContext) => {
return {};
};

export default withLDProvider({
clientSideID: applicationConfig.LAUNCHDARKLY_ID as string,
reactOptions: {
useCamelCaseFlagKeys: true,
},
})(appWithTranslation(App, nextI18NextConfig) as FunctionComponent);
export default appWithTranslation(App, nextI18NextConfig);
1 change: 1 addition & 0 deletions pages/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function handler(
APP_DOMAIN: process.env.APP_DOMAIN,
NEAR_ENV: process.env.NEAR_ENV,
NEAR_CONTRACT_NAME: process.env.NEAR_CONTRACT_NAME,
LAUNCHDARKLY_ID: process.env.NEXT_PUBLIC_LAUNCHDARKLY_ID,
};

res.status(200).json(config);
Expand Down
1 change: 1 addition & 0 deletions types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Config = {
LOCAL_WALLET_REDIRECT: boolean;
NEAR_CONTRACT_NAME: string;
TOKEN_FACTORY_CONTRACT_NAME: string;
LAUNCHDARKLY_ID: string;
};

export enum WalletType {
Expand Down