Skip to content
Merged
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
64 changes: 31 additions & 33 deletions frontend/src/screens/apps/NewApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ const NewAppInternal = ({ capabilities }: NewAppInternalProps) => {
id: "configure",
title: "Configure",
},
...(returnTo ? [] : [{ id: "finalize", title: "Finalize" }])
...(returnTo || pubkey ? [] : [{ id: "finalize", title: "Finalize" }])
),
[appStoreApp, returnTo]
[appStoreApp, returnTo, pubkey]
);

const handleCreateApp = async (nextFunc: () => void) => {
Expand Down Expand Up @@ -260,13 +260,40 @@ const NewAppInternal = ({ capabilities }: NewAppInternalProps) => {

const createAppResponse = await createApp(createAppRequest);

// 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: {
relayUrl: createAppResponse.relayUrl,
walletPubkey: createAppResponse.walletPubkey,
lud16: createAppResponse.lud16,
},
});
window.dispatchEvent(nwcEvent);

// notify the opener of the successful connection
if (window.opener) {
window.opener.postMessage(
{
type: "nwc:success",
relayUrl: createAppResponse.relayUrl,
walletPubkey: createAppResponse.walletPubkey,
lud16: createAppResponse.lud16,
},
"*"
);
}

if (createAppResponse.returnTo) {
// open connection URI directly in an app
window.location.href = createAppResponse.returnTo;
return;
}
toast("App created");
setCreateAppResponse(createAppResponse);
if (pubkey) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure we should add this navigation. For most cases either there will be a return_to or a listener for one of the success messages above (like Bitcoin Connect, which will then close the dialog)

return;
}

nextFunc();
} catch (error) {
Expand Down Expand Up @@ -306,6 +333,7 @@ const NewAppInternal = ({ capabilities }: NewAppInternalProps) => {
<Stepper.Navigation>
{methods.all.map((step) => (
<Stepper.Step
key={step.id}
of={step.id}
onClick={() =>
methods.current.id === "configure" && step.id === "install"
Expand Down Expand Up @@ -411,7 +439,7 @@ const NewAppInternal = ({ capabilities }: NewAppInternalProps) => {
</div>
),
})}
{(!methods.isLast || returnTo) && (
{(!methods.isLast || returnTo || pubkey) && (
<Stepper.Controls className="mt-6">
{!methods.isFirst && (
<Button
Expand Down Expand Up @@ -476,36 +504,6 @@ function FinalizeConnection({
}
}, [app?.lastUsedAt, navigate]);

React.useEffect(() => {
// 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: {
relayUrl: createAppResponse.relayUrl,
walletPubkey: createAppResponse.walletPubkey,
lud16: createAppResponse.lud16,
},
});
window.dispatchEvent(nwcEvent);

// notify the opener of the successful connection
if (window.opener) {
window.opener.postMessage(
{
type: "nwc:success",
relayUrl: createAppResponse.relayUrl,
walletPubkey: createAppResponse.walletPubkey,
lud16: createAppResponse.lud16,
},
"*"
);
}
}, [
createAppResponse.relayUrl,
createAppResponse.walletPubkey,
createAppResponse.lud16,
]);

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