From b4056f9bf82dd80b0e9f5e94996bced973baab35 Mon Sep 17 00:00:00 2001 From: WhiteMind Date: Fri, 20 Oct 2023 17:03:15 +0800 Subject: [PATCH] refactor: search component --- src/components/Search/index.tsx | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 075405009..3bb8c3540 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -58,16 +58,30 @@ const handleSearchResult = async ( const { data } = await explorerService.api.fetchSearchResult(addPrefixForHash(query)) clearSearchInput(inputElement) setSearchValue('') - if (data.type === SearchResultType.Block) { - history.push(`/block/${data.attributes.blockHash}`) - } else if (data.type === SearchResultType.Transaction) { - history.push(`/transaction/${data.attributes.transactionHash}`) - } else if (data.type === SearchResultType.Address) { - history.push(`/address/${data.attributes.addressHash}`) - } else if (data.type === SearchResultType.LockHash) { - history.push(`/address/${data.attributes.lockHash}`) - } else if (data.type === SearchResultType.UDT) { - history.push(`/sudt/${query}`) + + switch (data.type) { + case SearchResultType.Block: + history.push(`/block/${data.attributes.blockHash}`) + break + + case SearchResultType.Transaction: + history.push(`/transaction/${data.attributes.transactionHash}`) + break + + case SearchResultType.Address: + history.push(`/address/${data.attributes.addressHash}`) + break + + case SearchResultType.LockHash: + history.push(`/address/${data.attributes.lockHash}`) + break + + case SearchResultType.UDT: + history.push(`/sudt/${query}`) + break + + default: + break } } catch (error) { setSearchContent(inputElement, query)