@@ -13,7 +13,7 @@ import useDefaultNavigate from '@subwallet/extension-koni-ui/hooks/router/useDef
1313import useGetChainInfo from '@subwallet/extension-koni-ui/hooks/screen/common/useFetchChainInfo' ;
1414import useGetAccountInfoByAddress from '@subwallet/extension-koni-ui/hooks/screen/common/useGetAccountInfoByAddress' ;
1515import InscriptionImage from '@subwallet/extension-koni-ui/Popup/Home/Nfts/component/InscriptionImage' ;
16- import { INftItemDetail , isValidJson } from '@subwallet/extension-koni-ui/Popup/Home/Nfts/utils' ;
16+ import { ContentType , determineContentType , getContentType , INftItemDetail , isValidJson } from '@subwallet/extension-koni-ui/Popup/Home/Nfts/utils' ;
1717import { RootState } from '@subwallet/extension-koni-ui/stores' ;
1818import { Theme , ThemeProps } from '@subwallet/extension-koni-ui/types' ;
1919import { BackgroundIcon , Field , Icon , Image , Logo , ModalContext , SwModal } from '@subwallet/react-ui' ;
@@ -139,13 +139,94 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
139139 const show3DModel = SHOW_3D_MODELS_CHAIN . includes ( nftItem . chain ) ;
140140 const ordinalNftItem = nftItem . description && isValidJson ( nftItem . description ) && JSON . parse ( nftItem . description ) as OrdinalRemarkData ;
141141 const isBRC20Inscription = useMemo ( ( ) => {
142- if ( ordinalNftItem && 'p' in ordinalNftItem && 'op' in ordinalNftItem && 'tick' in ordinalNftItem && 'amt' in ordinalNftItem ) {
142+ if ( typeof ordinalNftItem === 'object' && 'p' in ordinalNftItem && 'op' in ordinalNftItem && 'tick' in ordinalNftItem && 'amt' in ordinalNftItem ) {
143143 return true ;
144144 }
145145
146146 return false ;
147147 } , [ ordinalNftItem ] ) ;
148148
149+ const renderAppJsonContent = ( ) => {
150+ const ordinalNftDescription = nftItem ?. description && isValidJson ( nftItem . description )
151+ ? JSON . parse ( nftItem . description ) as Record < string , unknown >
152+ : undefined ;
153+
154+ if ( ! ordinalNftDescription || Object . keys ( ordinalNftDescription ) . length === 0 ) {
155+ return (
156+ < Image
157+ className = { CN ( { clickable : nftItem . externalUrl } ) }
158+ fallbackSrc = { DefaultLogosMap . default_placeholder }
159+ height = { 358 }
160+ modelViewerProps = { show3DModel ? { ...DEFAULT_MODEL_VIEWER_PROPS , ...CAMERA_CONTROLS_MODEL_VIEWER_PROPS } : undefined }
161+ onClick = { onImageClick }
162+ src = { nftItem . image || DefaultLogosMap . default_placeholder }
163+ width = { show3DModel ? 358 : undefined }
164+ />
165+ ) ;
166+ }
167+
168+ return (
169+ < div className = 'nft-container' >
170+ < pre >
171+ < code >
172+ { JSON . stringify ( ordinalNftDescription , null , 2 ) }
173+ </ code >
174+ </ pre >
175+ </ div >
176+ ) ;
177+ } ;
178+
179+ const renderNftContent = ( ) => {
180+ const contentType = determineContentType ( getContentType ( nftItem . properties ) ) ;
181+
182+ switch ( contentType ) {
183+ case ContentType . Audio :
184+ return (
185+ < div className = '-nft-audio' >
186+ < audio controls >
187+ < source
188+ src = { nftItem . image }
189+ type = { getContentType ( nftItem ?. properties ) }
190+ />
191+ </ audio >
192+ </ div >
193+ ) ;
194+
195+ case ContentType . AppJson :
196+ return renderAppJsonContent ( ) ;
197+
198+ case ContentType . TextHTML :
199+ case ContentType . ImageSVG :
200+ case ContentType . ModelGltf :
201+ case ContentType . ImageGIF :
202+ return (
203+ < div className = '-nft-text-html-wrapper' >
204+ < iframe
205+ className = '-nft-text-html'
206+ src = { nftItem . image }
207+ />
208+ </ div >
209+ ) ;
210+
211+ default :
212+ if ( ! isBRC20Inscription ) {
213+ return (
214+ < Image
215+ className = { CN ( { clickable : nftItem . externalUrl } ) }
216+ fallbackSrc = { DefaultLogosMap . default_placeholder }
217+ height = { 358 }
218+ modelViewerProps = { show3DModel ? { ...DEFAULT_MODEL_VIEWER_PROPS , ...CAMERA_CONTROLS_MODEL_VIEWER_PROPS } : undefined }
219+ onClick = { onImageClick }
220+ src = { nftItem . image || DefaultLogosMap . default_placeholder }
221+ width = { show3DModel ? 358 : undefined }
222+ />
223+ ) ;
224+ }
225+
226+ return null ;
227+ }
228+ } ;
229+
149230 return (
150231 < PageWrapper
151232 className = { `${ className } ` }
@@ -162,23 +243,15 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
162243 >
163244 < div className = { 'nft_item_detail__container' } >
164245 < div className = { 'nft_item_detail__nft_image' } >
165- { isBRC20Inscription && nftItem . description && (
166- < InscriptionImage
167- alone = { true }
168- properties = { JSON . parse ( nftItem . description ) as OrdinalRemarkData }
169- />
170- ) }
171- { ! isBRC20Inscription && (
172- < Image
173- className = { CN ( { clickable : nftItem . externalUrl } ) }
174- fallbackSrc = { DefaultLogosMap . default_placeholder }
175- height = { 358 }
176- modelViewerProps = { show3DModel ? { ...DEFAULT_MODEL_VIEWER_PROPS , ...CAMERA_CONTROLS_MODEL_VIEWER_PROPS } : undefined }
177- onClick = { onImageClick }
178- src = { nftItem . image || DefaultLogosMap . default_placeholder }
179- width = { show3DModel ? 358 : undefined }
180- />
181- ) }
246+ < >
247+ { isBRC20Inscription && nftItem . description && (
248+ < InscriptionImage
249+ alone = { true }
250+ properties = { JSON . parse ( nftItem . description ) as OrdinalRemarkData }
251+ />
252+ ) }
253+ { renderNftContent ( ) }
254+ </ >
182255 </ div >
183256
184257 < div className = { 'nft_item_detail__info_container' } >
@@ -307,6 +380,40 @@ const NftItemDetail = styled(Component)<Props>(({ theme: { token } }: Props) =>
307380 '.clickable' : {
308381 cursor : 'pointer'
309382 } ,
383+ '.-nft-audio' : {
384+ display : 'flex' ,
385+ alignItems : 'center'
386+ } ,
387+ '.-nft-text-html' : {
388+ width : 358 ,
389+ height : 358 ,
390+ border : 'none' ,
391+ overflow : 'hidden'
392+ } ,
393+ '.nft-container' : {
394+ width : 358 ,
395+ height : 358 ,
396+ backgroundColor : token . colorTextTertiary ,
397+ padding : token . padding ,
398+ gap : 8 ,
399+ display : 'flex' ,
400+ flexDirection : 'column' ,
401+ overflow : 'hidden'
402+ } ,
403+ '.__nft-item' : {
404+ fontSize : token . fontSize ,
405+ lineHeight : token . lineHeight ,
406+ color : token . colorTextDark1 ,
407+ justifyContent : 'space-between' ,
408+ display : 'flex' ,
409+ gap : 4
410+
411+ } ,
412+ '.__nft-item-value' : {
413+ color : token . colorTextDark4 ,
414+ overflow : 'hidden' ,
415+ textOverflow : 'ellipsis'
416+ } ,
310417
311418 '.nft_item_detail__info_container' : {
312419 display : 'flex' ,
0 commit comments