Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
350147a4
Commit
350147a4
authored
Feb 09, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
display video
parent
47c7f5d5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
191 additions
and
3 deletions
+191
-3
getCspPolicy.ts
lib/csp/getCspPolicy.ts
+3
-0
NFTItem.tsx
ui/address/tokens/NFTItem.tsx
+1
-1
NftImage.tsx
ui/shared/nft/NftImage.tsx
+83
-0
NftMedia.tsx
ui/shared/nft/NftMedia.tsx
+56
-0
NftVideo.tsx
ui/shared/nft/NftVideo.tsx
+40
-0
TokenInstanceDetails.tsx
ui/tokenInstance/TokenInstanceDetails.tsx
+8
-2
No files found.
lib/csp/getCspPolicy.ts
View file @
350147a4
...
...
@@ -141,6 +141,9 @@ function makePolicyMap() {
// walletconnect
'
*.walletconnect.com
'
,
// token's media
'
ipfs.io
'
,
],
'
font-src
'
:
[
...
...
ui/address/tokens/NFTItem.tsx
View file @
350147a4
...
...
@@ -4,7 +4,7 @@ import React from 'react';
import
type
{
AddressTokenBalance
}
from
'
types/api/address
'
;
import
link
from
'
lib/link/link
'
;
import
NftImage
from
'
ui/shared/NftImage
'
;
import
NftImage
from
'
ui/shared/
nft/
NftImage
'
;
import
TokenLogo
from
'
ui/shared/TokenLogo
'
;
import
TruncatedTextTooltip
from
'
ui/shared/TruncatedTextTooltip
'
;
...
...
ui/shared/NftImage.tsx
→
ui/shared/
nft/
NftImage.tsx
View file @
350147a4
import
{
AspectRatio
,
chakra
,
Icon
,
Image
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
type
{
ResponsiveValue
}
from
'
@chakra-ui/react
'
;
import
{
AspectRatio
,
chakra
,
Icon
,
Image
,
shouldForwardProp
,
Skeleton
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
type
{
Property
}
from
'
csstype
'
;
import
React
from
'
react
'
;
import
nftIcon
from
'
icons/nft_shield.svg
'
;
...
...
@@ -7,6 +9,7 @@ interface Props {
url
:
string
|
null
;
className
?:
string
;
fallbackPadding
?:
string
;
objectFit
:
ResponsiveValue
<
Property
.
ObjectFit
>
;
}
interface
FallbackProps
{
...
...
@@ -25,7 +28,19 @@ const Fallback = ({ className, padding }: FallbackProps) => {
);
};
const
NftImage
=
({
url
,
className
,
fallbackPadding
}:
Props
)
=>
{
const
NftImage
=
({
url
,
className
,
fallbackPadding
,
objectFit
}:
Props
)
=>
{
const
[
isLoading
,
setIsLoading
]
=
React
.
useState
(
true
);
const
handleLoad
=
React
.
useCallback
(()
=>
{
setIsLoading
(
false
);
},
[]);
const
handleLoadError
=
React
.
useCallback
(()
=>
{
setIsLoading
(
false
);
},
[]);
const
_objectFit
=
objectFit
||
'
contain
'
;
return
(
<
AspectRatio
className=
{
className
}
...
...
@@ -35,20 +50,34 @@ const NftImage = ({ url, className, fallbackPadding }: Props) => {
borderRadius=
"md"
sx=
{
{
'
&>img
'
:
{
objectFit
:
'
contain
'
,
objectFit
:
_objectFit
,
},
}
}
>
<
Image
w=
"100%"
h=
"100%"
objectFit=
"contain"
objectFit=
{
_objectFit
}
src=
{
url
||
undefined
}
alt=
"Token instance image"
fallback=
{
<
Fallback
className=
{
className
}
padding=
{
fallbackPadding
}
/>
}
fallback=
{
url
&&
isLoading
?
<
Skeleton
/>
:
<
Fallback
className=
{
className
}
padding=
{
fallbackPadding
}
/>
}
onError=
{
handleLoadError
}
onLoad=
{
handleLoad
}
/>
</
AspectRatio
>
);
};
export
default
chakra
(
NftImage
);
const
NftImageChakra
=
chakra
(
NftImage
,
{
shouldForwardProp
:
(
prop
)
=>
{
const
isChakraProp
=
!
shouldForwardProp
(
prop
);
if
(
isChakraProp
&&
prop
!==
'
objectFit
'
)
{
return
false
;
}
return
true
;
},
});
export
default
NftImageChakra
;
ui/shared/nft/NftMedia.tsx
0 → 100644
View file @
350147a4
import
{
AspectRatio
,
chakra
,
Skeleton
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
NftImage
from
'
./NftImage
'
;
import
NftVideo
from
'
./NftVideo
'
;
interface
Props
{
imageUrl
:
string
|
null
;
animationUrl
:
string
|
null
;
className
?:
string
;
}
const
NftMedia
=
({
imageUrl
,
animationUrl
,
className
}:
Props
)
=>
{
const
[
type
,
setType
]
=
React
.
useState
<
'
image
'
|
'
video
'
|
undefined
>
(
!
animationUrl
?
'
image
'
:
undefined
);
React
.
useEffect
(()
=>
{
if
(
!
animationUrl
)
{
return
;
}
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
'
HEAD
'
,
animationUrl
,
true
);
xhr
.
onload
=
function
()
{
const
contentType
=
xhr
.
getResponseHeader
(
'
Content-Type
'
);
setType
(
contentType
?.
startsWith
(
'
video
'
)
?
'
video
'
:
'
image
'
);
};
xhr
.
send
();
return
()
=>
{
xhr
.
abort
();
};
},
[
animationUrl
]);
if
(
!
type
)
{
return
(
<
AspectRatio
className=
{
className
}
ratio=
{
1
/
1
}
overflow=
"hidden"
borderRadius=
"md"
>
<
Skeleton
/>
</
AspectRatio
>
);
}
if
(
animationUrl
&&
type
===
'
video
'
)
{
return
<
NftVideo
className=
{
className
}
src=
{
animationUrl
}
/>;
}
return
<
NftImage
className=
{
className
}
url=
{
animationUrl
||
imageUrl
}
/>;
};
export
default
chakra
(
NftMedia
);
ui/shared/nft/NftVideo.tsx
0 → 100644
View file @
350147a4
import
{
AspectRatio
,
Skeleton
,
chakra
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
interface
Props
{
className
?:
string
;
src
:
string
;
}
const
NftVideo
=
({
className
,
src
}:
Props
)
=>
{
const
[
isLoading
,
setIsLoading
]
=
React
.
useState
(
true
);
const
handleCanPlay
=
React
.
useCallback
(()
=>
{
setIsLoading
(
false
);
},
[]);
return
(
<
AspectRatio
className=
{
className
}
ratio=
{
1
/
1
}
overflow=
"hidden"
borderRadius=
"md"
>
<>
<
chakra
.
video
src=
{
src
}
autoPlay
disablePictureInPicture
loop
muted
playsInline
onCanPlayThrough=
{
handleCanPlay
}
borderRadius=
"md"
/>
{
isLoading
&&
<
Skeleton
position=
"absolute"
w=
"100%"
h=
"100%"
left=
{
0
}
top=
{
0
}
/>
}
</>
</
AspectRatio
>
);
};
export
default
chakra
(
NftVideo
);
ui/tokenInstance/TokenInstanceDetails.tsx
View file @
350147a4
...
...
@@ -9,7 +9,7 @@ import AddressLink from 'ui/shared/address/AddressLink';
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
DetailsInfoItem
from
'
ui/shared/DetailsInfoItem
'
;
import
HashStringShortenDynamic
from
'
ui/shared/HashStringShortenDynamic
'
;
import
Nft
Image
from
'
ui/shared/NftImage
'
;
import
Nft
Media
from
'
ui/shared/nft/NftMedia
'
;
import
TokenSnippet
from
'
ui/shared/TokenSnippet/TokenSnippet
'
;
import
TokenInstanceCreatorAddress
from
'
./details/TokenInstanceCreatorAddress
'
;
...
...
@@ -66,7 +66,13 @@ const TokenInstanceDetails = ({ data, scrollRef }: Props) => {
</
DetailsInfoItem
>
<
TokenInstanceTransfersCount
hash=
{
data
.
token
.
address
}
id=
{
data
.
id
}
onClick=
{
handleCounterItemClick
}
/>
</
Grid
>
<
NftImage
url=
{
data
.
image_url
}
w=
"250px"
flexShrink=
{
0
}
alignSelf=
{
{
base
:
'
center
'
,
lg
:
'
flex-start
'
}
}
/>
<
NftMedia
imageUrl=
{
data
.
image_url
}
animationUrl=
{
data
.
animation_url
}
w=
"250px"
flexShrink=
{
0
}
alignSelf=
{
{
base
:
'
center
'
,
lg
:
'
flex-start
'
}
}
/>
</
Flex
>
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment