diff --git a/packages/app/src/Element/Invoice.tsx b/packages/app/src/Element/Invoice.tsx
index f961375b..2d6d1251 100644
--- a/packages/app/src/Element/Invoice.tsx
+++ b/packages/app/src/Element/Invoice.tsx
@@ -66,7 +66,7 @@ export default function Invoice(props: InvoiceProps) {
{amount > 0 && (
<>
- {amount.toLocaleString()} sat{amount === 1 ? "" : "s"}
+ {(amount / 1_000).toLocaleString()} sat{amount === 1_000 ? "" : "s"}
>
)}
diff --git a/packages/app/src/Util.ts b/packages/app/src/Util.ts
index 137d95b0..fb206015 100644
--- a/packages/app/src/Util.ts
+++ b/packages/app/src/Util.ts
@@ -240,8 +240,17 @@ export const delay = (t: number) => {
});
};
-export type InvoiceDetails = ReturnType;
-export function decodeInvoice(pr: string) {
+export interface InvoiceDetails {
+ amount?: number;
+ expire?: number;
+ timestamp?: number;
+ description?: string;
+ descriptionHash?: string;
+ paymentHash?: string;
+ expired: boolean;
+}
+
+export function decodeInvoice(pr: string): InvoiceDetails | undefined {
try {
const parsed = invoiceDecode(pr);
@@ -249,17 +258,17 @@ export function decodeInvoice(pr: string) {
const amount = amountSection ? Number(amountSection.value as number | string) : undefined;
const timestampSection = parsed.sections.find(a => a.name === "timestamp");
- const timestamp = timestampSection ? (timestampSection.value as number) : NaN;
+ const timestamp = timestampSection ? Number(timestampSection.value as number | string) : undefined;
const expirySection = parsed.sections.find(a => a.name === "expiry");
- const expire = expirySection ? (expirySection.value as number) : NaN;
+ const expire = expirySection ? Number(expirySection.value as number | string) : undefined;
const descriptionSection = parsed.sections.find(a => a.name === "description")?.value;
const descriptionHashSection = parsed.sections.find(a => a.name === "description_hash")?.value;
const paymentHashSection = parsed.sections.find(a => a.name === "payment_hash")?.value;
const ret = {
amount: amount,
- expire: !isNaN(timestamp) && !isNaN(expire) ? timestamp + expire : undefined,
- timestamp: !isNaN(timestamp) ? timestamp : undefined,
+ expire: timestamp && expire ? timestamp + expire : undefined,
+ timestamp: timestamp,
description: descriptionSection as string | undefined,
descriptionHash: descriptionHashSection ? bytesToHex(descriptionHashSection as Uint8Array) : undefined,
paymentHash: paymentHashSection ? bytesToHex(paymentHashSection as Uint8Array) : undefined,
diff --git a/packages/app/src/Wallet/index.ts b/packages/app/src/Wallet/index.ts
index a53377e0..c0632777 100644
--- a/packages/app/src/Wallet/index.ts
+++ b/packages/app/src/Wallet/index.ts
@@ -85,8 +85,8 @@ export function prToWalletInvoice(pr: string) {
return {
amount: parsedInvoice.amount ?? 0,
memo: parsedInvoice.description,
- paymentHash: parsedInvoice.paymentHash,
- timestamp: parsedInvoice.timestamp,
+ paymentHash: parsedInvoice.paymentHash ?? "",
+ timestamp: parsedInvoice.timestamp ?? 0,
state: parsedInvoice.expired ? WalletInvoiceState.Expired : WalletInvoiceState.Pending,
pr,
} as WalletInvoice;