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: alby hub connector #3266

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions src/app/router/connectorRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import ConnectUmbrel from "@screens/connectors/ConnectUmbrel";
import { Route } from "react-router-dom";
import i18n from "~/i18n/i18nConfig";

import ConnectAlbyHub from "~/app/screens/connectors/ConnectAlbyHub";
import ConnectNWC from "~/app/screens/connectors/ConnectNWC";
import ConnectVoltage from "~/app/screens/connectors/ConnectVoltage";
import ConnectCommando from "../screens/connectors/ConnectCommando";
import albyhub from "/static/assets/icons/albyhub.png";
import btcpay from "/static/assets/icons/btcpay.svg";
import citadel from "/static/assets/icons/citadel.png";
import core_ln from "/static/assets/icons/core_ln.svg";
Expand Down Expand Up @@ -167,6 +169,12 @@ const connectorMap: { [key: string]: ConnectorRoute } = {
title: i18n.t("translation:choose_connector.nwc.title"),
logo: nwc,
},
albyhub: {
path: "albyhub",
element: <ConnectAlbyHub />,
title: i18n.t("translation:choose_connector.albyhub.title"),
logo: albyhub,
},
lawallet: {
path: "lawallet",
element: <ConnectLaWallet />,
Expand Down Expand Up @@ -246,6 +254,7 @@ const distributionMap: { [key: string]: { logo: string; children: Route[] } } =

function getConnectorRoutes(): ConnectorRoute[] {
return [
connectorMap["albyhub"],
connectorMap["lnd"],
connectorMap["lnc"],
connectorMap["commando"],
Expand Down
125 changes: 125 additions & 0 deletions src/app/screens/connectors/ConnectAlbyHub/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/albyhub.png";

export default function ConnectAlbyHub() {
const navigate = useNavigate();
const { t } = useTranslation("translation", {
keyPrefix: "choose_connector.albyhub",
});
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: "AlbyHub",
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>
);
}
13 changes: 13 additions & 0 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,19 @@
"connection_failed": "Connection failed. Are your credentials correct?"
}
},
"albyhub": {
"title": "Alby Hub",
"page": {
"instructions": "Paste a NWC connection secret from Alby Hub",
"url": {
"label": "NWC connection secret from Alby Hub",
"placeholder": "nostr+walletconnect://69effe..."
},
"errors": {
"connection_failed": "Connection failed. Is your Alby Hub online and app connection enabled?"
reneaaron marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
"nwc": {
"title": "Nostr Wallet Connect",
"page": {
Expand Down
Binary file added static/assets/icons/albyhub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading