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): add connect via settings #632 #640

Merged
merged 14 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ jobs:
run: yarn build
- name: Run Tests
run: yarn test
- name: Run Typecheck
cstenglein marked this conversation as resolved.
Show resolved Hide resolved
run: yarn tsc
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ Please do not commit the above changes.
- [MIT License (?)](https://github.com/lightningnetwork/lnd/blob/master/LICENSE)
- Core Lightning Logo from [Blockstream](https://blockstream.com/)
- [Blockstream Corporate Brand Guideline](https://blockstream.com/brand-assets/)
- Alby Logo from [Alby media repo](https://github.com/getAlby/media)
- License unclear
23 changes: 23 additions & 0 deletions backend-mock/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,27 @@ router.get("/get-debug-logs-raw", (req, res) => {
res.status(200).send(logs.toString());
});

router.get("/connection-info", (req, res) => {
console.info(`call to ${req.originalUrl}`);
const lndInfo = {
lnd_admin_macaroon:
"0201036C6E6402F801030A10B9BC5746E0F52F441BE2BF3B75A1C1EC1201301A160A0761646472657373120472656164120577726974651A130A04696E666F120472656164120577726974651A170A08696E766F69636573120472656164120577726974651A210A086D616361726F6FD634804926E441E8C730F92AE0C10E5732EE20EB6D6DE",
lnd_invoice_macaroon:
"0201036C6E640258030A10B7BC5746E0F52F441BE2BF3B75A1C1EC1201301A160A0761646472657373120472656164120577726974651A170A08696E766F6963657312047",
lnd_readonly_macaroon:
"0201036C6E6402AC01030A10B8BC5746E0F52F441BE2BF3B75A1C1EC1201301A0F0A07616464726573731204726561641A0C0A04696E666F1204726561641A100A08696E766F696365731204726561641A100A086D616361726F6F6E1204726561641A0F0A076D6573736167651204726561641A100A086F6666636861696E1204726561641A0F0A076F6E636861696E1204726561641A0D0A0570656572731204726561641A0E0A067369676E65721204726561640000062065950AD6F3E7C234B5E76B9EC58838180AB9296F99D49F9C0396C9138",
lnd_rest_onion:
"7hyube57cxcd47lcgrihujaevtsqlgd5ga34l637rgsyvd32x6.onion:8080",
lnd_tls_cert:
"2D2D2D2D2D424547494E2043455254494649434154452D2D2D2D2D0A4D494943436A434341624367417749424167495156505242734D556F4D37443532634574762B6671696A414B42676771686B6A4F50515144416A41314D5238770A485159445651514B45785A73626D5167595856306232646C626D56795958526C5A43426A5A584A304D52497745415944565151444760A633351774868634E4D6A45774F4449334D546B304D7A51775768634E4D6A49784D4449794D546B304D7A5177576A41314D523877485159445651514B45785A730A626D5167595856306232646C626D56795958526C5A43426A5A584A304D524977454159445651514445776C7362324E68624768766333517757544154426763710A686B6A4F5051494242676771686B6A4F50514D4242774E434141512B4A42564C363634484C58346F4F78482F534C705A61584E4E474F775657496E44373058310A4745426F425341492F3177372B354D635855694F6E554552793041524641304E366D354E4B666B502B346130586E79566F3447684D4947654D413447413155640A447745422F775145417749437044415442674E56485355454444414B4267677242674546425163444154415042674E5648524D4241663845425441444151482F0A4D42304741315564446751574242513946686E4B31517256705670344E68746A4A66323567584262687A424842674E56485245455144412B67676C7362324E680A62476876633353434248567561586943436E56756158687759574E725A56D364842483841414147484541414141414141414141410A414141414141414141414577436759494B6F5A497A6A3045417749445341417752514968414A726D33786478504C737444382F466B61554A68534846375375740A7A2B344776524A512F637A4876326836416941383677627747782F4C624A5074716342476E773639626C73507A6646496F2F3072434F636C4F754F5248773D3D0A2D2D2D2D2D454E44204345525449464943415445",
lnd_btcpay_connection_string: "",
lnd_zeus_connection_string:
"lndconnect://7hyube57cxcd47lcgrihujaevtsql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cBGnw69blsPzfFIo",
cl_rest_zeus_connection_string: "",
cl_rest_macaroon: "",
cl_rest_onion: "",
};
res.status(200).send(lndInfo);
});

module.exports = router;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"postinstall": "husky install",
"start": "vite",
"build": "vite build",
"tsc": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest watch",
"coverage": "vitest run --coverage"
Expand Down
Binary file added public/assets/apps/logos/alby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
declare global {
// for more detailed type-info see:
// https://github.com/getAlby/lightning-browser-extension/blob/master/src/extension/providers/alby/index.ts#L3
interface Window {
alby?: {
enable: () => Promise<void>;
addAccount: (params: {
name: string;
connector: string;
config: Record<string, unknown>;
}) => Promise<{ success: boolean }>;
};
}
}

export {};
14 changes: 14 additions & 0 deletions src/i18n/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
"jam": {
"about": "Jam is a web interface for JoinMarket focusing on user-friendliness and ease-of-use. It aims to provide sensible defaults and be easy to use for beginners while still having the features advanced users expect.",
"shortDescription": "Jam - A web interface for JoinMarket"
},
"alby": {
"about": "Alby Browser Extension",
"shortDescription": "Connect your RaspiBlitz LND node and use Bitcoin & Nostr apps with the Alby Extension",
"action": {
"install": "Install Alby",
"addAccount": "Connect",
"connection_info_error": "Could not get connection info",
"connection": {
"hint": "Please install the Alby extension first",
"success": "Raspiblitz account was added to Alby",
"error": "Adding Raspiblitz to Alby didn't work, please try again"
}
}
}
},
"apps": {
Expand Down
38 changes: 0 additions & 38 deletions src/i18n/langs/en_appInfo.json

This file was deleted.

101 changes: 101 additions & 0 deletions src/pages/Apps/AppCardAlby.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { PlusIcon, LinkIcon } from "@heroicons/react/24/outline";
import { FC } from "react";
import { useTranslation } from "react-i18next";
import AppIcon from "../../components/AppIcon";
import { toast } from "react-toastify";
import { instance } from "../../utils/interceptor";

export const AppCardAlby: FC = () => {
const { id, name } = {
id: "alby",
name: "Alby",
};

const { t } = useTranslation();

const addAlbyAccountHandler = async () => {
const resp = await instance.get("/system/connection-info");

if (
resp.status !== 200 ||
!resp.data.lnd_admin_macaroon ||
!resp.data.lnd_rest_onion
) {
toast.error(t(`appInfo.${id}.action.connection_info_error`));
return;
}

const { lnd_admin_macaroon, lnd_rest_onion } = resp.data;

const albyProvider = window.alby;

if (!albyProvider) {
toast.error(t(`appInfo.${id}.action.connection.hint`));
return;
}

try {
await albyProvider.enable();

const result = await albyProvider.addAccount({
name: "⚡️ Raspiblitz",
connector: "lnd",
config: {
adminkey: lnd_admin_macaroon,
url: lnd_rest_onion,
},
});

if (result.success) {
toast.success(t(`appInfo.${id}.action.connection.success`));
} else {
toast.error(t(`appInfo.${id}.action.connection.error`));
}
} catch (e) {
toast.error(t(`appInfo.${id}.action.connection.error`));
}
};

return (
<div className="bd-card transition-colors dark:bg-gray-800">
<div className="relative mt-2 flex h-4/6 w-full flex-row items-center">
{/* Icon */}
<div className="mt-4 flex w-1/4 items-center justify-center p-2">
<AppIcon appId={id} className="max-h-12" />
</div>
{/* Content */}
<div className="mt-4 flex w-3/4 flex-col items-start justify-center text-xl">
<h4>{name}</h4>
<p className="overflow-ellipsis text-base text-gray-500 dark:text-gray-200">
{t(`appInfo.${id}.shortDescription`)}
</p>
</div>
</div>
<div className="flex flex-row justify-center gap-2 py-4">
{window.alby && (
<button
className="bd-button flex w-1/2 items-center justify-center p-2 disabled:pointer-events-none"
onClick={addAlbyAccountHandler}
>
<LinkIcon className="inline h-6 w-6" />
&nbsp;{t(`appInfo.${id}.action.addAccount`)}
</button>
)}

{!window.alby && (
<a
className="bd-button flex w-1/2 items-center justify-center p-2 disabled:pointer-events-none"
target="_blank"
rel="noreferrer"
href="https://getalby.com"
>
<PlusIcon className="inline h-6 w-6" />
{t(`appInfo.${id}.action.install`)}
</a>
)}
</div>
</div>
);
};

export default AppCardAlby;
5 changes: 5 additions & 0 deletions src/pages/Apps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { availableApps } from "../../utils/availableApps";
import { checkError } from "../../utils/checkError";
import { instance } from "../../utils/interceptor";
import AppCard from "./AppCard";
import AppCardAlby from "./AppCardAlby";
import AppInfo from "./AppInfo";

export const Apps: FC = () => {
Expand Down Expand Up @@ -121,6 +122,10 @@ export const Apps: FC = () => {
</article>
);
})}

<article>
<AppCardAlby />
</article>
</div>
</section>
</>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Home/SendModal/__tests__/SendModal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import userEvent from "@testing-library/user-event";
import { UserEvent } from "@testing-library/user-event/dist/types/setup";
import type { UserEvent } from "@testing-library/user-event/dist/types/setup/setup";
import { render, screen } from "test-utils";
import { rest, server } from "../../../../testServer";
import SendModal, { Props } from "../SendModal";
Expand Down Expand Up @@ -115,6 +115,7 @@ describe("SendModal", () => {
describe("SendOnChain", () => {
let user: UserEvent;
// switch to onchain modal

beforeEach(async () => {
user = userEvent.setup();
setup();
Expand Down
8 changes: 5 additions & 3 deletions src/pages/Settings/ActionBox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FC } from "react";
import type { FC, ReactElement } from "react";

export type Props = {
name: string;
name: string | ReactElement;
actionName: string;
action: () => void;
};
Expand All @@ -11,7 +11,9 @@ const ActionBox: FC<Props> = ({ name, action, actionName }) => {
<div className="box-border w-full transition-colors dark:text-white">
<article className="relative rounded bg-white p-5 shadow-xl dark:bg-gray-800">
<div className="flex justify-between">
<h4 className="flex w-1/2 items-center font-bold xl:w-2/3">{name}</h4>
<h4 className="flex w-1/2 items-center font-bold xl:w-2/3">
<span>{name}</span>
</h4>
<button className="bd-button w-1/2 py-1 xl:w-1/3" onClick={action}>
{actionName}
</button>
Expand Down
3 changes: 3 additions & 0 deletions src/utils/__tests__/checkError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vi.mock("i18next", () => ({
describe("checkError", () => {
it("should display the message with basic detail object", () => {
const errorMsg = checkError({
// @ts-ignore response is not a full "AxiosResponse<ApiError, any>" type currently
response: {
data: {
detail: "old password format invalid",
Expand All @@ -18,6 +19,7 @@ describe("checkError", () => {

it("should display the message with detail.msg object", () => {
const errorMsg = checkError({
// @ts-ignore response is not a full "AxiosResponse<ApiError, any>" type currently
response: {
data: {
detail: [
Expand All @@ -40,6 +42,7 @@ describe("checkError", () => {

it("should display the message with detail as an array", () => {
const errorMsg = checkError({
// @ts-ignore
cstenglein marked this conversation as resolved.
Show resolved Hide resolved
response: {
data: {
detail: [
Expand Down