-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: restructure pages to resemble an actual web-app; use loaders a…
…nd actions (#340) * use loader to pull routes in list routes and edit route component * start handling the case of no routes * move routes around * create more focussed context * reorg context and app structure more * remove some obsolete code * migrate useSelectedRouteId hook * pass state more directly * use react-router instead of react-router-dom * adjust list routes spec * adjust edit route spec * port more things into loaders * adjust list routes component * adjust edit link * update breadcrumbs * move list and edit routes out of active route scope * add action to no route component * fix: do not break on IDs that contain `-` * make sure to correctly save initial route * add add new route on list * edit route requires route to be present * use loader for transactions * remove loader from transactions again * resolve dependency cycles * adjust specs again matching routes * adjust e2e tests * remove route through action * add handling for removing the last route * add createRoute helper * adjust edit spec to also use action * adjust e2e test
- Loading branch information
1 parent
e096e9c
commit c9f3cb4
Showing
78 changed files
with
699 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
extension/src/panel/execution-routes/ExecutionRouteContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { ExecutionRoute } from '@/types' | ||
import { invariant } from '@epic-web/invariant' | ||
import { createContext, useContext, type PropsWithChildren } from 'react' | ||
|
||
const ExecutionRouteContext = createContext<{ route: ExecutionRoute | null }>({ | ||
route: null, | ||
}) | ||
|
||
export const ProvideExecutionRoute = ({ | ||
route, | ||
children, | ||
}: PropsWithChildren<{ route: ExecutionRoute }>) => ( | ||
<ExecutionRouteContext.Provider value={{ route }}> | ||
{children} | ||
</ExecutionRouteContext.Provider> | ||
) | ||
|
||
export const useExecutionRoute = () => { | ||
const { route } = useContext(ExecutionRouteContext) | ||
|
||
invariant(route != null, 'Could not find active route on context') | ||
|
||
return route | ||
} | ||
|
||
export const useSelectedRouteId = () => { | ||
const route = useExecutionRoute() | ||
|
||
return route.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
extension/src/panel/execution-routes/SelectedRouteContext.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ETH_ZERO_ADDRESS } from '@/chains' | ||
import { ProviderType } from '@/types' | ||
import { nanoid } from 'nanoid' | ||
import { saveRoute } from './saveRoute' | ||
|
||
export const createRoute = () => | ||
saveRoute({ | ||
id: nanoid(), | ||
label: '', | ||
providerType: ProviderType.InjectedWallet, | ||
avatar: ETH_ZERO_ADDRESS, | ||
initiator: undefined, | ||
waypoints: undefined, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getStorageEntry } from '../utils' | ||
|
||
export const getLastUsedRouteId = () => | ||
getStorageEntry<string | null>({ key: 'lastUsedRoute' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { type ExecutionRoute } from '@/types' | ||
import { invariant } from '@epic-web/invariant' | ||
import { getStorageEntry } from '../utils' | ||
|
||
export const getRoute = async (routeId: string) => { | ||
const route = await getStorageEntry<ExecutionRoute | undefined>({ | ||
collection: 'routes', | ||
key: routeId, | ||
}) | ||
|
||
invariant(route != null, `Could not find route with id "${routeId}"`) | ||
|
||
return route | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { ExecutionRoute } from '@/types' | ||
import { getStorageEntries } from '../utils' | ||
|
||
export const getRoutes = async () => { | ||
const routes = await getStorageEntries<ExecutionRoute>('routes') | ||
|
||
return Object.values(routes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
export { createRoute } from './createRoute' | ||
export { | ||
ProvideExecutionRoute, | ||
useExecutionRoute, | ||
useSelectedRouteId, | ||
} from './ExecutionRouteContext' | ||
export { | ||
ProvideExecutionRoutes, | ||
useExecutionRoutes, | ||
useMarkRouteAsUsed, | ||
useRemoveExecutionRoute, | ||
useSaveExecutionRoute, | ||
} from './ExecutionRoutesContext' | ||
export { useSelectedRouteId } from './SelectedRouteContext' | ||
export { INITIAL_DEFAULT_ROUTE, useExecutionRoute } from './useExecutionRoute' | ||
export { getLastUsedRouteId } from './getLastUsedRouteId' | ||
export { getRoute } from './getRoute' | ||
export { getRoutes } from './getRoutes' | ||
export { markRouteAsUsed } from './markRouteAsUsed' | ||
export { removeRoute } from './removeRoute' | ||
export { saveLastUsedRouteId } from './saveLastUsedRouteId' | ||
export { saveRoute } from './saveRoute' | ||
export { useRouteConnect } from './useRouteConnect' | ||
export { useRouteProvider } from './useRouteProvider' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { ExecutionRoute } from '@/types' | ||
import { saveRoute } from './saveRoute' | ||
|
||
export const markRouteAsUsed = (route: ExecutionRoute) => | ||
saveRoute({ ...route, lastUsed: Date.now() }) |
Oops, something went wrong.