From 6f2b211d31fd79ce43e4756274824548184bcd5b Mon Sep 17 00:00:00 2001 From: Yudho <149754501+yudhomax@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:44:12 +0530 Subject: [PATCH] feat(app): add csr in search (#550) --- apps/app/package.json | 1 + apps/app/src/components/Address/Receipts.tsx | 2 +- .../src/components/Address/Transactions.tsx | 39 +------- apps/app/src/components/Layouts/Header.tsx | 15 +-- apps/app/src/components/Layouts/index.tsx | 29 +++--- .../src/components/Tokens/NFT/Transfers.tsx | 10 +- .../src/components/Transactions/Details.tsx | 33 ++++--- apps/app/src/components/common/Search.tsx | 69 ++++---------- apps/app/src/pages/404.tsx | 28 +----- apps/app/src/pages/about.tsx | 24 +---- apps/app/src/pages/address/[id].tsx | 91 ++++++++----------- apps/app/src/pages/advertise.tsx | 24 +---- apps/app/src/pages/apis.tsx | 25 +---- apps/app/src/pages/blocks/[hash].tsx | 21 +---- apps/app/src/pages/blocks/index.tsx | 18 +--- apps/app/src/pages/charts/addresses.tsx | 24 +---- apps/app/src/pages/charts/blocks.tsx | 24 +---- apps/app/src/pages/charts/index.tsx | 24 +---- apps/app/src/pages/charts/market-cap.tsx | 24 +---- apps/app/src/pages/charts/near-price.tsx | 24 +---- apps/app/src/pages/charts/near-supply.tsx | 24 +---- apps/app/src/pages/charts/tps.tsx | 24 +---- apps/app/src/pages/charts/txn-fee.tsx | 24 +---- apps/app/src/pages/charts/txn-volume.tsx | 24 +---- apps/app/src/pages/charts/txns.tsx | 24 +---- apps/app/src/pages/contact.tsx | 24 +---- apps/app/src/pages/exportdata.tsx | 24 +---- apps/app/src/pages/index.tsx | 61 ++++++------- .../src/pages/nft-token/[id]/[tid]/index.tsx | 20 +--- apps/app/src/pages/nft-token/[id]/index.tsx | 27 +----- apps/app/src/pages/nft-token/exportdata.tsx | 24 +---- apps/app/src/pages/nft-tokens.tsx | 29 +----- apps/app/src/pages/nft-tokentxns.tsx | 20 +--- apps/app/src/pages/node-explorer/[id].tsx | 22 +---- apps/app/src/pages/node-explorer/index.tsx | 20 +--- apps/app/src/pages/terms-and-conditions.tsx | 24 +---- apps/app/src/pages/token/[id].tsx | 27 +----- apps/app/src/pages/token/exportdata.tsx | 22 +---- apps/app/src/pages/tokens.tsx | 18 +--- apps/app/src/pages/tokentxns.tsx | 26 +----- apps/app/src/pages/txns/[hash].tsx | 61 +++++-------- apps/app/src/pages/txns/index.tsx | 28 +----- apps/app/src/pages/verify-contract/index.tsx | 24 +---- apps/app/src/utils/fetchData.ts | 28 +----- apps/app/src/utils/search.ts | 4 +- yarn.lock | 13 +++ 46 files changed, 240 insertions(+), 975 deletions(-) diff --git a/apps/app/package.json b/apps/app/package.json index beb39742..3997c21a 100644 --- a/apps/app/package.json +++ b/apps/app/package.json @@ -64,6 +64,7 @@ "next-sitemap": "4.2.3", "next-themes": "^0.3.0", "next-translate": "2.6.2", + "nextjs-toploader": "3.7.15", "qs": "^6.12.3", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/apps/app/src/components/Address/Receipts.tsx b/apps/app/src/components/Address/Receipts.tsx index 17fbceb6..63451bfa 100644 --- a/apps/app/src/components/Address/Receipts.tsx +++ b/apps/app/src/components/Address/Receipts.tsx @@ -203,7 +203,7 @@ const Receipts = ({ txns, count, error, cursor, tab }: TxnsProps) => { className="absolute h-auto max-w-xs bg-black bg-opacity-90 z-10 text-xs text-white p-2 break-words" > { 'px-4 py-4 text-left whitespace-nowrap text-xs font-semibold text-nearblue-600 dark:text-neargray-10 uppercase tracking-wider', }, { - header: ( - - - {t ? t('txns:type') : 'METHOD'}{' '} - - - -
- -
- - -
-
-
-
- ), + header: {t ? t('txns:type') : 'METHOD'}, key: 'actions', cell: (row: TransactionInfo) => ( @@ -247,6 +212,8 @@ const Transactions = ({ txns, count, error, cursor, tab }: TxnsProps) => { ), tdClassName: 'px-4 py-2 whitespace-nowrap text-sm text-nearblue-600 dark:text-neargray-10', + thClassName: + 'px-4 py-4 text-left text-xs font-semibold text-nearblue-600 dark:text-neargray-10 uppercase tracking-wider whitespace-nowrap', }, { header: {t ? t('txns:depositValue') : 'DEPOSIT VALUE'}, diff --git a/apps/app/src/components/Layouts/Header.tsx b/apps/app/src/components/Layouts/Header.tsx index 4000ce59..26471c32 100644 --- a/apps/app/src/components/Layouts/Header.tsx +++ b/apps/app/src/components/Layouts/Header.tsx @@ -139,16 +139,9 @@ const languages = [ interface Props { statsDetails?: { stats: Stats[] }; latestBlocks?: { blocks: BlocksInfo[] }; - searchResultDetails?: any; - searchRedirectDetails?: any; } -const Header = ({ - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, -}: Props) => { +const Header = ({ statsDetails, latestBlocks }: Props) => { /* eslint-disable @next/next/no-img-element */ const router = useRouter(); @@ -301,11 +294,7 @@ const Header = ({ {showSearch && (
- +
)} diff --git a/apps/app/src/components/Layouts/index.tsx b/apps/app/src/components/Layouts/index.tsx index 9310fd72..cf7cfd86 100644 --- a/apps/app/src/components/Layouts/index.tsx +++ b/apps/app/src/components/Layouts/index.tsx @@ -1,20 +1,18 @@ -import { ReactNode } from 'react'; +import { ReactNode, useEffect, useState } from 'react'; import Header from './Header'; import Footer from './Footer'; import { useRouter } from 'next/router'; import { BlocksInfo, Stats } from '@/utils/types'; -import useLoading from '@/hooks/useLoading'; -import { Spinner } from '../common/Spinner'; import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; +import NextTopLoader from 'nextjs-toploader'; +import { useTheme } from 'next-themes'; interface LayoutProps { children: ReactNode; notice?: ReactNode; statsDetails?: { stats: Stats[] }; latestBlocks?: { blocks: BlocksInfo[] }; - searchResultDetails?: any; - searchRedirectDetails?: any; } const Layout = ({ @@ -22,11 +20,15 @@ const Layout = ({ notice, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }: LayoutProps) => { const router = useRouter(); - const { loading, setLoading } = useLoading(); + const [isMounted, setIsMounted] = useState(false); + const { theme } = useTheme(); + + useEffect(() => { + setIsMounted(true); + }, []); + const className = router.pathname === '/404' ? 'bg-white dark:bg-black-300' @@ -36,14 +38,11 @@ const Layout = ({
{notice}
-
+
- {loading && } + {isMounted && ( + + )}
{children}
diff --git a/apps/app/src/components/Tokens/NFT/Transfers.tsx b/apps/app/src/components/Tokens/NFT/Transfers.tsx index 8d5044b9..100ba187 100644 --- a/apps/app/src/components/Tokens/NFT/Transfers.tsx +++ b/apps/app/src/components/Tokens/NFT/Transfers.tsx @@ -75,7 +75,7 @@ const Transfers = ({ txns, count, cursor, error, tab }: Props) => { 'px-5 py-4 whitespace-nowrap text-left text-xs font-semibold text-nearblue-600 dark:text-neargray-10 uppercase tracking-wider', }, { - header: METHOD, + header: METHOD, key: 'cause', cell: (row: TransactionInfo) => ( @@ -95,7 +95,7 @@ const Transfers = ({ txns, count, cursor, error, tab }: Props) => { 'px-5 py-4 text-left text-xs font-semibold text-nearblue-600 dark:text-neargray-10 uppercase tracking-wider', }, { - header: From, + header: From, key: 'affected_account_id', cell: (row: TransactionInfo) => { return Number(row.delta_amount) < 0 ? ( @@ -161,9 +161,9 @@ const Transfers = ({ txns, count, cursor, error, tab }: Props) => { ); }, tdClassName: - 'px-5 py-3 whitespace-nowrap text-sm text-nearblue-600 dark:text-neargray-10 font-medium', + 'px-3 py-3 whitespace-nowrap text-sm text-nearblue-600 dark:text-neargray-10 font-medium', thClassName: - 'px-5 py-4 text-left text-xs font-semibold text-nearblue-600 dark:text-neargray-10 uppercase tracking-wider', + 'px-3 py-3 text-left text-xs font-semibold text-nearblue-600 dark:text-neargray-10 uppercase tracking-wider', }, { header: , @@ -182,7 +182,7 @@ const Transfers = ({ txns, count, cursor, error, tab }: Props) => { tdClassName: 'text-center', }, { - header: To, + header: To, key: 'involved_account_id', cell: (row: TransactionInfo) => { return Number(row.delta_amount) < 0 ? ( diff --git a/apps/app/src/components/Transactions/Details.tsx b/apps/app/src/components/Transactions/Details.tsx index 58550d32..b6104401 100644 --- a/apps/app/src/components/Transactions/Details.tsx +++ b/apps/app/src/components/Transactions/Details.tsx @@ -65,33 +65,33 @@ const Details = (props: Props) => { let nfts: NftsInfo[] = []; receipts && - receipts.forEach( + receipts?.forEach( (receipt) => receipt?.fts?.forEach((ft) => { - if (ft.ft_meta && ft.cause === 'TRANSFER') { - if (ft.ft_meta && Number(ft.delta_amount) < 0) fts.push(ft); + if (ft?.ft_meta && ft.cause === 'TRANSFER') { + if (ft?.ft_meta && Number(ft?.delta_amount) < 0) fts?.push(ft); } else { - if (ft.ft_meta) fts.push(ft); + if (ft?.ft_meta) fts?.push(ft); } }), ); receipts && - receipts.forEach( + receipts?.forEach( (receipt) => receipt?.nfts?.forEach((nft) => { if ( - nft.nft_meta && - nft.nft_token_meta && - nft.cause === 'TRANSFER' + nft?.nft_meta && + nft?.nft_token_meta && + nft?.cause === 'TRANSFER' ) { if ( - nft.nft_meta && - nft.nft_token_meta && - Number(nft.delta_amount) < 0 + nft?.nft_meta && + nft?.nft_token_meta && + Number(nft?.delta_amount) < 0 ) - nfts.push(nft); + nfts?.push(nft); } else { - if (nft.nft_meta && nft.nft_token_meta) nfts.push(nft); + if (nft?.nft_meta && nft?.nft_token_meta) nfts?.push(nft); } }), ); @@ -103,7 +103,7 @@ const Details = (props: Props) => { } if (txn?.receipts?.length) { - return tokensTransfers(txn.receipts); + return tokensTransfers(txn?.receipts); } return { fts: [], nfts: [] }; @@ -836,7 +836,10 @@ const Details = (props: Props) => { | {' '} {txn?.receipt_conversion_tokens_burnt - ? yoctoToNear(txn.receipt_conversion_tokens_burnt, true) + ? yoctoToNear( + txn?.receipt_conversion_tokens_burnt, + true, + ) : txn?.receipt_conversion_tokens_burnt ?? ''}{' '} Ⓝ
diff --git a/apps/app/src/components/common/Search.tsx b/apps/app/src/components/common/Search.tsx index 5c6a4787..aae1626f 100644 --- a/apps/app/src/components/common/Search.tsx +++ b/apps/app/src/components/common/Search.tsx @@ -17,6 +17,7 @@ import { networkId } from '@/utils/config'; import ArrowDown from '../Icons/ArrowDown'; import { localFormat, shortenAddress, shortenHex } from '@/utils/libs'; import SearchIcon from '../Icons/SearchIcon'; +import search from '@/utils/search'; export const SearchToast = () => { if (networkId === 'testnet') { @@ -55,19 +56,13 @@ export const redirect = (route: any) => { } }; -const Search = ({ - header = false, - result = {} as any, - redirectResult = {} as any, -}) => { +const Search = ({ header = false }) => { const router = useRouter(); const { t } = useTranslation('common'); const [keyword, setKeyword] = useState(''); + const [result, setResult] = useState({} as any); const [filter, setFilter] = useState('all'); - const query = router?.query?.query; - const q = typeof query === 'string' ? query.replace(/[\s,]/g, '') : ''; - const homeSearch = router.pathname === '/'; const showResults = @@ -76,51 +71,20 @@ const Search = ({ result?.accounts?.length > 0 || result?.receipts?.length > 0; - useEffect(() => { - const redirects = (route: any) => { - switch (route?.type) { - case 'block': - return router.push(`/blocks/${route?.path}`); - case 'txn': - case 'receipt': - return router.push(`/txns/${route?.path}`); - case 'address': - return router.push(`/address/${route?.path}`); - default: - return toast.error(SearchToast); - } - }; - - if (q) { - redirects(redirectResult); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [q, redirectResult]); - useEffect(() => { if (filter && keyword) { - const { query, ...currentQuery } = router.query; - const newQuery = { - ...currentQuery, - keyword: keyword, - filter: filter, - }; - router.push({ - pathname: router.pathname, - query: newQuery, - }); + search(keyword, filter).then((data) => setResult(data || {})); } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [filter, keyword]); // eslint-disable-next-line react-hooks/exhaustive-deps const debouncedSave = useCallback( - debounce((nextValue) => setKeyword(nextValue), 300), + debounce((nextValue) => setKeyword(nextValue), 500), [], ); const handleChange = (event: any) => { - const { value: nextValue } = event.target; + const { value: nextValue } = event?.target; debouncedSave(nextValue.replace(/[\s,]/g, '')); }; @@ -134,19 +98,18 @@ const Search = ({ const text = ( document.getElementsByClassName('search')[0] as HTMLInputElement ).value; - const qs = text.replace(/[\s,]/g, ''); - const { query, keyword, ...currentQuery } = router.query; - const newQuery = { - ...currentQuery, - query: qs, - filter: filter, - }; + const query = text.replace(/[\s,]/g, ''); + + if (!query) return toast.error(SearchToast); + + const route = await search(query, filter, true); + + if (route) { + return redirect(route); + } - return router.push({ - pathname: router.pathname, - query: newQuery, - }); + return toast.error(SearchToast); }; return ( diff --git a/apps/app/src/pages/404.tsx b/apps/app/src/pages/404.tsx index 1253a57c..be103647 100644 --- a/apps/app/src/pages/404.tsx +++ b/apps/app/src/pages/404.tsx @@ -1,38 +1,20 @@ import Error from '@/components/Error'; import Layout from '@/components/Layouts'; import { fetchData } from '@/utils/fetchData'; -import { GetStaticProps, GetStaticPropsContext } from 'next'; +import { GetStaticProps } from 'next'; import { ReactElement } from 'react'; export const getStaticProps: GetStaticProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context: GetStaticPropsContext) => { - const { params } = context; - - const keyword: any = params?.keyword ?? ''; - const query: any = params?.query ?? ''; - const filter: any = params?.filter ?? 'all'; - - const key = keyword && keyword?.replace(/[\s,]/g, ''); - const q = query && query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -42,8 +24,6 @@ export const getStaticProps: GetStaticProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -55,8 +35,6 @@ NotFound.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/about.tsx b/apps/app/src/pages/about.tsx index 476c97d5..86ff7a19 100644 --- a/apps/app/src/pages/about.tsx +++ b/apps/app/src/pages/about.tsx @@ -12,30 +12,14 @@ const ogUrl = env('NEXT_PUBLIC_OG_URL'); export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -44,8 +28,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -93,8 +75,6 @@ AboutPage.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/address/[id].tsx b/apps/app/src/pages/address/[id].tsx index eb85aa4e..d94f40f3 100644 --- a/apps/app/src/pages/address/[id].tsx +++ b/apps/app/src/pages/address/[id].tsx @@ -41,6 +41,7 @@ import dynamic from 'next/dynamic'; import { getCookieFromRequest } from '@/utils/libs'; import { RpcProviders } from '@/utils/rpc'; import { fetchData } from '@/utils/fetchData'; +import Receipts from '@/components/Address/Receipts'; const network = env('NEXT_PUBLIC_NETWORK_ID'); const ogUrl = env('NEXT_PUBLIC_OG_URL'); @@ -48,10 +49,6 @@ const RpcMenu = dynamic(() => import('../../components/Layouts/RpcMenu'), { ssr: false, }); -const Receipts = dynamic(() => import('../../components/Address/Receipts'), { - ssr: false, -}); - const tabs = [ 'txns', 'receipts', @@ -84,18 +81,9 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; tab: string; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; }> = async (context) => { const { - query: { - id = '', - tab = 'txns', - keyword = '', - query = '', - filter = 'all', - ...qs - }, + query: { id = '', tab = 'txns', ...qs }, req, }: { query: { @@ -111,9 +99,6 @@ export const getServerSideProps: GetServerSideProps<{ const address = id.toLowerCase(); const rpcUrl = getCookieFromRequest('rpcUrl', req) || RpcProviders?.[0]?.url; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - const commonApiUrls = { account: id && `account/${address}?rpc=${rpcUrl}`, deployments: id && `account/${address}/contract/deployments?rpc=${rpcUrl}`, @@ -183,12 +168,7 @@ export const getServerSideProps: GetServerSideProps<{ fetchCommonData(commonApiUrls.inventory), ]); - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); const getResult = (result: PromiseSettledResult) => result.status === 'fulfilled' ? result.value : null; @@ -230,8 +210,6 @@ export const getServerSideProps: GetServerSideProps<{ error: !dataResult, // Set error to true only if dataResult is null tab, latestBlocks: latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; }; @@ -531,6 +509,7 @@ const Address = ({ href={`${appUrl}/address/${accountData?.account_id}`} /> +
{!id ? ( @@ -540,7 +519,7 @@ const Address = ({ ) : (
-

+

Near Account:  {id && ( @@ -610,7 +589,15 @@ const Address = ({
<>
- + {[ { key: 0, label: t ? t('address:txns') : 'Transactions' }, @@ -655,7 +642,13 @@ const Address = ({ @@ -725,21 +718,17 @@ const Address = ({ )} - {tab === 'comments' ? ( - } - props={{ - network: network, - path: `nearblocks.io/address/${id}`, - limit: 10, - requestSignInWithWallet, - }} - loading={} - /> - ) : ( -
- )} + } + props={{ + network: network, + path: `nearblocks.io/address/${id}`, + limit: 10, + requestSignInWithWallet, + }} + loading={} + />
@@ -761,14 +750,14 @@ const Address = ({ }; Address.getLayout = (page: ReactElement) => ( - - {page} - + <> + + {page} + + ); export default Address; diff --git a/apps/app/src/pages/advertise.tsx b/apps/app/src/pages/advertise.tsx index 3b24d610..bec4ade3 100644 --- a/apps/app/src/pages/advertise.tsx +++ b/apps/app/src/pages/advertise.tsx @@ -17,30 +17,14 @@ const ogUrl = env('NEXT_PUBLIC_OG_URL'); export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -49,8 +33,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -365,8 +347,6 @@ AdvertisePage.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/apis.tsx b/apps/app/src/pages/apis.tsx index 27e2903f..1e1b3fa3 100644 --- a/apps/app/src/pages/apis.tsx +++ b/apps/app/src/pages/apis.tsx @@ -23,30 +23,14 @@ const userApiURL = env('NEXT_PUBLIC_USER_API_URL'); export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -55,12 +39,11 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } }; + const ApiPlan = () => { const router = useRouter(); const { status } = router.query; @@ -600,8 +583,6 @@ ApiPlan.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/blocks/[hash].tsx b/apps/app/src/pages/blocks/[hash].tsx index a06fe06d..04b4522e 100644 --- a/apps/app/src/pages/blocks/[hash].tsx +++ b/apps/app/src/pages/blocks/[hash].tsx @@ -19,27 +19,17 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; }> = async (context) => { const { - query: { hash, keyword = '', query = '', filter = 'all' }, + query: { hash }, }: any = context; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - try { const [blockInfoResult] = await Promise.allSettled([ fetcher(`blocks/${hash}`), ]); - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); const blockInfo = blockInfoResult.status === 'fulfilled' ? blockInfoResult.value : null; @@ -69,8 +59,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -83,8 +71,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -101,6 +87,7 @@ const Block = ({ const blockHash = blockInfo?.blocks[0]?.block_hash; const thumbnail = `${ogUrl}/thumbnail/block?block_height=${blockHeight}&brand=near`; + return ( <> @@ -157,8 +144,6 @@ Block.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/blocks/index.tsx b/apps/app/src/pages/blocks/index.tsx index 4507d3f8..f1d84c84 100644 --- a/apps/app/src/pages/blocks/index.tsx +++ b/apps/app/src/pages/blocks/index.tsx @@ -19,8 +19,6 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; }> = async (context) => { const { query: { keyword = '', filter = 'all', query = '', ...qs }, @@ -29,9 +27,6 @@ export const getServerSideProps: GetServerSideProps<{ const apiUrl = 'blocks'; const fetchUrl = qs ? `blocks?${queryString.stringify(qs)}` : `${apiUrl}`; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - try { const [dataResult, dataCountResult] = await Promise.allSettled([ fetcher(fetchUrl), @@ -42,12 +37,7 @@ export const getServerSideProps: GetServerSideProps<{ dataCountResult.status === 'fulfilled' ? dataCountResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -57,8 +47,6 @@ export const getServerSideProps: GetServerSideProps<{ apiUrl, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -71,8 +59,6 @@ export const getServerSideProps: GetServerSideProps<{ apiUrl: '', statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -133,8 +119,6 @@ Blocks.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/charts/addresses.tsx b/apps/app/src/pages/charts/addresses.tsx index 626d3854..7a7b7e91 100644 --- a/apps/app/src/pages/charts/addresses.tsx +++ b/apps/app/src/pages/charts/addresses.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -128,8 +110,6 @@ AddressesChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/blocks.tsx b/apps/app/src/pages/charts/blocks.tsx index d174f535..e84ea189 100644 --- a/apps/app/src/pages/charts/blocks.tsx +++ b/apps/app/src/pages/charts/blocks.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -123,8 +105,6 @@ BlocksChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/index.tsx b/apps/app/src/pages/charts/index.tsx index ad89ffb2..78b2c672 100644 --- a/apps/app/src/pages/charts/index.tsx +++ b/apps/app/src/pages/charts/index.tsx @@ -14,30 +14,14 @@ const ogUrl = env('NEXT_PUBLIC_OG_URL'); export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -46,8 +30,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -101,8 +83,6 @@ Charts.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/market-cap.tsx b/apps/app/src/pages/charts/market-cap.tsx index 112de60b..195cbb22 100644 --- a/apps/app/src/pages/charts/market-cap.tsx +++ b/apps/app/src/pages/charts/market-cap.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -129,8 +111,6 @@ MarketCapChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/near-price.tsx b/apps/app/src/pages/charts/near-price.tsx index 32d388bc..4b17ae24 100644 --- a/apps/app/src/pages/charts/near-price.tsx +++ b/apps/app/src/pages/charts/near-price.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -130,8 +112,6 @@ NearPriceChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/near-supply.tsx b/apps/app/src/pages/charts/near-supply.tsx index 5c304a2c..8a4f90b7 100644 --- a/apps/app/src/pages/charts/near-supply.tsx +++ b/apps/app/src/pages/charts/near-supply.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -134,8 +116,6 @@ NearSupplyChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/tps.tsx b/apps/app/src/pages/charts/tps.tsx index 1c553010..1f6fbeec 100644 --- a/apps/app/src/pages/charts/tps.tsx +++ b/apps/app/src/pages/charts/tps.tsx @@ -14,27 +14,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts/tps')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -42,8 +28,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -54,8 +38,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -135,8 +117,6 @@ Tps.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/txn-fee.tsx b/apps/app/src/pages/charts/txn-fee.tsx index 668ea6e2..cce71b7b 100644 --- a/apps/app/src/pages/charts/txn-fee.tsx +++ b/apps/app/src/pages/charts/txn-fee.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -124,8 +106,6 @@ TxnFeeChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/txn-volume.tsx b/apps/app/src/pages/charts/txn-volume.tsx index 57ca9cf8..29ec4127 100644 --- a/apps/app/src/pages/charts/txn-volume.tsx +++ b/apps/app/src/pages/charts/txn-volume.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -129,8 +111,6 @@ TxnVolumeChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/charts/txns.tsx b/apps/app/src/pages/charts/txns.tsx index 42b8c83c..090d95e0 100644 --- a/apps/app/src/pages/charts/txns.tsx +++ b/apps/app/src/pages/charts/txns.tsx @@ -17,27 +17,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [dataResult] = await Promise.allSettled([fetcher('charts')]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -45,8 +31,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -57,8 +41,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -120,8 +102,6 @@ TxnsChart.getLayout = (page: ReactElement) => ( notice={} statsDetails={page?.props?.statsDetails} latestBlocks={page?.props?.latestBlocks} - searchResultDetails={page?.props?.searchResultDetails} - searchRedirectDetails={page?.props?.searchRedirectDetails} > {page} diff --git a/apps/app/src/pages/contact.tsx b/apps/app/src/pages/contact.tsx index 85dd1c4f..943f44bf 100644 --- a/apps/app/src/pages/contact.tsx +++ b/apps/app/src/pages/contact.tsx @@ -24,30 +24,14 @@ const ogUrl = env('NEXT_PUBLIC_OG_URL'); export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -56,8 +40,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -495,8 +477,6 @@ Contact.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/exportdata.tsx b/apps/app/src/pages/exportdata.tsx index a3046609..b2cbb68a 100644 --- a/apps/app/src/pages/exportdata.tsx +++ b/apps/app/src/pages/exportdata.tsx @@ -10,30 +10,14 @@ import { fetchData } from '@/utils/fetchData'; export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -42,8 +26,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -91,8 +73,6 @@ ExportData.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/index.tsx b/apps/app/src/pages/index.tsx index 0ac94d76..089239ef 100644 --- a/apps/app/src/pages/index.tsx +++ b/apps/app/src/pages/index.tsx @@ -2,18 +2,21 @@ import Head from 'next/head'; import Layout from '@/components/Layouts'; import { appUrl } from '@/utils/config'; import useTranslation from 'next-translate/useTranslation'; -import React, { ReactElement } from 'react'; +import React, { ReactElement, useEffect } from 'react'; import 'react-toastify/dist/ReactToastify.css'; import { env } from 'next-runtime-env'; import Banner from '@/components/Banner'; import SponserdText from '@/components/SponserdText'; import LatestBlocks from '@/components/Blocks/Latest'; -import Search from '@/components/common/Search'; +import Search, { redirect, SearchToast } from '@/components/common/Search'; import fetcher from '@/utils/fetcher'; import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; import Overview from '@/components/Transactions/Overview'; import LatestTransactions from '@/components/Transactions/Latest'; import { fetchData } from '@/utils/fetchData'; +import { toast } from 'react-toastify'; +import search from '@/utils/search'; +import { useRouter } from 'next/router'; const network = env('NEXT_PUBLIC_NETWORK_ID'); const ogUrl = env('NEXT_PUBLIC_OG_URL'); @@ -24,20 +27,8 @@ export const getServerSideProps: GetServerSideProps<{ blockDetails: any; txnsDetails: any; latestBlocks: any; - searchRedirectDetails: any; - searchResultDetails: any; error: boolean; -}> = async (context) => { - const { - query: { query = '', keyword = '', filter = 'all' }, - }: { - query: { query?: string; keyword?: string; filter?: string }; - req: any; - } = context; - - const q = query?.replace(/[\s,]/g, ''); - const key = keyword?.replace(/[\s,]/g, ''); - +}> = async () => { try { const [chartResult, blockResult, txnsResult] = await Promise.allSettled([ fetcher(`charts/latest`), @@ -52,13 +43,7 @@ export const getServerSideProps: GetServerSideProps<{ const txnsDetails = txnsResult.status === 'fulfilled' ? txnsResult.value : null; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - error, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks, error } = await fetchData(); return { props: { @@ -67,8 +52,6 @@ export const getServerSideProps: GetServerSideProps<{ blockDetails, txnsDetails, latestBlocks, - searchRedirectDetails, - searchResultDetails, error, }, }; @@ -81,8 +64,6 @@ export const getServerSideProps: GetServerSideProps<{ blockDetails: null, txnsDetails: null, latestBlocks: null, - searchRedirectDetails: null, - searchResultDetails: null, error: true, }, }; @@ -94,17 +75,36 @@ const HomePage = ({ chartDetails, blockDetails, txnsDetails, - searchRedirectDetails, - searchResultDetails, error, }: InferGetServerSidePropsType) => { const { t } = useTranslation(); + const router = useRouter(); + const { q } = router.query; + const stats = statsDetails?.stats?.[0]; const charts = chartDetails; const blocks = blockDetails?.blocks || []; const txns = txnsDetails?.txns || []; const thumbnail = `${ogUrl}/thumbnail/home?brand=near`; + useEffect(() => { + const loadResults = async (keyword: string) => { + const route = await search(keyword, 'all', true); + + if (route) { + return redirect(route); + } + + return toast.error(SearchToast); + }; + + const keyword = typeof q === 'string' ? q.trim() : ''; + + if (keyword) { + loadResults(keyword); + } + }, [q]); + return ( <> @@ -143,10 +143,7 @@ const HomePage = ({ {t('home:heroTitle')}

- +
diff --git a/apps/app/src/pages/nft-token/[id]/[tid]/index.tsx b/apps/app/src/pages/nft-token/[id]/[tid]/index.tsx index 894ced62..be399429 100644 --- a/apps/app/src/pages/nft-token/[id]/[tid]/index.tsx +++ b/apps/app/src/pages/nft-token/[id]/[tid]/index.tsx @@ -11,6 +11,7 @@ import Detail from '@/components/Tokens/NFT/Detail'; import { fetchData } from '@/utils/fetchData'; const network = env('NEXT_PUBLIC_NETWORK_ID'); + export const getServerSideProps: GetServerSideProps<{ tokenInfo: any; txnsList: any; @@ -20,18 +21,14 @@ export const getServerSideProps: GetServerSideProps<{ tid: string; statsDetails: any; latestBlocks: any; - searchRedirectDetails: any; - searchResultDetails: any; }> = async (context) => { const { - query: { id, tid, query = '', filter = 'all', keyword = '', ...qs }, + query: { id, tid, ...qs }, }: any = context; const apiUrl = `nfts/${id}/tokens/${tid}`; const fetchUrl = qs ? `${apiUrl}/txns?${QueryString.stringify(qs)}` : `${apiUrl}/txns`; - const q = query?.replace(/[\s,]/g, ''); - const key = keyword?.replace(/[\s,]/g, ''); try { const [tokenData, txnsListResult, txnsCountResult] = @@ -47,12 +44,7 @@ export const getServerSideProps: GetServerSideProps<{ txnsCountResult.status === 'fulfilled' ? txnsCountResult.value : null; const error = txnsListResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -64,8 +56,6 @@ export const getServerSideProps: GetServerSideProps<{ tid, statsDetails, latestBlocks, - searchRedirectDetails, - searchResultDetails, }, }; } catch (error) { @@ -80,8 +70,6 @@ export const getServerSideProps: GetServerSideProps<{ tid: null, statsDetails: null, latestBlocks: null, - searchRedirectDetails: null, - searchResultDetails: null, }, }; } @@ -142,8 +130,6 @@ NFTokenInfo.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/nft-token/[id]/index.tsx b/apps/app/src/pages/nft-token/[id]/index.tsx index 1aeb81ee..3a5e9366 100644 --- a/apps/app/src/pages/nft-token/[id]/index.tsx +++ b/apps/app/src/pages/nft-token/[id]/index.tsx @@ -35,18 +35,9 @@ export const getServerSideProps: GetServerSideProps<{ tab: string; statsDetails: any; latestBlocks: any; - searchRedirectDetails: any; - searchResultDetails: any; }> = async (context) => { const { - query: { - id = '', - tab = 'transfers', - query = '', - filter = 'all', - keyword = '', - ...qs - }, + query: { id = '', tab = 'transfers', ...qs }, }: { query: { id?: string; @@ -73,9 +64,6 @@ export const getServerSideProps: GetServerSideProps<{ comments: { api: `` }, }; - const q = query?.replace(/[\s,]/g, ''); - const key = keyword?.replace(/[\s,]/g, ''); - const commonApiUrls = { token: id && `nfts/${id}`, sync: 'sync/status', @@ -125,12 +113,7 @@ export const getServerSideProps: GetServerSideProps<{ const getResult = (result: PromiseSettledResult) => result.status === 'fulfilled' ? result.value : null; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -144,8 +127,6 @@ export const getServerSideProps: GetServerSideProps<{ tab: tab as string, statsDetails: statsDetails, latestBlocks: latestBlocks, - searchRedirectDetails, - searchResultDetails, }, }; } catch (error) { @@ -162,8 +143,6 @@ export const getServerSideProps: GetServerSideProps<{ tab: 'transfers', statsDetails: null, latestBlocks: null, - searchRedirectDetails: null, - searchResultDetails: null, }, }; } @@ -342,8 +321,6 @@ NFToken.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/nft-token/exportdata.tsx b/apps/app/src/pages/nft-token/exportdata.tsx index 9cfeb852..fea23254 100644 --- a/apps/app/src/pages/nft-token/exportdata.tsx +++ b/apps/app/src/pages/nft-token/exportdata.tsx @@ -10,30 +10,14 @@ import { fetchData } from '@/utils/fetchData'; export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -42,8 +26,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -89,8 +71,6 @@ ExportData.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/nft-tokens.tsx b/apps/app/src/pages/nft-tokens.tsx index 2116746f..26396b35 100644 --- a/apps/app/src/pages/nft-tokens.tsx +++ b/apps/app/src/pages/nft-tokens.tsx @@ -18,25 +18,13 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; }> = async (context) => { const { - query: { keyword = '', query = '', filter = 'all', ...qs }, - }: { - query: { - query?: string; - keyword?: string; - filter?: string; - order?: string; - }; - } = context; + query: { ...qs }, + }: any = context; const params = { ...qs, order: qs.order || 'desc' }; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - const fetchUrl = `nfts?sort=txns_day&per_page=50&${QueryString.stringify( params, )}`; @@ -48,12 +36,7 @@ export const getServerSideProps: GetServerSideProps<{ fetcher(countUrl), ]); - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const dataCount = @@ -68,8 +51,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -82,8 +63,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -157,8 +136,6 @@ TopNFTTokens.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/nft-tokentxns.tsx b/apps/app/src/pages/nft-tokentxns.tsx index 7ca2458e..957999db 100644 --- a/apps/app/src/pages/nft-tokentxns.tsx +++ b/apps/app/src/pages/nft-tokentxns.tsx @@ -20,19 +20,14 @@ export const getServerSideProps: GetServerSideProps<{ error: boolean; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; }> = async (context) => { const { - query: { keyword = '', query = '', filter = 'all', ...qs }, + query: { ...qs }, }: any = context; const apiUrl = 'nfts/txns'; const fetchUrl = qs ? `nfts/txns?${queryString.stringify(qs)}` : `${apiUrl}`; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - try { const [dataResult, dataCountResult, syncResult] = await Promise.allSettled([ fetcher(fetchUrl), @@ -46,12 +41,7 @@ export const getServerSideProps: GetServerSideProps<{ syncResult.status === 'fulfilled' ? syncResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -61,8 +51,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -75,8 +63,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -150,8 +136,6 @@ NftToxenTxns.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/node-explorer/[id].tsx b/apps/app/src/pages/node-explorer/[id].tsx index 30bdeede..ddf14478 100644 --- a/apps/app/src/pages/node-explorer/[id].tsx +++ b/apps/app/src/pages/node-explorer/[id].tsx @@ -19,30 +19,14 @@ const RpcMenu = dynamic(() => import('../../components/Layouts/RpcMenu'), { export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -51,8 +35,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } diff --git a/apps/app/src/pages/node-explorer/index.tsx b/apps/app/src/pages/node-explorer/index.tsx index 7f3991f4..99af5c71 100644 --- a/apps/app/src/pages/node-explorer/index.tsx +++ b/apps/app/src/pages/node-explorer/index.tsx @@ -24,17 +24,12 @@ export const getServerSideProps: GetServerSideProps<{ latestBlock: any; error: boolean; statsDetails: any; - searchRedirectDetails: any; - searchResultDetails: any; }> = async (context) => { const { - query: { keyword = '', query = '', filter = 'all', ...qs }, + query: { qs }, req, }: any = context; - const q = query?.replace(/[\s,]/g, ''); - const key = keyword?.replace(/[\s,]/g, ''); - const rpcUrl = getCookieFromRequest('rpcUrl', req) || RpcProviders?.[0]?.url; const fetchUrl = `validators?${queryString.stringify(qs)}&rpc=${rpcUrl}`; @@ -44,12 +39,7 @@ export const getServerSideProps: GetServerSideProps<{ const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { @@ -57,8 +47,6 @@ export const getServerSideProps: GetServerSideProps<{ latestBlock: latestBlocks, error, statsDetails, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -69,8 +57,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, latestBlock: null, statsDetails: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -130,8 +116,6 @@ NodeExplorer.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/terms-and-conditions.tsx b/apps/app/src/pages/terms-and-conditions.tsx index c32c1dee..6e3b8f01 100644 --- a/apps/app/src/pages/terms-and-conditions.tsx +++ b/apps/app/src/pages/terms-and-conditions.tsx @@ -12,30 +12,14 @@ const ogUrl = env('NEXT_PUBLIC_OG_URL'); export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -44,8 +28,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -465,8 +447,6 @@ TermsAndConditions.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/token/[id].tsx b/apps/app/src/pages/token/[id].tsx index aa619673..57f463c2 100644 --- a/apps/app/src/pages/token/[id].tsx +++ b/apps/app/src/pages/token/[id].tsx @@ -32,23 +32,12 @@ type TabType = 'transfers' | 'holders' | 'info' | 'faq' | 'comments'; export const getServerSideProps: GetServerSideProps = async (context) => { const { - query: { - id = '', - a = '', - tab = 'transfers', - keyword = '', - query = '', - filter = 'all', - ...qs - }, + query: { id = '', a = '', tab = 'transfers', ...qs }, }: { query: { id?: string; a?: string; tab?: TabType; - query?: string; - keyword?: string; - filter?: string; } & Record; } = context; @@ -69,9 +58,6 @@ export const getServerSideProps: GetServerSideProps = async (context) => { } } - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - const commonApiUrls = { stats: 'stats', token: id && `fts/${id}`, @@ -111,12 +97,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { fetchCommonData(commonApiUrls.holdersCount), ]); - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); let dataResult = null; let dataCountResult = null; @@ -166,8 +147,6 @@ export const getServerSideProps: GetServerSideProps = async (context) => { dataCount: dataCountResult && getResult(dataCountResult), error: dataResult && dataResult.status === 'rejected', tab, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -408,8 +387,6 @@ TokenDetails.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/token/exportdata.tsx b/apps/app/src/pages/token/exportdata.tsx index 406d38d8..fb029eb3 100644 --- a/apps/app/src/pages/token/exportdata.tsx +++ b/apps/app/src/pages/token/exportdata.tsx @@ -10,30 +10,14 @@ import { fetchData } from '@/utils/fetchData'; export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -42,8 +26,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } diff --git a/apps/app/src/pages/tokens.tsx b/apps/app/src/pages/tokens.tsx index 76e05bd4..ec6dd06c 100644 --- a/apps/app/src/pages/tokens.tsx +++ b/apps/app/src/pages/tokens.tsx @@ -20,7 +20,7 @@ export const getServerSideProps: GetServerSideProps<{ latestBlocks: any; }> = async (context) => { const { - query: { keyword = '', query = '', filter = 'all', ...qs }, + query: { ...qs }, }: { query: { query?: string; @@ -32,9 +32,6 @@ export const getServerSideProps: GetServerSideProps<{ const params = { ...qs, order: qs.order || 'desc' }; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - const fetchUrl = `fts?sort=onchain_market_cap&per_page=50&${QueryString.stringify( params, )}`; @@ -46,12 +43,7 @@ export const getServerSideProps: GetServerSideProps<{ fetcher(countUrl), ]); - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const dataCount = @@ -66,8 +58,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -80,8 +70,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -154,8 +142,6 @@ TopFTTokens.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/tokentxns.tsx b/apps/app/src/pages/tokentxns.tsx index fc2df4cf..f208e487 100644 --- a/apps/app/src/pages/tokentxns.tsx +++ b/apps/app/src/pages/tokentxns.tsx @@ -22,20 +22,11 @@ export const getServerSideProps: GetServerSideProps<{ latestBlocks: any; }> = async (context) => { const { - query: { keyword = '', query = '', filter = 'all', ...qs }, - }: { - query: { - query?: string; - keyword?: string; - filter?: string; - }; - } = context; + query: { ...qs }, + }: any = context; const apiUrl = 'fts/txns'; const fetchUrl = `${apiUrl}?${queryString.stringify(qs)}`; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - try { const [dataResult, dataCountResult, syncResult] = await Promise.allSettled([ fetcher(fetchUrl), @@ -43,12 +34,7 @@ export const getServerSideProps: GetServerSideProps<{ fetcher('sync/status'), ]); - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const dataCount = @@ -66,8 +52,6 @@ export const getServerSideProps: GetServerSideProps<{ error, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -81,8 +65,6 @@ export const getServerSideProps: GetServerSideProps<{ error: true, statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -155,8 +137,6 @@ ToxenTxns.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/txns/[hash].tsx b/apps/app/src/pages/txns/[hash].tsx index 755bd612..6892bfd9 100644 --- a/apps/app/src/pages/txns/[hash].tsx +++ b/apps/app/src/pages/txns/[hash].tsx @@ -56,37 +56,28 @@ export const getServerSideProps: GetServerSideProps<{ isContract: any; price: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; }> = async (context) => { const { - query: { hash = '', keyword = '', query = '', filter = 'all' }, + query: { hash = '' }, }: any = context; - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - try { const [dataResult] = await Promise.allSettled([fetcher(`txns/${hash}`)]); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const error = dataResult.status === 'rejected'; - const txn = data?.txns?.[0]; + const txn = data && data?.txns?.[0]; - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); let price: number | null = null; if (txn?.block_timestamp) { - const timestamp = new Date(nanoToMilli(txn.block_timestamp)); + const timestamp = new Date(nanoToMilli(txn?.block_timestamp)); const currentDate = new Date(); - const currentDt = currentDate.toISOString().split('T')[0]; - const blockDt = timestamp.toISOString().split('T')[0]; + const currentDt = + currentDate && currentDate?.toISOString()?.split('T')[0]; + const blockDt = timestamp && timestamp?.toISOString()?.split('T')[0]; if (currentDt > blockDt) { const priceData = await fetcher(`stats/price?date=${blockDt}`); @@ -101,7 +92,7 @@ export const getServerSideProps: GetServerSideProps<{ ]); isContract = - contractResult.status === 'fulfilled' ? contractResult.value : null; + contractResult?.status === 'fulfilled' ? contractResult?.value : null; } return { @@ -112,8 +103,6 @@ export const getServerSideProps: GetServerSideProps<{ isContract, price, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -126,8 +115,6 @@ export const getServerSideProps: GetServerSideProps<{ isContract: false, price: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -160,7 +147,7 @@ const Txn = ({ (store) => store.requestSignInWithWallet, ); - const txn = data?.txns?.[0]; + const txn = data && data?.txns?.[0]; let title = t('txns:txn.metaTitle', { txn: hash }); title = `${network === 'testnet' ? 'TESTNET' : ''} ${title}`; @@ -230,7 +217,7 @@ const Txn = ({ try { setRpcError(false); const txnExists: any = await transactionStatus(hash, 'bowen'); - const status = txnExists.status?.Failure ? false : true; + const status = txnExists?.status?.Failure ? false : true; let block: any = {}; if (txnExists) { @@ -240,31 +227,31 @@ const Txn = ({ } const modifiedTxns = { - transaction_hash: txnExists.transaction_outcome.id, - included_in_block_hash: txnExists.transaction_outcome.block_hash, + transaction_hash: txnExists?.transaction_outcome?.id, + included_in_block_hash: txnExists?.transaction_outcome?.block_hash, outcomes: { status: status }, - block: { block_height: block?.header.height }, - block_timestamp: block?.header.timestamp_nanosec, - receiver_account_id: txnExists.transaction.receiver_id, - signer_account_id: txnExists.transaction.signer_id, + block: { block_height: block?.header?.height }, + block_timestamp: block?.header?.timestamp_nanosec, + receiver_account_id: txnExists?.transaction?.receiver_id, + signer_account_id: txnExists?.transaction?.signer_id, receipt_conversion_gas_burnt: - txnExists.transaction_outcome.outcome.gas_burnt.toString(), + txnExists?.transaction_outcome?.outcome?.gas_burnt?.toString(), receipt_conversion_tokens_burnt: - txnExists.transaction_outcome.outcome.tokens_burnt, + txnExists.transaction_outcome?.outcome?.tokens_burnt, actions_agg: { - deposit: calculateTotalDeposit(txnExists?.transaction.actions), - gas_attached: calculateTotalGas(txnExists?.transaction.actions), + deposit: calculateTotalDeposit(txnExists?.transaction?.actions), + gas_attached: calculateTotalGas(txnExists?.transaction?.actions), }, outcomes_agg: { transaction_fee: txnFee( (txnExists?.receipts_outcome as ExecutionOutcomeWithIdView[]) ?? [], - txnExists?.transaction_outcome.outcome.tokens_burnt ?? '0', + txnExists?.transaction_outcome?.outcome?.tokens_burnt ?? '0', ), gas_used: calculateGasUsed( (txnExists?.receipts_outcome as ExecutionOutcomeWithIdView[]) ?? [], - txnExists?.transaction_outcome.outcome.gas_burnt ?? '0', + txnExists?.transaction_outcome?.outcome?.gas_burnt ?? '0', ), }, }; @@ -313,7 +300,7 @@ const Txn = ({
-

+

{t ? t('txns:txn.heading') : 'Transaction Details'}

@@ -477,8 +464,6 @@ Txn.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/txns/index.tsx b/apps/app/src/pages/txns/index.tsx index fc822caa..740692fa 100644 --- a/apps/app/src/pages/txns/index.tsx +++ b/apps/app/src/pages/txns/index.tsx @@ -20,21 +20,10 @@ export const getServerSideProps: GetServerSideProps<{ apiUrl: string; statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; }> = async (context) => { const { - query: { keyword = '', query = '', filter = 'all', ...qs }, - }: { - query: { - query?: string; - keyword?: string; - filter?: string; - }; - } = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); + query: { ...qs }, + }: any = context; const apiUrl = `txns`; const fetchUrl = `${apiUrl}?${queryString.stringify(qs)}`; @@ -46,12 +35,7 @@ export const getServerSideProps: GetServerSideProps<{ fetcher(countUrl), ]); - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); const data = dataResult.status === 'fulfilled' ? dataResult.value : null; const dataCount = @@ -66,8 +50,6 @@ export const getServerSideProps: GetServerSideProps<{ apiUrl, statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -80,8 +62,6 @@ export const getServerSideProps: GetServerSideProps<{ apiUrl: '', statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -139,8 +119,6 @@ TransactionList.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/pages/verify-contract/index.tsx b/apps/app/src/pages/verify-contract/index.tsx index f7520ff3..91fb853a 100644 --- a/apps/app/src/pages/verify-contract/index.tsx +++ b/apps/app/src/pages/verify-contract/index.tsx @@ -14,30 +14,14 @@ const ogUrl = env('NEXT_PUBLIC_OG_URL'); export const getServerSideProps: GetServerSideProps<{ statsDetails: any; latestBlocks: any; - searchResultDetails: any; - searchRedirectDetails: any; -}> = async (context) => { - const { - query: { keyword = '', query = '', filter = 'all' }, - }: any = context; - - const key = keyword?.replace(/[\s,]/g, ''); - const q = query?.replace(/[\s,]/g, ''); - +}> = async () => { try { - const { - statsDetails, - latestBlocks, - searchResultDetails, - searchRedirectDetails, - } = await fetchData(q, key, filter); + const { statsDetails, latestBlocks } = await fetchData(); return { props: { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, }, }; } catch (error) { @@ -46,8 +30,6 @@ export const getServerSideProps: GetServerSideProps<{ props: { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, }, }; } @@ -108,8 +90,6 @@ VerifyContract.getLayout = (page: ReactElement) => ( {page} diff --git a/apps/app/src/utils/fetchData.ts b/apps/app/src/utils/fetchData.ts index 0550ed27..08cc7121 100644 --- a/apps/app/src/utils/fetchData.ts +++ b/apps/app/src/utils/fetchData.ts @@ -1,21 +1,10 @@ import fetcher from './fetcher'; -import search from './search'; - -export async function fetchData(q?: string, keyword?: string, filter?: string) { - const key = keyword?.replace(/[\s,]/g, ''); - const query = q?.replace(/[\s,]/g, ''); +export async function fetchData() { try { - const [ - statsResult, - latestBlocksResult, - searchResult, - searchRedirectResult, - ] = await Promise.allSettled([ + const [statsResult, latestBlocksResult] = await Promise.allSettled([ fetcher(`stats`), fetcher(`blocks/latest?limit=1`), - key && filter ? search(key, filter, false) : Promise.resolve({}), - query && filter ? search(query, filter, true) : Promise.resolve({}), ]); const statsDetails = @@ -26,21 +15,12 @@ export async function fetchData(q?: string, keyword?: string, filter?: string) { ? latestBlocksResult.value : null; - const searchResultDetails = - searchResult.status === 'fulfilled' ? searchResult.value : {}; - - const searchRedirectDetails = - searchRedirectResult.status === 'fulfilled' - ? searchRedirectResult.value - : {}; - const error: boolean = statsResult.status === 'rejected'; return { statsDetails, latestBlocks, - searchResultDetails, - searchRedirectDetails, + error, }; } catch (error) { @@ -48,8 +28,6 @@ export async function fetchData(q?: string, keyword?: string, filter?: string) { return { statsDetails: null, latestBlocks: null, - searchResultDetails: null, - searchRedirectDetails: null, error: true, }; } diff --git a/apps/app/src/utils/search.ts b/apps/app/src/utils/search.ts index 46c724bd..0b068e20 100644 --- a/apps/app/src/utils/search.ts +++ b/apps/app/src/utils/search.ts @@ -1,4 +1,4 @@ -import fetcher from './fetcher'; +import { fetcher } from '@/hooks/useFetch'; const getRoute = (filter: string) => { switch (filter) { @@ -25,7 +25,7 @@ const search = async ( keyword = keyword.toLowerCase(); } - const resp = await fetcher(`search/${route}?keyword=${keyword}`); + const resp = await fetcher(`/search/${route}?keyword=${keyword}`); const data = { blocks: [], diff --git a/yarn.lock b/yarn.lock index c26efae5..f8bfcc59 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16902,6 +16902,14 @@ next@14.2.5: "@next/swc-win32-ia32-msvc" "14.2.5" "@next/swc-win32-x64-msvc" "14.2.5" +nextjs-toploader@3.7.15: + version "3.7.15" + resolved "https://registry.yarnpkg.com/nextjs-toploader/-/nextjs-toploader-3.7.15.tgz#2baba98b3d11c2001ab0639004ae5214d0e65f30" + integrity sha512-DvvXEJVRPfE2j1HVXgFhmPl8pRcLb/4mvyVBDuYdMdkbEY7KJghp0fG5iOZ002cV6awbBw9j/Di7vQL8LRazxQ== + dependencies: + nprogress "^0.2.0" + prop-types "^15.8.1" + node-addon-api@^5.0.0: version "5.1.0" resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.1.0.tgz#49da1ca055e109a23d537e9de43c09cca21eb762" @@ -17032,6 +17040,11 @@ npm-run-path@^5.1.0: dependencies: path-key "^4.0.0" +nprogress@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1" + integrity sha512-I19aIingLgR1fmhftnbWWO3dXc0hSxqHQHQb3H8m+K3TnEn/iSeTZZOyvKXWqQESMwuUVnatlCnZdLBZZt2VSA== + nth-check@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.1.1.tgz#c9eab428effce36cd6b92c924bdb000ef1f1ed1d"