Skip to content

Commit dd7eeb2

Browse files
committed
add development context
1 parent ccb0935 commit dd7eeb2

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createContext, useContext, type PropsWithChildren } from 'react'
2+
3+
const DevelopmentContext = createContext(false)
4+
5+
export const ProvideDevelopmentContext = ({
6+
children,
7+
isDev,
8+
}: PropsWithChildren<{ isDev: boolean }>) => (
9+
<DevelopmentContext value={isDev}>{children}</DevelopmentContext>
10+
)
11+
12+
export const useIsDev = () => useContext(DevelopmentContext)

deployables/app/app/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { lazy } from 'react'
22

33
export { AvatarInput } from './AvatarInput'
44
export { ChainSelect } from './ChainSelect'
5+
export { ProvideDevelopmentContext, useIsDev } from './DevelopmentContext'
56
export * from './navigation'
67
export { Page } from './Page'
78
export * from './pilotStatus'

deployables/app/app/components/versionManagement/MinimumVersion.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
import { compare } from 'compare-versions'
22
import type { PropsWithChildren } from 'react'
3+
import { useIsDev } from '../DevelopmentContext'
34
import { useExtensionVersion } from './ExtensionVersionContext'
45

56
export const MinimumVersion = ({
67
children,
78
version,
89
}: PropsWithChildren<{ version: string }>) => {
910
const extensionVersion = useExtensionVersion()
11+
const isDev = useIsDev()
12+
13+
if (isDev) {
14+
return (
15+
<div className="rounded border border-yellow-900/80">
16+
<div className="flex items-center gap-2 p-2 text-xs uppercase">
17+
<span className="opacity-75">From version:</span>
18+
<span className="font-semibold">{version}</span>
19+
</div>
20+
21+
{children}
22+
</div>
23+
)
24+
}
1025

1126
// Extension too old to even support this feature
1227
if (extensionVersion == null) {

deployables/app/app/root.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ProvideExtensionVersion } from '@/components'
1+
import {
2+
ProvideDevelopmentContext,
3+
ProvideExtensionVersion,
4+
} from '@/components'
25
import { ToastContainer } from '@zodiac/ui'
36
import {
47
isRouteErrorResponse,
@@ -7,6 +10,7 @@ import {
710
Outlet,
811
Scripts,
912
ScrollRestoration,
13+
useLoaderData,
1014
} from 'react-router'
1115
import type { Route } from './+types/root'
1216

@@ -20,7 +24,7 @@ export function Layout({ children }: { children: React.ReactNode }) {
2024
<Links />
2125
</head>
2226
<body className="flex h-full flex-col text-base text-zinc-900 dark:text-white">
23-
<ProvideExtensionVersion>{children}</ProvideExtensionVersion>
27+
{children}
2428
<ToastContainer />
2529
<ScrollRestoration />
2630
<Scripts />
@@ -29,8 +33,18 @@ export function Layout({ children }: { children: React.ReactNode }) {
2933
)
3034
}
3135

36+
export const loader = () => ({ isDev: process.env.NODE_ENV === 'development' })
37+
3238
export default function App() {
33-
return <Outlet />
39+
const { isDev } = useLoaderData<typeof loader>()
40+
41+
return (
42+
<ProvideDevelopmentContext isDev={isDev}>
43+
<ProvideExtensionVersion>
44+
<Outlet />
45+
</ProvideExtensionVersion>
46+
</ProvideDevelopmentContext>
47+
)
3448
}
3549

3650
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {

deployables/app/app/routes/edit/edit-route.$data.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AvatarInput,
33
ChainSelect,
44
ConnectWallet,
5+
useIsDev,
56
WalletProvider,
67
ZodiacMod,
78
} from '@/components'
@@ -71,7 +72,6 @@ export const loader = ({ params }: Route.LoaderArgs) => {
7172
chainId,
7273
avatar: route.avatar,
7374
waypoints: route.waypoints,
74-
isDev: process.env.NODE_ENV === 'development',
7575
}
7676
}
7777

@@ -174,11 +174,12 @@ export const clientAction = async ({
174174
}
175175

176176
const EditRoute = ({
177-
loaderData: { chainId, label, avatar, waypoints, isDev },
177+
loaderData: { chainId, label, avatar, waypoints },
178178
actionData,
179179
}: Route.ComponentProps) => {
180180
const submit = useSubmit()
181181
const optimisticRoute = useOptimisticRoute()
182+
const isDev = useIsDev()
182183

183184
return (
184185
<>

0 commit comments

Comments
 (0)