-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd58460
commit 3557e63
Showing
7 changed files
with
72 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './snap-ui-avatar'; |
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,44 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { CaipAccountId, parseCaipAccountId } from '@metamask/utils'; | ||
import BlockieIdenticon from '../../../ui/identicon/blockieIdenticon'; | ||
import Jazzicon from '../../../ui/jazzicon'; | ||
import { getUseBlockie } from '../../../../selectors'; | ||
|
||
export const DIAMETERS: Record<string, number> = { | ||
'xs': 16, | ||
'sm': 24, | ||
'md': 32, | ||
'lg': 40, | ||
}; | ||
|
||
export type SnapUIAvatarProps = { | ||
// The address must be a CAIP-10 string. | ||
address: string; | ||
size?: string; | ||
}; | ||
|
||
export const SnapUIAvatar: React.FunctionComponent<SnapUIAvatarProps> = ({ | ||
address, | ||
size = 'md', | ||
}) => { | ||
const parsed = useMemo(() => { | ||
return parseCaipAccountId(address as CaipAccountId); | ||
}, [address]); | ||
const useBlockie = useSelector(getUseBlockie); | ||
|
||
return useBlockie ? ( | ||
<BlockieIdenticon | ||
address={parsed.address} | ||
diameter={DIAMETERS[size]} | ||
borderRadius="50%" | ||
/> | ||
) : ( | ||
<Jazzicon | ||
namespace={parsed.chain.namespace} | ||
address={parsed.address} | ||
diameter={DIAMETERS[size]} | ||
style={{ display: 'flex' }} | ||
/> | ||
); | ||
}; |
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
9 changes: 9 additions & 0 deletions
9
ui/components/app/snaps/snap-ui-renderer/components/avatar.ts
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,9 @@ | ||
import { AvatarElement } from '@metamask/snaps-sdk/jsx'; | ||
import { UIComponentFactory } from './types'; | ||
|
||
export const avatar: UIComponentFactory<AvatarElement> = ({ element }) => ({ | ||
element: 'SnapUIAvatar', | ||
props: { | ||
address: element.props.address, | ||
}, | ||
}); |
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