Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove tokens minLiquidity filter when value is 0 #93

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PortalsFiTokenOffChainDataProvider } from "./portalsFiTokenOffChainData

const MIN_TOKENS_LIQUIDITY_FILTER = 0;
const TOKENS_INFO_API_URL = "https://api.portals.fi/v2/tokens";
const TOKENS_INFO_API_QUERY = `networks=ethereum&limit=250&sortBy=liquidity&minLiquidity=${MIN_TOKENS_LIQUIDITY_FILTER}&sortDirection=desc`;
const TOKENS_INFO_API_QUERY = `networks=ethereum&limit=250&sortBy=liquidity&sortDirection=desc`;

const providerTokensResponse = [
{
Expand Down Expand Up @@ -140,6 +140,25 @@ describe("PortalsFiTokenOffChainDataProvider", () => {
]);
});

it("includes minLiquidity filter when provided minLiquidity filter > 0", async () => {
pipeMock.mockReturnValueOnce(
new rxjs.Observable((subscriber) => {
subscriber.next({
data: {
more: false,
tokens: [providerTokensResponse[0]],
},
});
})
);

await provider.getTokensOffChainData(1000000);
expect(httpServiceMock.get).toBeCalledTimes(1);
expect(httpServiceMock.get).toBeCalledWith(
`${TOKENS_INFO_API_URL}?${TOKENS_INFO_API_QUERY}&page=0&minLiquidity=1000000`
);
});

it("retries when provider API call fails", async () => {
pipeMock
.mockImplementationOnce((callback) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ export class PortalsFiTokenOffChainDataProvider implements TokenOffChainDataProv
page: number;
minLiquidity: number;
}): Promise<ITokensOffChainDataPage> {
const queryString = `networks=ethereum&limit=250&sortBy=liquidity&minLiquidity=${minLiquidity}&sortDirection=desc&page=${page}`;
const query = {
networks: "ethereum",
limit: "250",
sortBy: "liquidity",
sortDirection: "desc",
page: page.toString(),
...(minLiquidity && {
minLiquidity: minLiquidity.toString(),
}),
};
const queryString = new URLSearchParams(query).toString();

const { data } = await firstValueFrom<{ data: ITokensOffChainDataProviderResponse }>(
this.httpService.get(`${TOKENS_INFO_API_URL}?${queryString}`).pipe(
Expand Down
Loading