From cb53330e8f5f33e602073eb25c21ec243261ce15 Mon Sep 17 00:00:00 2001 From: ajaysehwal Date: Sat, 1 Aug 2026 20:06:37 +0530 Subject: [PATCH] fix(nwc): derive CLN lookup created_at from BOLT11 timestamp --- models/Invoice.ts | 8 +++++++- utils/NostrConnectUtils.test.ts | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/models/Invoice.ts b/models/Invoice.ts index 2c565fe92..17b892bfd 100644 --- a/models/Invoice.ts +++ b/models/Invoice.ts @@ -359,7 +359,13 @@ export default class Invoice extends BaseModel { } @computed public get getCreationDate(): Date { - return DateTimeUtils.listDate(this.created_at || this.creation_date); + // CLN listinvoices omits created_at; fall back to the BOLT11 timestamp + return DateTimeUtils.listDate( + this.created_at || + this.creation_date || + this.decodedPaymentRequest?.timestamp || + 0 + ); } @computed public get formattedCreationDate(): string { diff --git a/utils/NostrConnectUtils.test.ts b/utils/NostrConnectUtils.test.ts index bc55209ae..4743ebef3 100644 --- a/utils/NostrConnectUtils.test.ts +++ b/utils/NostrConnectUtils.test.ts @@ -837,6 +837,27 @@ describe('NostrConnectUtils', () => { expect(tx.state).not.toBe('settled'); expect(tx.settled_at).toBe(0); }); + + it('derives created_at from BOLT11 when CLN listinvoices omits a creation timestamp', () => { + // Real CLN listinvoices shape: no created_at/creation_date + const BOLT11 = + 'lnbcrt1230n1pj429x7pp57t97q4awqj3f529snr0pa6senk83sq5pp760qf5a4jzvd7xgwcksdqqcqzzsxqrrsssp57eqtv7vxr46arupna3w4ct0lkf2mqmz9wt044cwkks0rwlnhfr5s9qyyssqragwpwav7nfwv2xyuuamxxj4pnnpzv2hlw7j473repd3sq7st698ta9kmzmygt0w7tmncl56a6mnma0w7e5dlpqd0wy6x3v35rssldspjhh8p0'; + const BOLT11_TIMESTAMP = 1700074718; + const tx = lookupLightningInvoice({ + label: 'zeus.123456', + bolt11: BOLT11, + payment_hash: + 'f2cbe056ae04a29a28b098de1eea199d8f1802900fb4f0269dac84c6f8c8762d', + amount_msat: 123000, + status: 'unpaid', + description: 'test invoice', + expires_at: BOLT11_TIMESTAMP + EXPIRY_SECONDS, + created_index: 7 + }); + + expect(tx.created_at).toBe(BOLT11_TIMESTAMP); + expect(tx.expires_at).toBe(BOLT11_TIMESTAMP + EXPIRY_SECONDS); + }); }); describe('list_transactions', () => {