-
Notifications
You must be signed in to change notification settings - Fork 49
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
Config-based routing, wouter
v3
, custom useLocation()
/ navigate()
#556
Conversation
…ooks and entry points.
…h popup routes (so that scroll and transitions work properly).
src/popup.tsx
Outdated
</HistoryProvider> | ||
</Router> | ||
<> | ||
<Routes routes={POPUP_ROUTES} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Routes have been defined in POPUP_ROUTES
and are wrapped automatically in a Page
component by the Routes
component.
The params
are automatically passed as params
prop to all of them, so there's no need to wrap them in functions like we had before.
Additionally, the Head
component could be extracted here (just like NavigationBar
) so that it is not affected by page transitions, but that would also require adding a headProps
property to the RouterConfig
interface (for static personalization) and also creating a context and/or portal to allow for personalization coming directly from the view/page's own life cycle (for dynamic personalization).
@@ -84,6 +86,30 @@ export function AuthRequestsProvider({ | |||
[] | |||
); | |||
|
|||
const closeAuthPopup = useCallback((delay: number = 0) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change for the embedded wallet already here, but it doesn't affect the functionality in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -232,6 +134,12 @@ export async function setActiveWallet(address?: string) { | |||
export type DecryptedWallet = StoredWallet<JWKInterface>; | |||
|
|||
export async function openOrSelectWelcomePage(force = false) { | |||
if (process.env.PLASMO_PUBLIC_APP_TYPE !== "extension") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change for the embedded wallet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already added env var to GH repo 👍
active={page === i + 1} | ||
onClick={() => navigateToPage(i + 1)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be replaced with navigate(i + 1)
. See #568
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
import type { CommonRouteProps } from "~wallets/router/router.types"; | ||
import { Redirect } from "~wallets/router/components/redirect/Redirect"; | ||
|
||
const Views = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could/should be replaced with <Routes>
too. See #567.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
|
||
// Wallet generate pages: | ||
|
||
// TODO: Use a nested router instead: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could/should be implemented using <Routes>
. See #567.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
if (![1, 2, 3].includes(page)) return 1; | ||
const Views = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could/should be implemented using <Routes>
. See #567.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
<Page | ||
key={i} | ||
active={page === i + 1} | ||
onClick={() => navigate(`/start/${i + 1}`)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could/should be replaced with navigate(i+1)
. See #568.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
const currentLocation = () => window.location.hash.replace(/^#/, "") || "/"; | ||
|
||
export const useHashLocation: BaseLocationHook = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comes from wouter
now.
authType?: RouteAuthType; | ||
} | ||
|
||
export type ArConnectRoutePath = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Routes (across all apps) are now type-safe, which includes calls to navigate()
, <Link>
and <Redirect>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
key?: string; | ||
path: P; | ||
component: React.ComponentType<CommonRouteProps>; | ||
authType?: RouteAuthType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This param will probably be used for embedded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
return null; | ||
} | ||
|
||
export type NavigateAction = "prev" | "next" | "up" | number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shortcuts for common routing actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
// TODO: Consider adding `<AnimatePresence>` and `<BodyScroller>` inside here. | ||
|
||
// TODO: Consider adding a prop to `RouteConfig.parseParams` to parse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might do it later. Removes the need to parse params in the views, as parsing would be done at the router level.
})} | ||
</Switch> | ||
); | ||
}, [routes, diffLocation ? location : undefined]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diffing the location makes different views that use the same component to show a transition between the two (e.g. selecting an AuthRequest
of the same type in the Auth popup). This is off by default (as that's how it was working before).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we waiting to turn it on? 🙌
useLocation()
/ navigate()
useLocation()
/ navigate()
wouter
v3
, custom useLocation()
/ navigate()
- Move <AnimatePresence> and <BodyScroller> into <Routes>. - Fix rendering issue in <HeadAuth> making it re-render constantly. - Implement routing overrides. - Use routing overrides for the cover, loading, unlock and unlocked states of the Popup and Auth apps. - Get rid of useNowallets() and useDecryptionKey() in favour of the new useWallets() hook and <WalletsProvider>.
@7i7o A |
}); | ||
} | ||
|
||
loadAppInfo(); | ||
}, [url, appInfoProp]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing an infinite rendering loop on this component.
|
||
useEffect(() => { | ||
(async () => { | ||
const activeAddress = await getActiveAddress(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not ideal because the state won't change if the wallets are removed. Same with the useDecryptionKey
hook below. Both have been replaced with useWallets()
which gets the state from <WalletsProvider>
which subscribes to state updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK 👍
@@ -93,7 +92,7 @@ | |||
"uuid": "^9.0.0", | |||
"warp-contracts": "^1.2.13", | |||
"webextension-polyfill": "^0.10.0", | |||
"wouter": "^2.8.0-alpha.2" | |||
"wouter": "^3.3.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
export type ApplicationsDashboardViewProps = | ||
CommonRouteProps<ApplicationsDashboardViewParams>; | ||
|
||
export function ApplicationsDashboardView() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🦸
isQuickSetting | ||
}: AddContactDashboardViewProps) { | ||
const { navigate } = useLocation(); | ||
const { address } = useSearchParams<{ address: string }>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
const searchInput = useInput(); | ||
|
||
// active setting val | ||
const activeSetting = useMemo(() => params.setting, [params.setting]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
return undefined; | ||
} | ||
|
||
return new Application(decodeURIComponent(activeSubSetting)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
authType?: RouteAuthType; | ||
} | ||
|
||
export type ArConnectRoutePath = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
}, [routes]); | ||
} | ||
|
||
const memoizedRoutes = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const memoizedRoutes = useMemo(() => { | |
const memorizedRoutes = useMemo(() => { |
typo
})} | ||
</Switch> | ||
); | ||
}, [routes, diffLocation ? location : undefined]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we waiting to turn it on? 🙌
<> | ||
<BodyScroller /> | ||
|
||
<AnimatePresence initial={false}>{memoizedRoutes}</AnimatePresence> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<AnimatePresence initial={false}>{memoizedRoutes}</AnimatePresence> | |
<AnimatePresence initial={false}>{memorizedRoutes}</AnimatePresence> |
same typo
return null; | ||
} | ||
|
||
export type NavigateAction = "prev" | "next" | "up" | number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
🎉 This PR is included in version 1.21.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Page
component.<Name>View
and replace default exports with named exports.withPage
) to wrap "views" with the defaultPage
component.Page
component.<Routes>
component that renders the route config objects, and use it to all apps, including the Welcome and the Dashboard apps (but only part of their routing uses it, the rest is still done by manually checking params).useLocation()
anduseSearchParam()
hooks that wrap and extendwouter
'suseLocation()
,useSearch()
andnavigate()
functions<HistoryProvider>
component anduseHistory()
hook.ArConnectRoutePath
) and use those innavigate()
,<Redirect>
and<Link>
.wouter
to the latest version.<WalletsProvider>
anduseWallets()
hook to replace the logic insidesrc/wallets/setup/browser-extension/browser-extension-wallet-setup.hook.ts
and get rid of the olduseNoWallets()
anduseDecryptionKey()
hooks (which were not reactive).