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 block in search by preventing non number #984

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#984](https://github.com/alleslabs/celatone-frontend/pull/984) Exclude non block number from searching block in lite
- [#974](https://github.com/alleslabs/celatone-frontend/pull/974) Fix tx by account addr lcd to support new cosmos sdk
- [#976](https://github.com/alleslabs/celatone-frontend/pull/976) Support save accounts in lite version
- [#944](https://github.com/alleslabs/celatone-frontend/pull/944) Fix asset input selector
Expand Down
30 changes: 22 additions & 8 deletions src/lib/layout/Searchbar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-duplicate-string */
import {
Button,
chakra,
Expand All @@ -16,7 +17,7 @@ import {
useDisclosure,
useOutsideClick,
} from "@chakra-ui/react";
import { useCallback, useRef, useState } from "react";
import { useCallback, useMemo, useRef, useState } from "react";
import type { ChangeEvent, KeyboardEvent } from "react";

import { trackUseMainSearch } from "lib/amplitude";
Expand Down Expand Up @@ -131,6 +132,18 @@ const ResultItem = ({
onClose,
}: ResultItemProps) => {
const route = getRouteOptions(type)?.pathname;
const isAccountAddress = type === "Account Address";
const displayValue = useMemo(() => {
if (isAccountAddress) {
return metadata.icns.address || metadata.initiaUsername.address || value;
}
return value;
}, [
isAccountAddress,
metadata.icns.address,
metadata.initiaUsername.address,
value,
]);
evilpeach marked this conversation as resolved.
Show resolved Hide resolved
const normalizedIcnsValue = value.endsWith(`.${metadata.icns.bech32Prefix}`)
? value
: `${value}.${metadata.icns.bech32Prefix}`;
Expand All @@ -155,9 +168,7 @@ const ResultItem = ({
onClose?.();
}}
>
<Text variant="body2">
{metadata.icns.address || metadata.initiaUsername.address || value}
</Text>
<Text variant="body2">{displayValue}</Text>
{metadata.icns.icnsNames?.primaryName && (
<Flex gap={1} align="center" flexWrap="wrap">
<Flex gap={1} align="center">
Expand All @@ -184,7 +195,7 @@ const ResultItem = ({
)}
</Flex>
)}
{metadata.initiaUsername?.username && (
{isAccountAddress && metadata.initiaUsername?.username && (
<InitiaUsername username={metadata.initiaUsername.username} />
)}
</Flex>
Expand Down Expand Up @@ -314,9 +325,12 @@ const Searchbar = () => {
if (type === "Module Path") {
return splitModule(keyword) as [Addr, string];
}
return (
metadata.icns.address || metadata.initiaUsername.address || keyword
);
if (type === "Account Address")
return (
metadata.icns.address || metadata.initiaUsername.address || keyword
);

return keyword;
};

trackUseMainSearch(isClick, type);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/services/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ export const useSearchHandler = (
isPosDecimal(debouncedKeyword) && isFullTier
);
const { foundBlock, isFetching: blockFetching } = useMemo(() => {
if (!isFullTier) return { foundBlock: true, isFetching: false };
if (isPosDecimal(debouncedKeyword) && !isFullTier)
return { foundBlock: true, isFetching: false };
return { foundBlock: blockApi.data, isFetching: blockApi.isFetching };
}, [blockApi, isFullTier]);
}, [blockApi.data, blockApi.isFetching, debouncedKeyword, isFullTier]);

// Proposal
const { data: proposalApiData, isFetching: proposalApiIsFetching } =
Expand Down
Loading