-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathNFT.tsx
More file actions
79 lines (71 loc) · 2.13 KB
/
Copy pathNFT.tsx
File metadata and controls
79 lines (71 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { FC, PropsWithChildren, useState } from 'react'
import { useParams } from 'react-router'
import { Helmet } from 'react-helmet-async'
import { useQuery } from 'react-query'
import NoMatch from '../NoMatch'
import { NFTHeader } from './NFTHeader/NFTHeader'
import { NFTTabs } from './NFTTabs/NFTTabs'
import { useAnalytics } from '../shared/analytics'
import { NOT_FOUND, BAD_REQUEST } from '../shared/utils'
import { ErrorMessage } from '../shared/Interfaces'
import { parseIssuerFromNFTokenID } from '../../rippled/NFTTransactions'
import './styles.scss'
const ERROR_MESSAGES: { [code: number]: ErrorMessage } = {
[NOT_FOUND]: {
title: 'assets.no_nfts_message',
hints: ['check_nft_id'],
},
[BAD_REQUEST]: {
title: 'invalid_xrpl_address',
hints: ['check_nft_id'],
},
}
const DEFAULT_ERROR: ErrorMessage = {
title: 'generic_error',
hints: ['not_your_fault'],
}
const getErrorMessage = (error: any) => ERROR_MESSAGES[error] ?? DEFAULT_ERROR
const Page: FC<PropsWithChildren<{ tokenId: string }>> = ({
tokenId,
children,
}) => (
<div className="nft-page">
<Helmet title={`NFT ${tokenId.substring(0, 12)}...`} />
{children}
</div>
)
export const NFT = () => {
const { trackScreenLoaded } = useAnalytics()
const { id: tokenId = '' } = useParams<{ id: string }>()
const [error, setError] = useState<number | null>(null)
useQuery(['screen-load', tokenId], () => {
trackScreenLoaded({
nftoken_id: tokenId,
issuer: parseIssuerFromNFTokenID(tokenId),
})
window.scrollTo(0, 0)
return null
})
const renderError = () => {
const message = getErrorMessage(error)
return (
<div className="token-page">
<NoMatch title={message.title} hints={message.hints} />
</div>
)
}
if (error) {
return <Page tokenId={tokenId}>{renderError()}</Page>
}
return (
<Page tokenId={tokenId}>
{tokenId && <NFTHeader tokenId={tokenId} setError={setError} />}
{tokenId && <NFTTabs tokenId={tokenId} />}
{!tokenId && (
<div className="nft-warning">
<h2>Enter a NFT ID in the search box</h2>
</div>
)}
</Page>
)
}