Skip to content

Commit

Permalink
[FEAT] : Improve Market for Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mcayuelas-ledger committed Jul 18, 2024
1 parent 53e9dd4 commit 00e7703
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-melons-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Improve Search for Market when >=2 chars
5 changes: 5 additions & 0 deletions .changeset/polite-bananas-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Lowercase search on market
5 changes: 5 additions & 0 deletions .changeset/rare-windows-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Lower case search + add debounce on Market Search
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/src/renderer/reducers/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const initialState: MarketState = {
search: "",
liveCompatible: false,
page: 1,
counterCurrency: "usd",
counterCurrency: "USD",
},
currentPage: 1,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useDebounce } from "@ledgerhq/live-common/hooks/useDebounce";
import { Flex, SearchInput } from "@ledgerhq/react-ui";

import React from "react";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import { track } from "~/renderer/analytics/segment";
import { withV3StyleProvider } from "~/renderer/styles/StyleProviderV3";

const SearchContainer = styled(Flex).attrs({ flexShrink: "1" })`
Expand All @@ -18,12 +20,27 @@ type Props = {

function SearchInputComponent({ search, updateSearch }: Props) {
const { t } = useTranslation();

const [inputSearch, setInputSearch] = useState(search);
const debouncedSearch = useDebounce(inputSearch, 300);

useEffect(() => {
track("Page Market Query", {
currencyName: debouncedSearch,
});
updateSearch(debouncedSearch ? debouncedSearch.trim() : "");
}, [debouncedSearch, updateSearch]);

useEffect(() => {
setInputSearch(search.toLowerCase());
}, [search]);

return (
<SearchContainer>
<SearchInput
data-test-id="market-search-input"
value={search}
onChange={updateSearch}
value={inputSearch}
onChange={setInputSearch}
placeholder={t("common.search")}
clearable
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function SearchHeader({ search, refresh }: Props) {
}, [debouncedSearch, refresh]);

useEffect(() => {
setInputSearch(search);
setInputSearch(search?.toLowerCase());
}, [search]);

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/src/reducers/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const INITIAL_STATE: MarketState = {
search: "",
liveCompatible: false,
page: 1,
counterCurrency: "usd",
counterCurrency: "USD",
},
marketFilterByStarredCurrencies: false,
marketCurrentPage: 1,
Expand Down
2 changes: 1 addition & 1 deletion libs/ledger-live-common/src/market/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function fetchList({
pageSize: limit,
to: counterCurrency,
sort: getSortParam(order, range),
...(search.length >= 1 && { filter: search }),
...(search.length >= 2 && { filter: search }),
...(starred.length > 0 && { ids: starred.join(",") }),
...(liveCoinsList.length > 1 && { ids: liveCoinsList.join(",") }),
...([Order.topLosers, Order.topGainers].includes(order) && { top: 100 }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function useMarketData(props: MarketListRequestParams): MarketListRequest
props.order,
{
counterCurrency: props.counterCurrency,
...(props.search && props.search?.length >= 1 && { search: props.search }),
...(props.search && props.search?.length >= 2 && { search: props.search }),
...(props.starred && props.starred?.length >= 1 && { starred: props.starred }),
...(props.liveCoinsList &&
props.liveCoinsList?.length >= 1 && { liveCoinsList: props.liveCoinsList }),
Expand Down

0 comments on commit 00e7703

Please sign in to comment.