-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50ed1dc
commit 1e7adc1
Showing
24 changed files
with
658 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
frontend/src/app/(routes)/transactions/history/SearchTransaction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; | ||
import { getAnyChainTransaction } from '@/store/features/recent-transactions/recentTransactionsSlice'; | ||
import React, { useEffect, useState } from 'react'; | ||
import SearchTransactionHash from './[network]/components/SearchTransactionHash'; | ||
import { TxStatus } from '@/types/enums'; | ||
import { parseTxnData } from '@/utils/util'; | ||
import Transaction from './[network]/components/Transaction'; | ||
import useGetChainInfo from '@/custom-hooks/useGetChainInfo'; | ||
import { CircularProgress } from '@mui/material'; | ||
|
||
const SearchTransaction = () => { | ||
const dispatch = useAppDispatch(); | ||
const { getChainInfo } = useGetChainInfo(); | ||
const [searchQuery, setSearchQuery] = useState(''); | ||
|
||
const handleSearchQueryChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchQuery(e.target.value); | ||
}; | ||
|
||
const handleClearSearch = () => { | ||
setSearchQuery(''); | ||
}; | ||
|
||
const onSearch = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
if (searchQuery) dispatch(getAnyChainTransaction({ txhash: searchQuery })); | ||
}; | ||
|
||
const loading = useAppSelector( | ||
(state) => state.recentTransactions.txn?.status | ||
); | ||
|
||
const txnResult = useAppSelector( | ||
(state) => state.recentTransactions.txn?.data?.[0] | ||
); | ||
const { txHash = '' } = txnResult ? parseTxnData(txnResult) : {}; | ||
|
||
const [chainID, setChainID] = useState(''); | ||
const { chainName } = getChainInfo(chainID); | ||
|
||
useEffect(() => { | ||
if (txnResult) { | ||
setChainID(txnResult.chain_id); | ||
} | ||
}, [txnResult]); | ||
|
||
return ( | ||
<div className="w-full"> | ||
<form onSubmit={onSearch} className="flex gap-6 items-center"> | ||
<SearchTransactionHash | ||
searchQuery={searchQuery} | ||
handleSearchQueryChange={handleSearchQueryChange} | ||
handleClearSearch={handleClearSearch} | ||
/> | ||
<button type="submit" className="primary-btn"> | ||
Search | ||
</button> | ||
</form> | ||
|
||
{loading === TxStatus.PENDING ? ( | ||
<div className="flex-center-center gap-2 my-[25%]"> | ||
<CircularProgress sx={{ color: 'white' }} size={18} /> | ||
<div className="italic font-extralight text-[14px]"> | ||
Fetching transaction info <span className="dots-flashing"></span> | ||
</div> | ||
</div> | ||
) : ( | ||
<> | ||
{txnResult && chainID && chainName ? ( | ||
<Transaction | ||
hash={txHash} | ||
chainName={chainName} | ||
chainID={chainID} | ||
isSearchPage | ||
/> | ||
) : null} | ||
</> | ||
)} | ||
<TransactionNotFound /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchTransaction; | ||
|
||
const TransactionNotFound = () => { | ||
const txSearchError = useAppSelector( | ||
(state) => state.recentTransactions.txn.error | ||
); | ||
|
||
if (txSearchError) | ||
return ( | ||
<div className="w-full my-[25%]"> | ||
<p className="text-h2 font-bold w-fit mx-auto"> | ||
Sorry, the transaction you're looking for is not found. | ||
</p> | ||
</div> | ||
); | ||
return <></>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.