-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #3688 ## What has been done Added video support for wallet avatars ## Testing - [x] Test with video avatar (example user `0xab7375daf14bc661a0c9aff8800d49a34b037a98`) - [x] Test with image avatar Latest build: [extension-builds-3700](https://github.com/tahowallet/extension/suites/19135090954/artifacts/1121162389) (as of Mon, 18 Dec 2023 11:20:52 GMT).
- Loading branch information
Showing
7 changed files
with
133 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { CSSProperties, useEffect, useState } from "react" | ||
|
||
type SharedAvatarProps = { | ||
width: string | ||
background?: string | ||
borderRadius?: string | ||
avatarURL?: string | ||
backupAvatar: string | ||
style?: CSSProperties | ||
} | ||
|
||
async function getAvatarType(url?: string) { | ||
if (!url) return null | ||
|
||
try { | ||
const fileTypeFetch = await fetch(url, { method: "HEAD" }) | ||
const fileType = fileTypeFetch.headers.get("Content-Type") | ||
|
||
return fileType | ||
} catch { | ||
return null | ||
} | ||
} | ||
|
||
export default function SharedAvatar({ | ||
width, | ||
background = "var(--green-40)", | ||
borderRadius = "12px", | ||
avatarURL, | ||
backupAvatar, | ||
style, | ||
}: SharedAvatarProps) { | ||
const [avatarType, setAvatarType] = useState<string | null>(null) | ||
|
||
useEffect(() => { | ||
const fetchAvatarType = async () => { | ||
const type = await getAvatarType(avatarURL) | ||
setAvatarType(type) | ||
} | ||
|
||
fetchAvatarType() | ||
}, [avatarURL]) | ||
|
||
return ( | ||
<> | ||
<div className="avatar_container" style={style}> | ||
{avatarType === "video/mp4" ? ( | ||
<div className="video"> | ||
<video src={avatarURL} autoPlay muted loop /> | ||
</div> | ||
) : ( | ||
<div className="avatar" /> | ||
)} | ||
</div> | ||
<style jsx>{` | ||
.avatar_container { | ||
width: ${width}; | ||
height: ${width}; | ||
border-radius: ${borderRadius}; | ||
background-color: ${background}; | ||
flex-shrink: 0; | ||
} | ||
.avatar { | ||
width: 100%; | ||
height: 100%; | ||
border-radius: ${borderRadius}; | ||
flex-shrink: 0; | ||
background: url("${avatarURL ?? backupAvatar}"); | ||
background-size: cover; | ||
background-position: center; | ||
background-repeat: no-repeat; | ||
} | ||
.video { | ||
width: 100%; | ||
height: 100%; | ||
border-radius: ${borderRadius}; | ||
overflow: hidden; | ||
} | ||
.video > video { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
`}</style> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters