Skip to content

Fix/issue 180 - #421

Open
Chigybillionz wants to merge 9 commits into
AnchorNet-Org:mainfrom
Chigybillionz:fix/issue-180
Open

Fix/issue 180#421
Chigybillionz wants to merge 9 commits into
AnchorNet-Org:mainfrom
Chigybillionz:fix/issue-180

Conversation

@Chigybillionz

@Chigybillionz Chigybillionz commented Jul 30, 2026

Copy link
Copy Markdown
Contributor
Close #180 

### Summary of the issue
The `fetchSettlements` and `exportSettlementsCsv` functions in `src/lib/settlementsApi.ts` duplicated the logic to construct query parameters using `URLSearchParams` from the identical `FetchSettlementsOptions` payload, which was error-prone and not scalable.
---
### Root cause
There was a lack of a shared helper utility to convert structured query options into a standardized URL query string, leading to inline repetitive `.set(...)` configurations in every API function requiring URL parameters.

### Solution implemented
- Implemented a shared `buildQueryParams` helper in `src/lib/api.ts` that safely constructs the URL query string, filters out undefined parameters, and retains identical behavior as the previously duplicated code.
- Refactored both `fetchSettlements` and `exportSettlementsCsv` in `src/lib/settlementsApi.ts` to use this new `buildQueryParams` helper, drastically removing their duplicated inline `URLSearchParams` code.
---
### Key changes made
- Updated `fetchSettlements` and `exportSettlementsCsv` inside `src/lib/settlementsApi.ts` to replace inline configurations with `buildQueryParams`.
- Added the missing `apiTextRequest` import inside `src/lib/settlementsApi.ts`.
- Restored the missing `isAbortError` function definition in `src/lib/api.ts` that was inadvertently lost in a prior commit, resolving test suite regressions.
---
### Any trade-offs or considerations
This is a pure refactor with no new dependencies. It maintains complete backwards compatibility for existing query endpoints and sets up a robust utility for future API calls (such as in `anchorsApi.ts`) to consume seamlessly as filter parameters increase.
---
### Testing steps (how to verify the fix)
1. Pull this branch and ensure you're on the latest commit.
2. Run the test suite: `npx vitest run src/lib/settlementsApi.test.ts src/lib/api.test.ts`
3. Verify that all tests pass, ensuring that request URLs are generated identically as before and the abort/retry logic is functioning properly.
---
Please kindly review this task. If there are any corrections, improvements, adjustments, or merge conflicts that you notice regarding my implementation, I'd really appreciate your feedback. I'd also love to hear your overall review of my work on this branch.Thank you!

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.

2 participants