bug: invoice amount from millisats
This commit is contained in:
parent
840e2ff400
commit
33bbadeda8
@ -66,7 +66,7 @@ export default function Invoice(props: InvoiceProps) {
|
||||
<p className="invoice-amount">
|
||||
{amount > 0 && (
|
||||
<>
|
||||
{amount.toLocaleString()} <span className="sats">sat{amount === 1 ? "" : "s"}</span>
|
||||
{(amount / 1_000).toLocaleString()} <span className="sats">sat{amount === 1_000 ? "" : "s"}</span>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user