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

feat: NWC connector 🤙 #2898

Merged
merged 23 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2e37ab9
feat: basic NWC connector implementation
reneaaron Nov 30, 2023
d220e98
fix: remove outdated connector template
reneaaron Nov 30, 2023
78d3d43
feat: add nwc to umbrel
reneaaron Dec 1, 2023
dc3a3f6
fix: close connection on unload
reneaaron Dec 1, 2023
a541b14
fix: more methods
reneaaron Dec 1, 2023
687547f
Merge remote-tracking branch 'upstream/master' into feat/nwc
pavanjoshi914 Dec 19, 2023
17d02d2
Merge remote-tracking branch 'origin/master' into feat/nwc
rolznz Dec 19, 2023
7b1b03a
feat: getinfo and keysend methods
pavanjoshi914 Dec 19, 2023
ac88d03
feat: improve NWC connector instructions
rolznz Dec 19, 2023
f6635b4
Merge branch 'feat/nwc' of github.com:getAlby/lightning-browser-exten…
rolznz Dec 19, 2023
5a554fd
feat: add getTransactions method
pavanjoshi914 Dec 19, 2023
d603c80
Merge branch 'feat/nwc' of github.com:getAlby/lightning-browser-exten…
rolznz Dec 19, 2023
fd71103
fix: nwc getInfo
rolznz Dec 19, 2023
5092598
fix: nwc transaction amount
rolznz Dec 19, 2023
edd91d3
fix: remove signMessage from nwc supported methods
rolznz Dec 19, 2023
2c39ecf
fix: receive invoice container larger than popup
rolznz Dec 19, 2023
6229d81
fix: response types in nwc connector methods
rolznz Dec 19, 2023
260aa9b
chore: simplify nwc instructions
rolznz Dec 19, 2023
ad26b98
chore: remove old TODO
rolznz Dec 19, 2023
74055d2
chore: add getTransaction in list of supported methods
pavanjoshi914 Dec 19, 2023
9d3997e
Merge branch 'master' into feat/nwc
reneaaron Dec 19, 2023
5cfae97
chore: bump alby js sdk version
rolznz Dec 22, 2023
cf0608e
Merge branch 'master' into feat/nwc
reneaaron Dec 22, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@bitcoin-design/bitcoin-icons-react": "^0.1.10",
"@bitcoinerlab/secp256k1": "^1.0.5",
"@getalby/sdk": "^3.1.0",
"@getalby/sdk": "^3.2.2",
"@headlessui/react": "^1.7.16",
"@lightninglabs/lnc-web": "^0.2.4-alpha",
"@noble/curves": "^1.1.0",
Expand Down Expand Up @@ -104,6 +104,7 @@
"@types/webextension-polyfill": "^0.10.5",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@webbtc/webln-types": "^3.0.0",
"autoprefixer": "^10.4.16",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^4.0.0",
Expand Down
10 changes: 10 additions & 0 deletions src/app/router/connectorRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ConnectUmbrel from "@screens/connectors/ConnectUmbrel";
import { Route } from "react-router-dom";
import i18n from "~/i18n/i18nConfig";

import ConnectNWC from "~/app/screens/connectors/ConnectNWC";
import ConnectCommando from "../screens/connectors/ConnectCommando";
import btcpay from "/static/assets/icons/btcpay.svg";
import citadel from "/static/assets/icons/citadel.png";
Expand All @@ -27,6 +28,7 @@ import lnbits from "/static/assets/icons/lnbits.png";
import lnd from "/static/assets/icons/lnd.png";
import lndhubGo from "/static/assets/icons/lndhub_go.png";
import mynode from "/static/assets/icons/mynode.png";
import nwc from "/static/assets/icons/nwc.svg";
import raspiblitz from "/static/assets/icons/raspiblitz.png";
import start9 from "/static/assets/icons/start9.png";
import umbrel from "/static/assets/icons/umbrel.png";
Expand Down Expand Up @@ -149,6 +151,12 @@ const connectorMap: { [key: string]: ConnectorRoute } = {
title: i18n.t("translation:choose_connector.btcpay.title"),
logo: btcpay,
},
nwc: {
reneaaron marked this conversation as resolved.
Show resolved Hide resolved
path: "nwc",
element: <ConnectNWC />,
title: i18n.t("translation:choose_connector.nwc.title"),
logo: nwc,
},
};

function getDistribution(key: string): ConnectorRoute {
Expand Down Expand Up @@ -188,6 +196,7 @@ const distributionMap: { [key: string]: { logo: string; children: Route[] } } =
connectorMap["lnc"],
connectorMap["commando"],
connectorMap["lnbits"],
connectorMap["nwc"],
],
},
mynode: {
Expand Down Expand Up @@ -235,6 +244,7 @@ function getConnectorRoutes(): ConnectorRoute[] {
getDistribution("mynode"),
getDistribution("start9"),
getDistribution("raspiblitz"),
connectorMap["nwc"],
];
}

Expand Down
8 changes: 5 additions & 3 deletions src/app/screens/ReceiveInvoice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ function ReceiveInvoice() {
{t("title")}
</Header>
{invoice ? (
<Container justifyBetween maxWidth="sm">
{renderInvoice()}
</Container>
<div className="h-full">
<Container justifyBetween maxWidth="sm">
{renderInvoice()}
</Container>
</div>
) : (
<div className="pt-4 h-full">
<form onSubmit={handleSubmit} className="h-full">
Expand Down
125 changes: 125 additions & 0 deletions src/app/screens/connectors/ConnectNWC/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import ConnectorForm from "@components/ConnectorForm";
import TextField from "@components/form/TextField";
import ConnectionErrorToast from "@components/toasts/ConnectionErrorToast";
import { useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import toast from "~/app/components/Toast";
import msg from "~/common/lib/msg";

import logo from "/static/assets/icons/nwc.svg";

export default function ConnectNWC() {
const navigate = useNavigate();
const { t } = useTranslation("translation", {
keyPrefix: "choose_connector.nwc",
});
const [formData, setFormData] = useState({
nostrWalletConnectUrl: "",
});
const [loading, setLoading] = useState(false);

function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
setFormData({
...formData,
[event.target.name]: event.target.value.trim(),
});
}

function getConnectorType() {
return "nwc";
}

async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setLoading(true);
const { nostrWalletConnectUrl } = formData;
const account = {
name: "NWC",
config: {
nostrWalletConnectUrl,
},
connector: getConnectorType(),
};

try {
const validation = await msg.request("validateAccount", account);
if (validation.valid) {
const addResult = await msg.request("addAccount", account);
if (addResult.accountId) {
await msg.request("selectAccount", {
id: addResult.accountId,
});
navigate("/test-connection");
}
} else {
console.error(validation);
toast.error(
<ConnectionErrorToast message={validation.error as string} />
);
}
} catch (e) {
console.error(e);
let message = t("page.errors.connection_failed");
if (e instanceof Error) {
message += `\n\n${e.message}`;
}
toast.error(message);
}
setLoading(false);
}

return (
<ConnectorForm
title={
<h1 className="text-2xl font-bold dark:text-white">
<Trans i18nKey={"title"} t={t} />
</h1>
}
description={
<Trans
i18nKey={"page.instructions"}
t={t}
components={[
// eslint-disable-next-line react/jsx-key
<a
target="_blank"
rel="noreferrer"
className="underline"
href="https://nwc.getalby.com"
></a>,
// eslint-disable-next-line react/jsx-key
<a
target="_blank"
rel="noreferrer"
className="underline"
href="https://apps.umbrel.com/app/alby-nostr-wallet-connect"
></a>,
// eslint-disable-next-line react/jsx-key
<a
target="_blank"
rel="noreferrer"
className="underline"
href="https://www.mutinywallet.com"
></a>,
]}
/>
}
logo={logo}
submitLoading={loading}
submitDisabled={formData.nostrWalletConnectUrl === ""}
onSubmit={handleSubmit}
>
<div className="mt-4 mb-6">
<TextField
id="nostrWalletConnectUrl"
label={t("page.url.label")}
placeholder={t("page.url.placeholder")}
required
onChange={handleChange}
autoFocus={true}
/>
</div>
</ConnectorForm>
);
}
5 changes: 4 additions & 1 deletion src/extension/background-script/actions/ln/checkPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { Message } from "~/types";
import state from "../../state";

const checkPayment = async (message: Message) => {
if (typeof message.args.paymentHash !== "string") {
if (
typeof message.args.paymentHash !== "string" ||
!message.args.paymentHash
) {
return {
error: "Payment hash missing.",
};
Expand Down
62 changes: 0 additions & 62 deletions src/extension/background-script/connectors/connector.example

This file was deleted.

2 changes: 2 additions & 0 deletions src/extension/background-script/connectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import NativeCitadel from "./nativecitadel";
import NativeLnBits from "./nativelnbits";
import NativeLnd from "./nativelnd";
import NativeLndHub from "./nativelndhub";
import NWC from "./nwc";

/*
const initialize = (account, password) => {
Expand All @@ -36,6 +37,7 @@ const connectors = {
nativecitadel: NativeCitadel,
commando: Commando,
alby: Alby,
nwc: NWC,
};

export default connectors;
Loading
Loading