Skip to content

Commit

Permalink
fix: portal bitcoin assets compatibility (#2544)
Browse files Browse the repository at this point in the history
* fix: portal bitcoin assets compatibility

* feat: add dompurify
  • Loading branch information
jojoo-eth authored Aug 30, 2024
1 parent b98056b commit 4e6d0d3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 30 deletions.
2 changes: 2 additions & 0 deletions infra/rooch-portal-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"axios": "^1.7.2",
"bignumber.js": "^9.1.2",
"dayjs": "^1.11.11",
"dompurify": "^3.1.6",
"framer-motion": "^11.2.10",
"next": "^14.2.4",
"nprogress": "^0.2.0",
Expand All @@ -68,6 +69,7 @@
"devDependencies": {
"@svgr/webpack": "^8.1.0",
"@types/autosuggest-highlight": "^3.2.3",
"@types/dompurify": "^3.0.5",
"@types/node": "^20.14.2",
"@types/nprogress": "^0.2.3",
"@types/react": "^18.3.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { ReactNode } from 'react';
import type { IndexerStateIDView } from '@roochnetwork/rooch-sdk';

import { useRef, useMemo, useState } from 'react';
import { useRoochClientQuery } from '@roochnetwork/rooch-sdk-kit';

import { Box, Card, Skeleton, CardHeader, Typography, CardContent } from '@mui/material';

import { Box, Card, Chip, Skeleton, CardHeader, Typography, CardContent } from '@mui/material';
import DOMPurify from 'dompurify';
import { hexToString } from 'src/utils/common';

import { EmptyContent } from 'src/components/empty-content/empty-content';
Expand Down Expand Up @@ -61,33 +62,44 @@ export default function OrdinalList({ address }: { address: string }) {
}
>
{isOrdinalListPending ? (
Array.from({ length: 4 }).map((i,index) => <Skeleton key={index} height={256} />)
Array.from({ length: 4 }).map((i, index) => <Skeleton key={index} height={256} />)
) : ordinalList?.data.length === 0 ? (
<EmptyContent title="No Ordinals Found" sx={{ py: 3 }} />
) : (
ordinalList?.data.map((i) => (
<Card key={i.id} elevation={0} className="!bg-gray-100 !shadow-none">
<CardHeader title={i.value.inscription_number} subheader="Inscriptions #" />
<CardContent>
<Typography
noWrap
sx={{
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
overflowWrap: 'break-word',
}}
>
{i.value.content_type === 'text/plain;charset=utf-8'
? JSON.stringify(
JSON.parse(hexToString(i.value.body as unknown as string)),
null,
2
)
: i.value.content_type}
</Typography>
</CardContent>
</Card>
))
ordinalList?.data.map((i) => {
let parsePlainText: string | null | undefined | ReactNode = '';
try {
parsePlainText =
i.value.content_type === 'text/plain;charset=utf-8'
? DOMPurify.sanitize(JSON.stringify(
JSON.parse(hexToString(i.value.body as unknown as string)),
null,
2
))
: i.value.content_type;
} catch (error) {
parsePlainText = (
<Chip label="Parse Error" size="small" variant="soft" color="error" />
);
}
return (
<Card key={i.id} elevation={0} className="!bg-gray-100 !shadow-none">
<CardHeader title={i.value.inscription_number} subheader="Inscriptions #" />
<CardContent>
<Typography
noWrap
sx={{
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
overflowWrap: 'break-word',
}}
>
{parsePlainText}
</Typography>
</CardContent>
</Card>
);
})
)}
</CardContent>
</Card>
Expand Down
31 changes: 27 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e6d0d3

Please sign in to comment.