Skip to content

Commit

Permalink
Merge pull request getAlby#2734 from getAlby/lnurl-auth-onboard
Browse files Browse the repository at this point in the history
feat: onboarding for lnurl-auth
  • Loading branch information
rolznz authored Sep 11, 2023
2 parents 9ad8ae4 + e9f744d commit 60cdce7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/app/router/Prompt/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function Prompt() {
<Route path="public/nostr/onboard" element={<Onboard />} />
<Route path="public/liquid/onboard" element={<Onboard />} />
<Route path="public/webbtc/onboard" element={<Onboard />} />
<Route path="public/webln/onboard" element={<Onboard />} />
<Route
path="public/confirmRequestPermission"
element={<ConfirmRequestPermission />}
Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const routes = {
addAccount: accounts.promptAdd,
},
webln: {
onboard: onboard.prompt,
enable: allowances.enable,
getInfo: ln.getInfo,
sendPaymentOrPrompt: webln.sendPaymentOrPrompt,
Expand Down
14 changes: 13 additions & 1 deletion src/extension/content-script/webln.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import browser from "webextension-polyfill";

import api from "~/common/lib/api";
import extractLightningData from "./batteries";
import getOriginData from "./originData";
import shouldInject from "./shouldInject";
Expand All @@ -25,6 +26,7 @@ const disabledCalls = ["webln/enable"];

let isEnabled = false; // store if webln is enabled for this content page
let isRejected = false; // store if the webln enable call failed. if so we do not prompt again
let account;

async function init() {
const inject = await shouldInject();
Expand All @@ -49,7 +51,7 @@ async function init() {
// message listener to listen to inpage webln/webbtc calls
// those calls get passed on to the background script
// (the inpage script can not do that directly, but only the inpage script can make webln available to the page)
window.addEventListener("message", (ev) => {
window.addEventListener("message", async (ev) => {
// Only accept messages from the current window
if (
ev.source !== window ||
Expand Down Expand Up @@ -89,6 +91,16 @@ async function init() {
origin: getOriginData(),
};

// Overrides the enable action so the user can go through onboarding to setup their keys

// Overrides the enable action so the user can go through onboarding to setup their keys
if (!account || !account.hasMnemonic) {
account = await api.getAccount();
if (!account.hasMnemonic) {
messageWithOrigin.action = ev.data.action = `public/webln/onboard`;
}
}

const replyFunction = (response) => {
// if it is the enable call we store if webln is enabled for this content script
if (ev.data.action === "webln/enable") {
Expand Down

0 comments on commit 60cdce7

Please sign in to comment.