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

Fix/add host to lndhub errors #2073

Merged
merged 1 commit into from
Mar 2, 2023
Merged
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
53 changes: 30 additions & 23 deletions src/extension/background-script/connectors/lndhub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosRequestConfig, Method } from "axios";
import type { AxiosResponse } from "axios";
import type { AxiosResponse, Method } from "axios";
import axios, { AxiosRequestConfig } from "axios";
import lightningPayReq from "bolt11";
import Base64 from "crypto-js/enc-base64";
import Hex from "crypto-js/enc-hex";
Expand All @@ -12,11 +12,11 @@ import state from "../state";
import Connector, {
CheckPaymentArgs,
CheckPaymentResponse,
ConnectorInvoice,
ConnectPeerResponse,
GetBalanceResponse,
GetInfoResponse,
GetInvoicesResponse,
ConnectorInvoice,
ConnectPeerResponse,
KeysendArgs,
MakeInvoiceArgs,
MakeInvoiceResponse,
Expand Down Expand Up @@ -330,34 +330,41 @@ export default class LndHub implements Connector {

async authorize() {
const url = `${this.config.url}/auth?type=auth`;
const { data: authData } = await axios.post(
url,
{
login: this.config.login,
password: this.config.password,
},
{
headers: {
...defaultHeaders,
"X-TS": Math.floor(Date.now() / 1000),
"X-VERIFY": this.generateHmacVerification(url),
try {
const { data: authData } = await axios.post(
url,
{
login: this.config.login,
password: this.config.password,
},
}
);
{
headers: {
...defaultHeaders,
"X-TS": Math.floor(Date.now() / 1000),
"X-VERIFY": this.generateHmacVerification(url),
},
}
);

if (authData.error || authData.errors) {
const error = authData.error || authData.errors;
const errMessage = error?.errors?.[0]?.message || error?.[0]?.message;
if (authData.error || authData.errors) {
const error = authData.error || authData.errors;
const errMessage = error?.errors?.[0]?.message || error?.[0]?.message;

throw new Error(errMessage);
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
}

console.error(errMessage);
throw new Error("API error: " + errMessage);
} else {
this.refresh_token = authData.refresh_token;
this.access_token = authData.access_token;
this.refresh_token_created = +new Date();
this.access_token_created = +new Date();

return authData;
} catch (e) {
throw new Error(
`API error (${this.config.url})${
e instanceof Error ? `: ${e.message}` : ""
}`
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
);
}
}

Expand Down