MyCrypto/common/components/ui/Identicon.jsx

50 lines
1.1 KiB
React
Raw Normal View History

2017-06-26 23:27:26 +00:00
// @flow
2017-06-26 22:27:55 +00:00
import React from 'react';
import { toDataUrl } from 'ethereum-blockies';
2017-06-26 23:27:26 +00:00
import { isValidETHAddress } from 'libs/validators';
2017-06-26 22:27:55 +00:00
type Props = {
address: string,
size?: string
2017-06-26 22:27:55 +00:00
};
export default function Identicon(props: Props) {
const size = props.size || '4rem';
2017-07-02 05:49:06 +00:00
// FIXME breaks on failed checksums
const identiconDataUrl = isValidETHAddress(props.address.toLowerCase())
? toDataUrl(props.address.toLowerCase())
: '';
2017-07-02 05:49:06 +00:00
return (
<div
style={{ position: 'relative', width: size, height: size }}
2017-07-02 05:49:06 +00:00
title="Address Indenticon"
>
<div
style={{
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
borderRadius: '50%',
boxShadow: `
inset rgba(255, 255, 255, 0.5) 0 2px 2px,
inset rgba(0, 0, 0, 0.6) 0 -1px 8px
`
}}
/>
{identiconDataUrl &&
<img
src={identiconDataUrl}
style={{
borderRadius: '50%',
width: '100%',
height: '100%'
}}
/>}
</div>
2017-07-02 05:49:06 +00:00
);
2017-06-26 22:27:55 +00:00
}