fix(wallet): clamp transaction limit#329
Conversation
Greptile SummaryThis PR fixes a gap in the wallet transactions route where negative
Confidence Score: 5/5Safe to merge — the change is tightly scoped to query-parameter normalisation and the new logic is fully covered by the accompanying tests. The parseLimit helper correctly handles every edge case: null/empty → 50, non-numeric (NaN, 'abc') → 50, negatives → 1, zero → 1, floats → truncated, oversized → 100. All paths are exercised by the test suite, and the rest of the route handler is unchanged. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["GET /api/wallet/transactions\n?limit=<value>"] --> B{Auth valid?}
B -- No --> C["401 Unauthorized"]
B -- Yes --> D["parseLimit(value)"]
D --> E{value null or\nwhitespace-only?}
E -- Yes --> F["use 50 as input"]
E -- No --> G["Number(value)"]
F --> H["Number(50) = 50"]
G --> I{isFinite?}
I -- No --> J["use 50"]
I -- Yes --> K["Math.trunc(parsed)"]
H --> K
J --> K
K --> L["Math.max(truncated, 1) clamp >= 1"]
L --> M["Math.min(result, 100) clamp <= 100"]
M --> N["fetch LNbits /api/v1/payments?limit=N"]
N --> O{lnWallet found?}
O -- No --> P["Return empty list"]
O -- Yes --> Q{LNbits ok?}
Q -- No --> P
Q -- Yes --> R["Filter + map payments Return 200"]
Reviews (2): Last reviewed commit: "test(wallet): cover transaction limit pa..." | Re-trigger Greptile |
Summary
Fixes #328.
Testing