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(ui-ux): fix NaN bug in homepage #1939

Merged
merged 6 commits into from
Oct 10, 2024
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
15 changes: 7 additions & 8 deletions src/components/commons/searchbar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ export function SearchBar(props: SearchBarInterface): JSX.Element {
const currentReference = refs.reference.current as Element;
Object.assign(refs.floating.current?.style, {
width: `${currentReference.scrollWidth}px`,
left:
`${
currentReference.scrollLeft +
(currentReference.scrollWidth - refs.floating.current?.scrollWidth)
}px` ?? "",
left: `${
currentReference.scrollLeft +
(currentReference.scrollWidth - refs.floating.current?.scrollWidth)
}px`,
});
}

Expand Down Expand Up @@ -113,7 +112,7 @@ export function SearchBar(props: SearchBarInterface): JSX.Element {

const onChangeDebounceHandler = useMemo(
() => debounce(changeHandler, 200),
[]
[],
);

function onSelect(result: SearchResult): void {
Expand All @@ -137,7 +136,7 @@ export function SearchBar(props: SearchBarInterface): JSX.Element {
>
<div
className={classNames(
"flex w-full p-2 rounded-3xl h-10 bg-white dark:bg-gray-800 dark:border-gray-700 border focus-within:border-primary-200"
"flex w-full p-2 rounded-3xl h-10 bg-white dark:bg-gray-800 dark:border-gray-700 border focus-within:border-primary-200",
)}
data-testid="SearchBar"
ref={reference}
Expand Down Expand Up @@ -184,7 +183,7 @@ export function SearchBar(props: SearchBarInterface): JSX.Element {
async function getSearchResults(
api: WhaleApiClient,
network: NetworkName,
query: string
query: string,
): Promise<SearchResult[]> {
const searchResults: SearchResult[] = [];

Expand Down
9 changes: 7 additions & 2 deletions src/utils/index/CalculatePercentage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
export function CalculatePercentage(
value1: number | undefined,
value2: number | undefined
value2: number | undefined,
): string {
if (value1 === undefined || value2 === undefined) {
return "";
}

return `${((value1 / value2) * 100).toFixed(2)}%`;
const result = value1 / value2;
if (isNaN(result)) {
return "0.00%";
}

return `${(result * 100).toFixed(2)}%`;
}
Loading