bug: invoice amount from millisats
This commit is contained in:
@ -240,8 +240,17 @@ export const delay = (t: number) => {
|
||||
});
|
||||
};
|
||||
|
||||
export type InvoiceDetails = ReturnType<typeof decodeInvoice>;
|
||||
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,
|
||||
|
Reference in New Issue
Block a user