Skip to content

Commit

Permalink
Merge pull request #3266 from getAlby/alby-hub-connector
Browse files Browse the repository at this point in the history
feat: alby hub connector
  • Loading branch information
pavanjoshi914 authored Nov 11, 2024
2 parents d040114 + 3686098 commit fd5ac46
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 3 deletions.
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: "Alby Hub",
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>
);
}
6 changes: 3 additions & 3 deletions src/i18n/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@
}
},
"nwc": {
"title": "Nostr-Wallet-Verbindung",
"title": "Nostr Wallet Connect",
"page": {
"url": {
"label": "Nostr Wallet Verbindungs-URL",
"label": "Nostr Wallet Connect-URL",
"placeholder": "nostr+walletconnect://69effe..."
},
"instructions": "Füge einen NWC-Verbindungsstring von <0>Alby Nostr Wallet Connect</0>, <1>Umbrel Nostr Wallet Connect</1> oder <2>Mutiny Wallet</2>",
"instructions": "Füge einen NWC-Verbindungsstring von <0>Nostr Wallet Connect</0>, <1>Umbrel Nostr Wallet Connect</1> oder <2>Mutiny Wallet</2>",
"errors": {
"connection_failed": "Verbindung fehlgeschlagen. Ist Ihre NWC Wallet online und wurden App Verbindungen zugelassen?"
}
Expand Down
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": "Open your Alby Hub, create a new app connection and paste the connection secret to connect.",
"url": {
"label": "NWC connection secret",
"placeholder": "nostr+walletconnect://69effe..."
},
"errors": {
"connection_failed": "Connection failed. Is your Alby Hub online and app connection enabled?"
}
}
},
"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.

0 comments on commit fd5ac46

Please sign in to comment.