diff --git a/background/main.ts b/background/main.ts index 7c5170963..a9e1df4c5 100644 --- a/background/main.ts +++ b/background/main.ts @@ -1059,11 +1059,15 @@ export default class Main extends BaseService { this.store.dispatch(updateAccountName({ ...addressOnNetwork, name })) }, ) + this.nameService.emitter.on( "resolvedAvatar", async ({ from: { addressOnNetwork }, resolved: { avatar } }) => { this.store.dispatch( - updateENSAvatar({ ...addressOnNetwork, avatar: avatar.toString() }), + updateENSAvatar({ + ...addressOnNetwork, + avatar: avatar.toString(), + }), ) }, ) diff --git a/background/redux-slices/accounts.ts b/background/redux-slices/accounts.ts index 80bb2533d..0dffc8789 100644 --- a/background/redux-slices/accounts.ts +++ b/background/redux-slices/accounts.ts @@ -387,7 +387,9 @@ const accountSlice = createSlice({ immerState, { payload: { address, network, avatar }, - }: { payload: AddressOnNetwork & { avatar: URI } }, + }: { + payload: AddressOnNetwork & { avatar: URI } + }, ) => { const normalizedAddress = normalizeEVMAddress(address) diff --git a/background/redux-slices/selectors/accountsSelectors.ts b/background/redux-slices/selectors/accountsSelectors.ts index 282e907e7..95bf3b1ef 100644 --- a/background/redux-slices/selectors/accountsSelectors.ts +++ b/background/redux-slices/selectors/accountsSelectors.ts @@ -458,6 +458,8 @@ function getNetworkAccountTotalsByCategory( } } + const { name, avatarURL } = accountData.ens + return { address, network, @@ -466,8 +468,8 @@ function getNetworkAccountTotalsByCategory( signerId, path, accountSigner, - name: accountData.ens.name ?? accountData.defaultName, - avatarURL: accountData.ens.avatarURL ?? accountData.defaultAvatar, + name: name ?? accountData.defaultName, + avatarURL: avatarURL ?? accountData.defaultAvatar, localizedTotalMainCurrencyAmount: formatCurrencyAmount( mainCurrencySymbol, getTotalBalance(accountData.balances, prices, mainCurrencySymbol), diff --git a/ui/components/Shared/SharedAccountItemSummary.tsx b/ui/components/Shared/SharedAccountItemSummary.tsx index ce174e777..6ec6d36e9 100644 --- a/ui/components/Shared/SharedAccountItemSummary.tsx +++ b/ui/components/Shared/SharedAccountItemSummary.tsx @@ -4,6 +4,17 @@ import { AccountTotal } from "@tallyho/tally-background/redux-slices/selectors" import { useTranslation } from "react-i18next" import SharedLoadingSpinner from "./SharedLoadingSpinner" +import SharedAvatar from "./SharedAvatar" + +function Avatar({ avatarURL }: { avatarURL?: string }) { + return ( + + ) +} interface Props { isSelected?: boolean @@ -33,10 +44,10 @@ export default function SharedAccountItemSummary(props: Props): ReactElement {
{isSelected ? (
-
+
) : ( -
+ )}
@@ -91,16 +102,6 @@ export default function SharedAccountItemSummary(props: Props): ReactElement { padding: 5px 0; overflow: hidden; } - .avatar { - background: url("${avatarURL ?? "./images/avatar@2x.png"}") center - no-repeat; - background-color: var(--green-40); - background-size: cover; - width: 48px; - height: 48px; - border-radius: 12px; - flex-shrink: 0; - } .avatar_selected_outline { width: 52px; height: 52px; diff --git a/ui/components/Shared/SharedAddressAvatar.tsx b/ui/components/Shared/SharedAddressAvatar.tsx index 0db8c4200..e5ecdc383 100644 --- a/ui/components/Shared/SharedAddressAvatar.tsx +++ b/ui/components/Shared/SharedAddressAvatar.tsx @@ -1,4 +1,10 @@ import React, { ReactElement } from "react" +import SharedAvatar from "./SharedAvatar" + +type SharedAddressAvatarProps = { + address: string + url?: string +} /* @TODO Switch to using our own resolution service, especially @@ -7,25 +13,14 @@ once we upgrade our service to support whatever else Effigy can do. export default function SharedAddressAvatar({ address, url, -}: { - address: string - url?: string -}): ReactElement { +}: SharedAddressAvatarProps): ReactElement { return ( -
- -
+ ) } diff --git a/ui/components/Shared/SharedAvatar.tsx b/ui/components/Shared/SharedAvatar.tsx new file mode 100644 index 000000000..157387a42 --- /dev/null +++ b/ui/components/Shared/SharedAvatar.tsx @@ -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(null) + + useEffect(() => { + const fetchAvatarType = async () => { + const type = await getAvatarType(avatarURL) + setAvatarType(type) + } + + fetchAvatarType() + }, [avatarURL]) + + return ( + <> +
+ {avatarType === "video/mp4" ? ( +
+
+ ) : ( +
+ )} +
+ + + ) +} diff --git a/ui/components/Shared/SharedCurrentAccountInformation.tsx b/ui/components/Shared/SharedCurrentAccountInformation.tsx index 1b3ec8ff6..70070e404 100644 --- a/ui/components/Shared/SharedCurrentAccountInformation.tsx +++ b/ui/components/Shared/SharedCurrentAccountInformation.tsx @@ -2,6 +2,7 @@ import React, { ReactElement } from "react" import classNames from "classnames" import SharedIcon from "./SharedIcon" import { useAreInternalSignersUnlocked } from "../../hooks/signing-hooks" +import SharedAvatar from "./SharedAvatar" type Props = { shortenedAddress: string @@ -25,7 +26,12 @@ export default function SharedCurrentAccountInformation({ {name ?? shortenedAddress} -
+ {showLockStatus && (