Skip to content

Commit

Permalink
fix: fix hash type on he script page
Browse files Browse the repository at this point in the history
Hash type should not be cast into 'data' and 'type'

Ref: Magickbase/ckb-explorer-public-issues#529
  • Loading branch information
Keith-CY committed Feb 19, 2024
1 parent 7b278f0 commit 187e5c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export enum LayoutLiteProfessional {
Lite = 'lite',
Professional = 'professional',
}
export enum HashType {
DATA = 'data',
DATA1 = 'data1',
TYPE = 'type',
}

export const MAINNET_URL = `https://${config.BASE_URL}`
export const TESTNET_URL = `https://${ChainName.Testnet}.${config.BASE_URL}`
16 changes: 13 additions & 3 deletions src/pages/Script/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { explorerService } from '../../services/ExplorerService'
import type { ScriptInfo } from '../../services/ExplorerService/fetcher'
import { ScriptTab, ScriptTabPane, ScriptTabTitle } from './styled'
import { Card, CardCellInfo, CardCellsLayout } from '../../components/Card'
import { HashType } from '../../constants/common'

const scriptDataList = isMainnet() ? MainnetContractHashTags : TestnetContractHashTags

Expand Down Expand Up @@ -98,8 +99,11 @@ export const ScriptPage = () => {
const { t } = useTranslation()
const currentLanguage = useCurrentLanguage()

const { codeHash, hashType: _hashType, tab } = useParams<{ codeHash: string; hashType: string; tab: ScriptTabType }>()
const hashType = _hashType === 'data' ? 'data' : 'type'
const { codeHash, hashType, tab } = useParams<{
codeHash: string
hashType: HashType
tab: ScriptTabType
}>()
const { currentPage, pageSize } = usePaginationParamsInPage()

const [countOfTransactions, setCountOfTransactions] = useState<number>(0)
Expand All @@ -122,7 +126,7 @@ export const ScriptPage = () => {
scriptName: '',
scriptType: '',
codeHash,
hashType,
hashType: hashType as HashType,
capacityOfDeployedCells: '0',
capacityOfReferringCells: '0',
countOfTransactions: 0,
Expand All @@ -137,6 +141,12 @@ export const ScriptPage = () => {
setCountOfReferringCells(scriptInfo.countOfReferringCells)
}, [scriptInfo.countOfDeployedCells, scriptInfo.countOfReferringCells, scriptInfo.countOfTransactions])

useEffect(() => {
if (!Object.values(HashType).includes(hashType as HashType)) {
history.replace('/404')
}
}, [hashType, history])

return (
<Content>
<div className={`${styles.scriptContentPanel} container`}>
Expand Down
3 changes: 2 additions & 1 deletion src/services/ExplorerService/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Block } from '../../models/Block'
import { Transaction } from '../../models/Transaction'
import { Address } from '../../models/Address'
import { OmigaInscriptionCollection, UDT } from '../../models/UDT'
import { HashType } from '../../constants/common'

async function v1Get<T>(...args: Parameters<typeof requesterV1.get>) {
return requesterV1.get(...args).then(res => toCamelcase<Response.Response<T>>(res.data))
Expand Down Expand Up @@ -889,7 +890,7 @@ export interface ScriptInfo {
scriptName: string
scriptType: string
codeHash: string
hashType: 'type' | 'data'
hashType: HashType
capacityOfDeployedCells: string
capacityOfReferringCells: string
countOfTransactions: number
Expand Down

0 comments on commit 187e5c4

Please sign in to comment.