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: add RaspiBlitz #777

Merged
merged 24 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
26d9f05
feat(connectors): add raspiblitz
secondl1ght Mar 11, 2022
da20da1
feat: add instructions
secondl1ght Mar 18, 2022
ae0fd7a
Merge branch 'master' into add-raspiblitz
secondl1ght Mar 18, 2022
75d88e1
Merge branch 'getAlby:master' into add-raspiblitz
secondl1ght Mar 18, 2022
f339b51
refactor: remove upload macaroon, update port, update textfield
secondl1ght Mar 18, 2022
6128c80
feat: add https and port for user automatically
secondl1ght Mar 21, 2022
3690ccf
Merge branch 'getAlby:master' into add-raspiblitz
secondl1ght Mar 21, 2022
e219b94
fix: update input pattern regex and message, add conditional to onChange
secondl1ght Mar 21, 2022
142dcee
Merge branch 'master' into add-raspiblitz
secondl1ght Mar 21, 2022
150a8f0
fix: change URL references to .onion address
secondl1ght Mar 21, 2022
87e065a
Merge branch 'add-raspiblitz' of github.com:secondl1ght/lightning-bro…
secondl1ght Mar 21, 2022
0354139
refactor: make 2 functions for change and remove onion validation
secondl1ght Mar 23, 2022
dbce16e
Merge branch 'getAlby:master' into add-raspiblitz
secondl1ght Mar 23, 2022
ff06931
refactor: make port configurable
secondl1ght Mar 23, 2022
d7f1aac
feat: check for http and add if not present
secondl1ght Apr 2, 2022
206d1f7
refactor: use bumi suggestion to dry handleUrl function
secondl1ght Apr 5, 2022
f256fd9
Merge branch 'add-raspiblitz' of https://github.com/secondl1ght/light…
secondl1ght Apr 5, 2022
3a819ad
fix: add raspiblitz back in after merge
secondl1ght Apr 5, 2022
304eb52
fix: delete unused code
secondl1ght Apr 5, 2022
e9a41f4
fix: filepath
secondl1ght Apr 5, 2022
7361805
refactor: move to new folder structure
secondl1ght Apr 5, 2022
0c901b1
refactor: add url variable instead of event
secondl1ght Apr 14, 2022
9fb7528
refactor: update to use new connectorform component
secondl1ght Apr 14, 2022
a1c433d
Merge branch 'master' into secondl1ght-add-raspiblitz
secondl1ght Apr 21, 2022
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: 9 additions & 1 deletion src/app/router/connectorRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import umbrel from "/static/assets/icons/umbrel.png";
import start9 from "/static/assets/icons/start9.png";
import citadel from "/static/assets/icons/citadel.png";
import mynode from "/static/assets/icons/mynode.png";

import raspiblitz from "/static/assets/icons/raspiblitz.png";
import ConnectLnd from "@screens/connectors/ConnectLnd";
import ConnectLndHub from "@screens/connectors/ConnectLndHub";
import ConnectLnbits from "@screens/connectors/ConnectLnbits";
import ConnectGaloy, { galoyUrls } from "@screens/connectors/ConnectGaloy";
import ConnectEclair from "@screens/connectors/ConnectEclair";
import ConnectCitadel from "@screens/connectors/ConnectCitadel";
import NewWallet from "@screens/connectors/NewWallet";
import ConnectRaspiBlitz from "@screens/connectors/ConnectRaspiBlitz";
import ConnectUmbrel from "@screens/connectors/ConnectUmbrel";
import ConnectStart9 from "@screens/connectors/ConnectStart9";
import ConnectMyNode from "@screens/connectors/ConnectMyNode";
Expand Down Expand Up @@ -90,6 +91,13 @@ export default [
description: "Connect to your Embassy",
logo: start9,
},
{
path: "raspiblitz",
element: <ConnectRaspiBlitz />,
title: "RaspiBlitz",
description: "Connect to your RaspiBlitz",
logo: raspiblitz,
},
{
path: galoyPaths.bitcoinBeach,
element: <ConnectGaloy instance={galoyPaths.bitcoinBeach} />,
Expand Down
143 changes: 143 additions & 0 deletions src/app/screens/connectors/ConnectRaspiBlitz/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import utils from "../../../../common/lib/utils";
secondl1ght marked this conversation as resolved.
Show resolved Hide resolved
import TextField from "../../../components/form/TextField";
secondl1ght marked this conversation as resolved.
Show resolved Hide resolved
import CompanionDownloadInfo from "../../../components/CompanionDownloadInfo";
secondl1ght marked this conversation as resolved.
Show resolved Hide resolved
import ConnectorForm from "../../../components/ConnectorForm";
secondl1ght marked this conversation as resolved.
Show resolved Hide resolved

const initialFormData = Object.freeze({
url: "",
macaroon: "",
});

export default function ConnectRaspiBlitz() {
const navigate = useNavigate();
const [formData, setFormData] = useState(initialFormData);
const [loading, setLoading] = useState(false);

function handleUrl(event: React.ChangeEvent<HTMLInputElement>) {
let url = event.target.value.trim();
if (url.substring(0, 4) !== "http") {
url = `https://${url}`;
}
setFormData({
...formData,
[event.target.name]: url,
});
}

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

function getConnectorType() {
if (formData.url.match(/\.onion/i)) {
return "nativelnd";
}
// default to LND
return "lnd";
}

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

try {
let validation;
// TODO: for native connectors we currently skip the validation because it is too slow (booting up Tor etc.)
if (account.connector === "nativelnd") {
validation = { valid: true, error: "" };
} else {
validation = await utils.call("validateAccount", account);
}

if (validation.valid) {
const addResult = await utils.call("addAccount", account);
if (addResult.accountId) {
await utils.call("selectAccount", {
id: addResult.accountId,
});
navigate("/test-connection");
}
} else {
alert(`
Connection failed. Are your RaspiBlitz credentials correct? \n\n(${validation.error})`);
}
} catch (e) {
console.error(e);
let message =
"Connection failed. Are your RaspiBlitz credentials correct?";
if (e instanceof Error) {
message += `\n\n${e.message}`;
}
alert(message);
}
setLoading(false);
}

return (
<ConnectorForm
title="Connect to your RaspiBlitz node"
description={
<p>
You need your node onion address, port, and a macaroon with read and
send permissions (e.g. admin.macaroon).
<br />
<br />
<strong>SSH</strong> into your <strong>RaspiBlitz</strong>.<br />
Run the command{" "}
<strong>sudo cat /mnt/hdd/tor/lndrest8080/hostname</strong>.
<br />
Copy and paste the <strong>.onion</strong> address in the input below.
<br />
Add your <strong>port</strong> after the onion address, the default
port is <strong>:8080</strong>.
</p>
}
submitLoading={loading}
submitDisabled={formData.url === "" || formData.macaroon === ""}
onSubmit={handleSubmit}
>
<div className="mt-6">
<TextField
id="url"
label="REST API host"
placeholder="your-node-onion-address:port"
onChange={handleUrl}
required
/>
</div>
{formData.url.match(/\.onion/i) && <CompanionDownloadInfo />}
<div className="mt-6">
<p className="mb-6 text-gray-500 mt-6 dark:text-gray-400">
Select <b>CONNECT</b>.<br />
Select <b>EXPORT</b>.<br />
Select <b>HEX</b>.<br />
Copy the <b>adminMacaroon</b>.<br />
Paste the macaroon in the input below.
</p>
<div>
<TextField
id="macaroon"
label="Macaroon (HEX format)"
value={formData.macaroon}
onChange={handleMacaroon}
required
/>
</div>
</div>
</ConnectorForm>
);
}
Binary file added static/assets/icons/raspiblitz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.