Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support btc tx and address #268

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ReactComponent as SearchIcon } from './search.svg'
import { ReactComponent as SpinnerIcon } from './spinner.svg'
import { ReactComponent as ClearIcon } from './clear.svg'
import SimpleButton from '../SimpleButton'
import { isValidBTCAddress } from '../../utils/bitcoin'

// Currently, the API returns all search results, which could be extremely large in quantity.
// Since the rendering component does not implement virtual scrolling, this leads to a significant decrease in page performance.
Expand Down Expand Up @@ -63,7 +64,7 @@ const Search: FC<{
refetch: refetchSearchById,
data: urlByIdSearch,
isFetching: isFetchingById,
} = useQuery(['searchById', searchValue], () => getURLByIdSearch(addPrefixForHash(searchValue)), {
} = useQuery(['searchById', searchValue], () => getURLByIdSearch(searchValue), {
enabled: false,
cacheTime: 0,
})
Expand Down Expand Up @@ -194,8 +195,12 @@ const SearchInput: FC<
}

const getURLByIdSearch = async (searchValue: string) => {
// check whether is btc address
if (isValidBTCAddress(searchValue)) {
return `/address/${searchValue}`
}
// TODO: Is this replace needed?
const query = searchValue.replace(',', '')
const query = addPrefixForHash(searchValue).replace(',', '')
if (!query || containSpecialChar(query)) {
return `/search/fail?q=${query}`
}
Expand Down Expand Up @@ -225,6 +230,9 @@ const getURLByIdSearch = async (searchValue: string) => {
case SearchResultType.UDT:
return data.attributes.udtType === 'omiga_inscription' ? `/inscription/${query}` : `/sudt/${query}`

case SearchResultType.BTC_TX:
return `/transaction/${attributes.transactionHash}`

default:
break
}
Expand Down
6 changes: 6 additions & 0 deletions src/models/Transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ export interface Transaction {
maxCycles: number | null
createTimestamp?: number
}

export interface BtcTx {
txId: string
transactionHash: string
ckbTransactionHash: string
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 3 additions & 1 deletion src/services/ExplorerService/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { assert } from '../../utils/error'
import { Cell } from '../../models/Cell'
import { Script } from '../../models/Script'
import { Block } from '../../models/Block'
import { Transaction } from '../../models/Transaction'
import { BtcTx, Transaction } from '../../models/Transaction'
import { Address } from '../../models/Address'
import { OmigaInscriptionCollection, UDT } from '../../models/UDT'
import { HashType } from '../../constants/common'
Expand Down Expand Up @@ -56,6 +56,7 @@ export enum SearchResultType {
LockHash = 'lock_hash',
UDT = 'udt',
TypeScript = 'type_script',
BTC_TX = 'bitcoin_transaction',
}

export const apiFetcher = {
Expand Down Expand Up @@ -235,6 +236,7 @@ export const apiFetcher = {
| Response.Wrapper<Address, SearchResultType.Address>
| Response.Wrapper<Address, SearchResultType.LockHash>
| Response.Wrapper<UDT, SearchResultType.UDT>
| Response.Wrapper<BtcTx, SearchResultType.BTC_TX>
| Response.Wrapper<Script & { scriptHash: string }, SearchResultType.TypeScript>
>('suggest_queries', {
params: {
Expand Down