-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathMPT.tsx
More file actions
75 lines (67 loc) · 1.93 KB
/
Copy pathMPT.tsx
File metadata and controls
75 lines (67 loc) · 1.93 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
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 { MPTHeader } from './MPTHeader/MPTHeader'
import { useAnalytics } from '../shared/analytics'
import { NOT_FOUND, BAD_REQUEST } from '../shared/utils'
import { ErrorMessage } from '../shared/Interfaces'
import './styles.scss'
const ERROR_MESSAGES: { [code: number]: ErrorMessage } = {
[NOT_FOUND]: {
title: 'assets.no_mpts_message',
hints: ['check_mpt_id'],
},
[BAD_REQUEST]: {
title: 'invalid_xrpl_address',
hints: ['check_mpt_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="mpt-page">
<Helmet title={`MPT ${tokenId.substr(0, 12)}...`} />
{children}
</div>
)
export const MPT = () => {
const { trackScreenLoaded } = useAnalytics()
const { id: tokenId = '' } = useParams<{ id: string }>()
const [error, setError] = useState<number | null>(null)
useQuery(['screen-load', tokenId], () => {
trackScreenLoaded({
mpt_issuance_id: 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 && <MPTHeader tokenId={tokenId} setError={setError} />}
{!tokenId && (
<div className="mpt-warning">
<h2>Enter a MPT Issuance ID in the search box</h2>
</div>
)}
</Page>
)
}