Skip to content

feat: add getInvoiceAge and getFundingVelocity to invoiceStats (Closes #611) - #625

Open
waterWang wants to merge 1 commit into
Stellar-split:mainfrom
waterWang:feat/611-invoice-stats
Open

feat: add getInvoiceAge and getFundingVelocity to invoiceStats (Closes #611)#625
waterWang wants to merge 1 commit into
Stellar-split:mainfrom
waterWang:feat/611-invoice-stats

Conversation

@waterWang

Copy link
Copy Markdown

Closes #611

Summary

Adds getInvoiceAge and getFundingVelocity helper functions to src/invoiceStats.ts for computing derived invoice metrics from existing Invoice fields without network calls.

Changes

src/invoiceStats.ts

  • getInvoiceAge(invoice): Returns { days, hours, minutes } since createdAt. Uses Date.now() internally.
  • getFundingVelocity(invoice): Returns USDC funded per day since creation. Returns 0 if createdAt is within the same second as Date.now() (prevents division by zero).
  • Both handle createdAt as either Unix timestamp (seconds) or milliseconds — auto-detected by magnitude (> 1e12 = ms).

Supporting changes

  • src/types.ts: Added createdAt: number to Invoice type
  • src/client.ts: Updated _parseInvoice to parse createdAt from raw contract data
  • src/testing/factories.ts and src/testing/mockFactory.ts: Added createdAt to mock invoice factories
  • src/index.ts: Public API export

Tests

  • test/invoiceStats.test.ts: 7 unit tests covering age, velocity, zero-age guard, and timestamp format auto-detection

All 7 tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add getInvoiceAge and getFundingVelocity to invoiceStats

1 participant