From 119d0ea5139ba242626f2b89e72bd07f7949fc49 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 075405009e..3bb8c3540c 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)