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: use browser router in http mode #1009

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { RouterProvider, createHashRouter } from "react-router-dom";
import {
RouterProvider,
createBrowserRouter,
createHashRouter,
} from "react-router-dom";

import { ThemeProvider } from "src/components/ui/theme-provider";

import { Toaster } from "src/components/ui/toaster";
import { TouchProvider } from "src/components/ui/tooltip";
import { useInfo } from "src/hooks/useInfo";
import routes from "src/routes.tsx";
import { isHttpMode } from "src/utils/isHttpMode";

const router = createHashRouter(routes);
const createRouterFunc = isHttpMode() ? createBrowserRouter : createHashRouter;
const router = createRouterFunc(routes);

function App() {
const { data: info } = useInfo();
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/SuggestedAppData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export const suggestedApps: SuggestedApp[] = [
<li>
4. Click{" "}
<Link
to="/#/apps/new?app=btcpay"
to="/apps/new?app=btcpay"
className="font-medium text-foreground underline"
>
Connect to BTCPay Server
Expand Down Expand Up @@ -492,7 +492,7 @@ export const suggestedApps: SuggestedApp[] = [
<li>
4. Click{" "}
<Link
to="/#/apps/new?app=lnbits"
to="/apps/new?app=lnbits"
className="font-medium text-foreground underline"
>
Connect to LNbits
Expand Down Expand Up @@ -569,7 +569,7 @@ export const suggestedApps: SuggestedApp[] = [
<li>
4. Click{" "}
<Link
to="/#/apps/new?app=coracle"
to="/apps/new?app=coracle"
className="font-medium text-foreground underline"
>
Connect to Coracle
Expand Down Expand Up @@ -639,7 +639,7 @@ export const suggestedApps: SuggestedApp[] = [
<li>
3. Click{" "}
<Link
to="/#/apps/new?app=nostter"
to="/apps/new?app=nostter"
className="font-medium text-foreground underline"
>
Connect to Nostter
Expand Down
19 changes: 13 additions & 6 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "src/App.tsx";
import "src/index.css";
import "src/fonts.css";
import "src/index.css";
import { isHttpMode } from "src/utils/isHttpMode";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// redirect hash router links to browser router links
// TODO: remove after 2026-01-01
if (isHttpMode() && window.location.href.indexOf("/#/") > -1) {
window.location.href = window.location.href.replace("/#/", "/");
} else {
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
}
10 changes: 7 additions & 3 deletions frontend/src/screens/apps/AppCreated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,24 @@ function AppCreatedInternal() {
}
// dispatch a success event which can be listened to by the opener or by the app that embedded the webview
// this gives those apps the chance to know the user has enabled the connection
const nwcEvent = new CustomEvent("nwc:success", { detail: {} });
const nwcEvent = new CustomEvent("nwc:success", {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually consume this custom event anywhere?

I know window.opener.postMessage is consumed by Alby JS SDK. Do we need both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, maybe this one is for a native app (I need to test it)

detail: {
nostrWalletConnectUrl: pairingUri,
},
});
window.dispatchEvent(nwcEvent);

// notify the opener of the successful connection
if (window.opener) {
window.opener.postMessage(
{
type: "nwc:success",
payload: { success: true },
nostrWalletConnectUrl: pairingUri,
},
"*"
);
}
}, [appstoreApp]);
}, [appstoreApp, pairingUri]);

if (!createAppResponse) {
return <Navigate to="/apps/new" />;
Expand Down
Loading