Skip to content

Commit

Permalink
Merge pull request #984 from alleslabs/fix/block-in-search3
Browse files Browse the repository at this point in the history
Fix block in search by preventing non number
  • Loading branch information
evilpeach committed Jun 20, 2024
2 parents fb4042a + 50da66c commit ab9c6d9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
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
33 changes: 24 additions & 9 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,19 @@ const ResultItem = ({
onClose,
}: ResultItemProps) => {
const route = getRouteOptions(type)?.pathname;
const isAccountAddress =
type === "Account Address" || type === "Contract Address";
const displayValue = useMemo(() => {
if (isAccountAddress) {
return metadata.icns.address || metadata.initiaUsername.address || value;
}
return value;
}, [
isAccountAddress,
metadata.icns.address,
metadata.initiaUsername.address,
value,
]);
const normalizedIcnsValue = value.endsWith(`.${metadata.icns.bech32Prefix}`)
? value
: `${value}.${metadata.icns.bech32Prefix}`;
Expand All @@ -155,10 +169,8 @@ const ResultItem = ({
onClose?.();
}}
>
<Text variant="body2">
{metadata.icns.address || metadata.initiaUsername.address || value}
</Text>
{metadata.icns.icnsNames?.primaryName && (
<Text variant="body2">{displayValue}</Text>
{isAccountAddress && metadata.icns.icnsNames?.primaryName && (
<Flex gap={1} align="center" flexWrap="wrap">
<Flex gap={1} align="center">
<PrimaryNameMark />
Expand All @@ -184,7 +196,7 @@ const ResultItem = ({
)}
</Flex>
)}
{metadata.initiaUsername?.username && (
{isAccountAddress && metadata.initiaUsername?.username && (
<InitiaUsername username={metadata.initiaUsername.username} />
)}
</Flex>
Expand Down Expand Up @@ -314,9 +326,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

0 comments on commit ab9c6d9

Please sign in to comment.