Skip to content

Commit

Permalink
feat: added LND connect URL for REST API (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
NehaK745 authored Aug 31, 2021
1 parent 1c5d864 commit 9f68059
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

lint-staged
yarn lint-staged
4 changes: 2 additions & 2 deletions src/components/designer/lightning/LightningDetails.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ describe('LightningDetails', () => {
fireEvent.click(await findByText('Connect'));
await waitFor(() => getByText('TLS Cert'));
toggle(container, 'lndc');
await waitFor(() => getByText('Admin Macaroon Url'));
await waitFor(() => getByText('GRPC Admin Macaroon Url'));
expect(files.read).toBeCalledTimes(4);
expect(getAllByText(/lndconnect/)).toHaveLength(3);
expect(getAllByText(/lndconnect/)).toHaveLength(6);
});

it('should display and error if getting the LND Connect url fails', async () => {
Expand Down
20 changes: 16 additions & 4 deletions src/components/designer/lightning/connect/LndConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,28 @@ const LndConnect: React.FC<Props> = ({ node }) => {
const { tlsCert, adminMacaroon, invoiceMacaroon, readonlyMacaroon } = node.paths;
try {
const host = `127.0.0.1:${node.ports.grpc}`;
const resthost = `127.0.0.1:${node.ports.rest}`;

const cert = await read(tlsCert);
const adminMac = await read(adminMacaroon, 'hex');
const invoiceMac = await read(invoiceMacaroon, 'hex');
const readonlyMac = await read(readonlyMacaroon, 'hex');

const values: Record<string, string> = {};
values[l('adminUrl')] = encode({ host, cert, macaroon: adminMac });
values[l('invoiceUrl')] = encode({ host, cert, macaroon: invoiceMac });
values[l('readOnlyUrl')] = encode({ host, cert, macaroon: readonlyMac });

values[l('grpcAdminUrl')] = encode({ host, cert, macaroon: adminMac });
values[l('grpcInvoiceUrl')] = encode({ host, cert, macaroon: invoiceMac });
values[l('grpcReadOnlyUrl')] = encode({ host, cert, macaroon: readonlyMac });
values[l('restAdminUrl')] = encode({ host: resthost, cert, macaroon: adminMac });
values[l('restInvoiceUrl')] = encode({
host: resthost,
cert,
macaroon: invoiceMac,
});
values[l('restReadOnlyUrl')] = encode({
host: resthost,
cert,
macaroon: readonlyMac,
});
setUrls(values);
} catch (error) {
notify({ message: l('encodeError'), error });
Expand Down
9 changes: 6 additions & 3 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@
"cmps.designer.lightning.connect.EncodedStrings.invoiceMacaroon": "Invoice Macaroon",
"cmps.designer.lightning.connect.EncodedStrings.readOnlyMacaroon": "Read-only Macaroon",
"cmps.designer.lightning.connect.EncodedStrings.error": "Failed to encode file contents",
"cmps.designer.lightning.connect.LndConnect.adminUrl": "Admin Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.invoiceUrl": "Invoice Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.readOnlyUrl": "Read-only Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.grpcAdminUrl": "GRPC Admin Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.grpcInvoiceUrl": "GRPC Invoice Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.grpcReadOnlyUrl": "GRPC Read-only Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.restAdminUrl": "REST Admin Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.restInvoiceUrl": "REST Invoice Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.restReadOnlyUrl": "REST Read-only Macaroon Url",
"cmps.designer.lightning.connect.LndConnect.encodeError": "Unable to create LND Connect url",
"cmps.designer.lightning.connect.BasicAuth.username": "Username",
"cmps.designer.lightning.connect.BasicAuth.password": "Password",
Expand Down

0 comments on commit 9f68059

Please sign in to comment.