bug: lndhub path

This commit is contained in:
Kieran 2023-03-02 21:56:25 +00:00
parent 9c52be315e
commit 9f763c09f8
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
4 changed files with 27 additions and 15 deletions

View File

@ -146,7 +146,7 @@ export default function WalletPage() {
<div>{(a.memo ?? "").length === 0 ? <>&nbsp;</> : a.memo}</div>
</div>
<div
className={(() => {
className={`nowrap ${(() => {
switch (a.state) {
case WalletInvoiceState.Paid:
return "success";
@ -157,7 +157,7 @@ export default function WalletPage() {
default:
return "pending";
}
})()}>
})()}`}>
{stateIcon(a.state)}
<FormattedMessage
defaultMessage="{amount} sats"
@ -175,14 +175,14 @@ export default function WalletPage() {
function walletBalance() {
if (wallet instanceof WebLNWallet) return null;
return (
<b>
<small>
<FormattedMessage
defaultMessage="Balance: {amount} sats"
values={{
amount: <FormattedNumber value={balance ?? 0} />,
}}
/>
</b>
</small>
);
}
@ -190,17 +190,16 @@ export default function WalletPage() {
if (!wallet?.isReady()) return null;
return (
<>
<h3>{info?.alias}</h3>
{walletBalance()}
<div className="card">
<h3>{info?.alias}</h3>
{walletBalance()}
</div>
{/*<div className="flex wallet-buttons">
<AsyncButton onClick={createInvoice}>
<FormattedMessage defaultMessage="Receive" description="Receive sats by generating LN invoice" />
</AsyncButton>
</div>*/}
{walletHistory()}
<button onClick={() => Wallets.remove(unwrap(walletState.config).id)}>
<FormattedMessage defaultMessage="Delete Account" />
</button>
</>
);
}
@ -211,6 +210,10 @@ export default function WalletPage() {
{walletList()}
{unlockWallet()}
{walletInfo()}
<button onClick={() => Wallets.remove(unwrap(walletState.config).id)}>
<FormattedMessage defaultMessage="Delete Account" />
</button>
</div>
);
}

View File

@ -131,14 +131,18 @@ export class LNCWallet implements LNWallet {
reversed: true,
});
console.debug(invoices);
return invoices.payments.map(a => {
const parsedInvoice = prToWalletInvoice(a.paymentRequest);
if (!parsedInvoice) {
throw new WalletError(WalletErrorCode.InvalidInvoice, `Could not parse ${a.paymentRequest}`);
}
return {
...parsedInvoice,
state: (() => {
switch (a.status) {
case Payment_PaymentStatus.SUCCEEDED:
return;
return WalletInvoiceState.Paid;
case Payment_PaymentStatus.FAILED:
return WalletInvoiceState.Failed;
default:

View File

@ -18,7 +18,7 @@ const defaultHeaders = {
export default class LNDHubWallet implements LNWallet {
type: "lndhub" | "snort";
url: string;
url: URL;
user: string;
password: string;
auth?: AuthResponse;
@ -32,13 +32,13 @@ export default class LNDHubWallet implements LNWallet {
if (!parsedUrl || parsedUrl.length !== 4) {
throw new Error("Invalid LNDHUB config");
}
this.url = new URL(parsedUrl[3]).toString();
this.url = new URL(parsedUrl[3]);
this.user = parsedUrl[1];
this.password = parsedUrl[2];
this.type = "lndhub";
} else if (url.startsWith("snort://")) {
const u = new URL(url);
this.url = `https://${u.host}${u.pathname}`;
this.url = new URL(`https://${u.host}${u.pathname}`);
this.user = "";
this.password = "";
this.type = "snort";
@ -125,10 +125,11 @@ export default class LNDHubWallet implements LNWallet {
private async getJson<T>(method: "GET" | "POST", path: string, body?: unknown): Promise<T> {
let auth = `Bearer ${this.auth?.access_token}`;
if (this.type === "snort") {
const ev = await this.publisher?.generic(`${new URL(this.url).pathname}${path}`, 30_000);
const ev = await this.publisher?.generic(`${this.url.pathname}${path}`, 30_000);
auth = JSON.stringify(ev?.ToObject());
}
const rsp = await fetch(`${this.url}${path}`, {
const url = `${this.url.pathname === "/" ? this.url.toString().slice(0, -1) : this.url.toString()}${path}`;
const rsp = await fetch(url, {
method: method,
body: body ? JSON.stringify(body) : undefined,
headers: {

View File

@ -535,6 +535,10 @@ body.scroll-lock {
font-weight: 700;
}
.nowrap {
white-space: nowrap;
}
.main-content h2 {
font-weight: 600;
font-size: 32px;