Skip to content

Commit 7d5695f

Browse files
committed
refactor: injects browserEnvConfig from DI container
1 parent defe97a commit 7d5695f

File tree

15 files changed

+53
-67
lines changed

15 files changed

+53
-67
lines changed

apps/deploy-web/src/components/deployments/DeploymentDetailTopBar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { Edit, MoreHoriz, NavArrowLeft, Refresh, Upload, XmarkSquare } from "ico
1313
import { useRouter } from "next/navigation";
1414

1515
import { CustomDropdownLinkItem } from "@src/components/shared/CustomDropdownLinkItem";
16-
import { browserEnvConfig } from "@src/config/browser-env.config";
1716
import { useLocalNotes } from "@src/context/LocalNoteProvider";
1817
import { useServices } from "@src/context/ServicesProvider";
1918
import { useWallet } from "@src/context/WalletProvider";
@@ -48,7 +47,7 @@ export const DeploymentDetailTopBar: React.FunctionComponent<Props> = ({
4847
deployment,
4948
leases
5049
}) => {
51-
const { analyticsService } = useServices();
50+
const { analyticsService, publicConfig } = useServices();
5251
const { changeDeploymentName, getDeploymentData, getDeploymentName } = useLocalNotes();
5352
const { udenomToUsd } = usePricing();
5453
const router = useRouter();
@@ -232,7 +231,7 @@ export const DeploymentDetailTopBar: React.FunctionComponent<Props> = ({
232231
<div className="space-y-2">
233232
<div>
234233
<div>
235-
Estimated amount: ${udenomToUsd(deploymentSetting.data?.estimatedTopUpAmount || 0, browserEnvConfig.NEXT_PUBLIC_MANAGED_WALLET_DENOM)}
234+
Estimated amount: ${udenomToUsd(deploymentSetting.data?.estimatedTopUpAmount || 0, publicConfig.NEXT_PUBLIC_MANAGED_WALLET_DENOM)}
236235
</div>
237236
<div>Check period: {formatDuration(intervalToDuration({ start: 0, end: deploymentSetting.data?.topUpFrequencyMs || 0 }))}</div>
238237
</div>

apps/deploy-web/src/components/get-started/GetStartedStepper.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Link from "next/link";
1313

1414
import { AddFundsLink } from "@src/components/user/AddFundsLink";
1515
import { ConnectManagedWalletButton } from "@src/components/wallet/ConnectManagedWalletButton";
16-
import { browserEnvConfig } from "@src/config/browser-env.config";
16+
import { useServices } from "@src/context/ServicesProvider";
1717
import { useWallet } from "@src/context/WalletProvider";
1818
import { useChainParam } from "@src/hooks/useChainParam/useChainParam";
1919
import { useCustomUser } from "@src/hooks/useCustomUser";
@@ -29,6 +29,7 @@ import { ConnectWalletButton } from "../wallet/ConnectWalletButton";
2929
import { QontoConnector, QontoStepIcon } from "./Stepper";
3030

3131
export const GetStartedStepper: React.FunctionComponent = () => {
32+
const { publicConfig } = useServices();
3233
const [activeStep, setActiveStep] = useState(0);
3334
const { isWalletConnected, address, isManaged: isManagedWallet, isTrialing } = useWallet();
3435
const { refetch: refetchBalances, balance: walletBalance } = useWalletBalance();
@@ -76,11 +77,11 @@ export const GetStartedStepper: React.FunctionComponent = () => {
7677
onClick={() => (activeStep > 0 ? onStepClick(0) : null)}
7778
classes={{ label: cn("text-xl tracking-tight", { ["cursor-pointer hover:text-primary"]: activeStep > 0, ["!font-bold"]: activeStep === 0 }) }}
7879
>
79-
{browserEnvConfig.NEXT_PUBLIC_BILLING_ENABLED ? "Trial / Billing" : "Billing"}
80+
{publicConfig.NEXT_PUBLIC_BILLING_ENABLED ? "Trial / Billing" : "Billing"}
8081
</StepLabel>
8182

8283
<StepContent>
83-
{browserEnvConfig.NEXT_PUBLIC_BILLING_ENABLED && !isWalletConnected && (
84+
{publicConfig.NEXT_PUBLIC_BILLING_ENABLED && !isWalletConnected && (
8485
<p className="text-muted-foreground">
8586
You can pay using either USD (fiat) or with crypto ($AKT or $USDC). To pay with USD, click "Start Trial". To pay with crypto, click "Connect
8687
Wallet"
@@ -143,7 +144,7 @@ export const GetStartedStepper: React.FunctionComponent = () => {
143144
</div>
144145

145146
<div className="flex items-center gap-2">
146-
{browserEnvConfig.NEXT_PUBLIC_BILLING_ENABLED && !isSignedInWithTrial && <ConnectManagedWalletButton className="mr-2 w-full md:w-auto" />}
147+
{publicConfig.NEXT_PUBLIC_BILLING_ENABLED && !isSignedInWithTrial && <ConnectManagedWalletButton className="mr-2 w-full md:w-auto" />}
147148
<ConnectWalletButton />
148149

149150
{isSignedInWithTrial && !user && (

apps/deploy-web/src/components/layout/CustomGoogleAnalytics.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { useReportWebVitals } from "next/web-vitals";
33
import { event, GoogleAnalytics as GAnalytics } from "nextjs-google-analytics";
44

5-
import { browserEnvConfig } from "@src/config/browser-env.config";
5+
import { useServices } from "@src/context/ServicesProvider";
66

77
export default function GoogleAnalytics() {
8+
const { publicConfig } = useServices();
89
useReportWebVitals(({ id, name, label, value }) => {
910
event(name, {
1011
category: label === "web-vital" ? "Web Vitals" : "Next.js custom metric",
@@ -13,5 +14,5 @@ export default function GoogleAnalytics() {
1314
nonInteraction: true // avoids affecting bounce rate.
1415
});
1516
});
16-
return <>{!!browserEnvConfig.NEXT_PUBLIC_GA_ENABLED && <GAnalytics trackPageViews />}</>;
17+
return <>{!!publicConfig.NEXT_PUBLIC_GA_ENABLED && <GAnalytics trackPageViews />}</>;
1718
}

apps/deploy-web/src/components/layout/TrackingScripts.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"use client";
22
import { useEffect } from "react";
33

4-
import { browserEnvConfig } from "@src/config/browser-env.config";
4+
import { useServices } from "@src/context/ServicesProvider";
55
import { addScriptToBody } from "@src/utils/domUtils";
66

77
export const TrackingScripts = () => {
8-
const isProduction = browserEnvConfig.NEXT_PUBLIC_NODE_ENV === "production";
8+
const { publicConfig } = useServices();
9+
const isProduction = publicConfig.NEXT_PUBLIC_NODE_ENV === "production";
910

1011
useEffect(() => {
11-
const shouldShowTracking = browserEnvConfig.NEXT_PUBLIC_TRACKING_ENABLED;
12-
const shouldShowGrowthChannel = browserEnvConfig.NEXT_PUBLIC_GROWTH_CHANNEL_TRACKING_ENABLED;
12+
const shouldShowTracking = publicConfig.NEXT_PUBLIC_TRACKING_ENABLED;
13+
const shouldShowGrowthChannel = publicConfig.NEXT_PUBLIC_GROWTH_CHANNEL_TRACKING_ENABLED;
1314

1415
if (isProduction && shouldShowTracking) {
1516
// Google Tag Manager
@@ -21,14 +22,14 @@ export const TrackingScripts = () => {
2122
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
2223
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
2324
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
24-
})(window,document,'script','dataLayer','${browserEnvConfig.NEXT_PUBLIC_GTM_ID}');
25+
})(window,document,'script','dataLayer','${publicConfig.NEXT_PUBLIC_GTM_ID}');
2526
`
2627
});
2728

2829
// GTM noscript fallback
2930
const gtmNoscript = document.createElement("noscript");
3031
const gtmIframe = document.createElement("iframe");
31-
gtmIframe.src = `https://www.googletagmanager.com/ns.html?id=${browserEnvConfig.NEXT_PUBLIC_GTM_ID}`;
32+
gtmIframe.src = `https://www.googletagmanager.com/ns.html?id=${publicConfig.NEXT_PUBLIC_GTM_ID}`;
3233
gtmIframe.height = "0";
3334
gtmIframe.width = "0";
3435
gtmIframe.style.display = "none";

apps/deploy-web/src/components/layout/WalletStatus.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { NavArrowDown, Wallet } from "iconoir-react";
88
import { useAtom } from "jotai";
99

1010
import { ConnectManagedWalletButton } from "@src/components/wallet/ConnectManagedWalletButton";
11-
import { browserEnvConfig } from "@src/config/browser-env.config";
1211
import { useWallet } from "@src/context/WalletProvider";
1312
import { getSplitText } from "@src/hooks/useShortText";
1413
import { useWalletBalance } from "@src/hooks/useWalletBalance";
@@ -17,8 +16,6 @@ import { ConnectWalletButton } from "../wallet/ConnectWalletButton";
1716
import { CustodialWalletPopup } from "../wallet/CustodialWalletPopup";
1817
import { ManagedWalletPopup } from "../wallet/ManagedWalletPopup";
1918

20-
const withBilling = browserEnvConfig.NEXT_PUBLIC_BILLING_ENABLED;
21-
2219
export function WalletStatus() {
2320
const { walletName, isWalletLoaded, isWalletConnected, isManaged, isWalletLoading, isTrialing } = useWallet();
2421
const { balance: walletBalance, isLoading: isWalletBalanceLoading } = useWalletBalance();
@@ -84,7 +81,7 @@ export function WalletStatus() {
8481
>
8582
<div>
8683
{!isManaged && <CustodialWalletPopup walletBalance={walletBalance} />}
87-
{withBilling && isManaged && <ManagedWalletPopup walletBalance={walletBalance} />}
84+
{isManaged && <ManagedWalletPopup walletBalance={walletBalance} />}
8885
</div>
8986
</ClickAwayListener>
9087
</DropdownMenuContent>
@@ -93,7 +90,7 @@ export function WalletStatus() {
9390
</div>
9491
) : (
9592
<div className="w-full">
96-
{withBilling && !isSignedInWithTrial && <ConnectManagedWalletButton className="mb-2 mr-2 w-full md:mb-0 md:w-auto" />}
93+
{!isSignedInWithTrial && <ConnectManagedWalletButton className="mb-2 mr-2 w-full md:mb-0 md:w-auto" />}
9794
<ConnectWalletButton className="w-full md:w-auto" />
9895
</div>
9996
)

apps/deploy-web/src/components/remote-deploy/update/RemoteDeployUpdate.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { useSnackbar } from "notistack";
66

77
import { EnvFormModal } from "@src/components/sdl/EnvFormModal/EnvFormModal";
88
import { EnvVarList } from "@src/components/sdl/EnvVarList";
9-
import { browserEnvConfig } from "@src/config/browser-env.config";
109
import { CURRENT_SERVICE, protectedEnvironmentVariables } from "@src/config/remote-deploy.config";
1110
import { SdlBuilderProvider } from "@src/context/SdlBuilderProvider";
11+
import { useServices } from "@src/context/ServicesProvider";
1212
import { EnvVarUpdater } from "@src/services/remote-deploy/remote-deployment-controller.service";
1313
import { tokens } from "@src/store/remoteDeployStore";
1414
import type { SdlBuilderFormValuesType, ServiceType } from "@src/types";
@@ -27,6 +27,7 @@ const RemoteDeployUpdate = ({ sdlString, onManifestChange }: { sdlString: string
2727
const { control, watch, setValue } = useForm<SdlBuilderFormValuesType>({ defaultValues: { services: [defaultService] } });
2828
const { fields: services } = useFieldArray({ control, name: "services", keyName: "id" });
2929
const envVarUpdater = useMemo(() => new EnvVarUpdater(services), [services]);
30+
const { publicConfig } = useServices();
3031

3132
useEffect(() => {
3233
const { unsubscribe }: any = watch(data => {
@@ -60,7 +61,7 @@ const RemoteDeployUpdate = ({ sdlString, onManifestChange }: { sdlString: string
6061
}
6162
}
6263
};
63-
return services?.[0]?.image.startsWith(browserEnvConfig.NEXT_PUBLIC_CI_CD_IMAGE_NAME) && services?.[0]?.env && services?.[0]?.env?.length > 0 ? (
64+
return services?.[0]?.image.startsWith(publicConfig.NEXT_PUBLIC_CI_CD_IMAGE_NAME) && services?.[0]?.env && services?.[0]?.env?.length > 0 ? (
6465
<div className="flex flex-col gap-6 rounded border bg-card px-4 py-6 md:px-6">
6566
<div className="flex flex-col gap-3 rounded border bg-card px-6 py-6 text-card-foreground">
6667
<div className="flex items-center justify-between gap-5">

apps/deploy-web/src/components/shared/TrialDeploymentBadge.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Badge, CustomTooltip } from "@akashnetwork/ui/components";
44
import { cn } from "@akashnetwork/ui/utils";
55
import { Info } from "lucide-react";
66

7-
import { browserEnvConfig } from "@src/config/browser-env.config";
7+
import { useServices } from "@src/context/ServicesProvider";
88
import { useTrialDeploymentTimeRemaining } from "@src/hooks/useTrialDeploymentTimeRemaining";
99
import { TrialDeploymentTooltip } from "./TrialDeploymentTooltip";
1010

@@ -24,7 +24,8 @@ export const DEPENDENCIES = {
2424
};
2525

2626
export function TrialDeploymentBadge({ createdHeight, trialDurationHours, averageBlockTime = 6, className, dependencies: d = DEPENDENCIES }: Props) {
27-
const trialDuration = trialDurationHours ?? browserEnvConfig.NEXT_PUBLIC_TRIAL_DEPLOYMENTS_DURATION_HOURS;
27+
const { publicConfig } = useServices();
28+
const trialDuration = trialDurationHours ?? publicConfig.NEXT_PUBLIC_TRIAL_DEPLOYMENTS_DURATION_HOURS;
2829

2930
const { isExpired, timeRemainingText } = d.useTrialTimeRemaining({
3031
createdHeight,

apps/deploy-web/src/components/wallet/CustodialWalletPopup.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useAtom } from "jotai";
77
import Link from "next/link";
88
import { useRouter } from "next/router";
99

10-
import { browserEnvConfig } from "@src/config/browser-env.config";
1110
import { UAKT_DENOM } from "@src/config/denom.config";
1211
import { useWallet } from "@src/context/WalletProvider";
1312
import { useCustomUser } from "@src/hooks/useCustomUser";
@@ -23,8 +22,6 @@ interface CustodialWalletPopupProps extends React.PropsWithChildren {
2322
walletBalance?: WalletBalance | null;
2423
}
2524

26-
const withBilling = browserEnvConfig.NEXT_PUBLIC_BILLING_ENABLED;
27-
2825
export const CustodialWalletPopup: React.FC<CustodialWalletPopupProps> = ({ walletBalance }) => {
2926
const { address, logout } = useWallet();
3027
const router = useRouter();
@@ -85,18 +82,14 @@ export const CustodialWalletPopup: React.FC<CustodialWalletPopupProps> = ({ wall
8582
<LogOut />
8683
<span>Disconnect Wallet</span>
8784
</Button>
88-
{withBilling && (
89-
<>
90-
<Separator className="my-4" />
85+
<Separator className="my-4" />
9186

92-
{isSignedInWithTrial && !user ? (
93-
<Link className={cn(buttonVariants({ variant: "outline" }), "w-full space-x-2")} href={UrlService.newLogin()}>
94-
Sign in for USD Payments
95-
</Link>
96-
) : (
97-
<ConnectManagedWalletButton className="w-full" />
98-
)}
99-
</>
87+
{isSignedInWithTrial && !user ? (
88+
<Link className={cn(buttonVariants({ variant: "outline" }), "w-full space-x-2")} href={UrlService.newLogin()}>
89+
Sign in for USD Payments
90+
</Link>
91+
) : (
92+
<ConnectManagedWalletButton className="w-full" />
10093
)}
10194
</div>
10295
</div>

apps/deploy-web/src/config/browser-env.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const browserEnvConfig = validateStaticEnvVars({
99
NEXT_PUBLIC_MASTER_WALLET_ADDRESS: process.env.NEXT_PUBLIC_MASTER_WALLET_ADDRESS,
1010
NEXT_PUBLIC_UAKT_TOP_UP_MASTER_WALLET_ADDRESS: process.env.NEXT_PUBLIC_UAKT_TOP_UP_MASTER_WALLET_ADDRESS,
1111
NEXT_PUBLIC_USDC_TOP_UP_MASTER_WALLET_ADDRESS: process.env.NEXT_PUBLIC_USDC_TOP_UP_MASTER_WALLET_ADDRESS,
12-
NEXT_PUBLIC_BILLING_ENABLED: process.env.NEXT_PUBLIC_BILLING_ENABLED,
1312
NEXT_PUBLIC_MANAGED_WALLET_NETWORK_ID: process.env.NEXT_PUBLIC_MANAGED_WALLET_NETWORK_ID,
1413
NEXT_PUBLIC_MANAGED_WALLET_DENOM: process.env.NEXT_PUBLIC_MANAGED_WALLET_DENOM,
1514
NEXT_PUBLIC_DEFAULT_INITIAL_DEPOSIT: process.env.NEXT_PUBLIC_DEFAULT_INITIAL_DEPOSIT,

apps/deploy-web/src/context/FlagProvider/FlagProvider.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useEffect, useState } from "react";
33
import { FlagProvider as FlagProviderOriginal, useUnleashClient } from "@unleash/nextjs";
44

55
import { Loading } from "@src/components/layout/Layout";
6-
import { browserEnvConfig } from "@src/config/browser-env.config";
76
import { useUser } from "@src/hooks/useUser";
87
import type { FCWithChildren } from "@src/types/component";
8+
import { useServices } from "../ServicesProvider";
99

1010
const COMPONENTS = {
1111
FlagProvider: FlagProviderOriginal,
@@ -16,8 +16,9 @@ const COMPONENTS = {
1616
export type Props = { components?: typeof COMPONENTS };
1717

1818
export const UserAwareFlagProvider: FCWithChildren<Props> = ({ children, components: c = COMPONENTS }) => {
19+
const { publicConfig } = useServices();
1920
const { user } = c.useUser();
20-
const isEnableAll = browserEnvConfig.NEXT_PUBLIC_UNLEASH_ENABLE_ALL;
21+
const isEnableAll = publicConfig.NEXT_PUBLIC_UNLEASH_ENABLE_ALL;
2122

2223
return (
2324
<c.FlagProvider

0 commit comments

Comments
 (0)