2017-06-26 22:27:55 +00:00
|
|
|
import { toDataUrl } from 'ethereum-blockies';
|
2017-06-26 23:27:26 +00:00
|
|
|
import { isValidETHAddress } from 'libs/validators';
|
2017-09-25 02:06:28 +00:00
|
|
|
import React from 'react';
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Props {
|
|
|
|
address: string;
|
|
|
|
size?: string;
|
|
|
|
}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
|
|
|
export default function Identicon(props: Props) {
|
2017-07-16 21:02:13 +00:00
|
|
|
const size = props.size || '4rem';
|
2017-07-02 05:49:06 +00:00
|
|
|
// FIXME breaks on failed checksums
|
2018-01-15 09:57:09 +00:00
|
|
|
const identiconDataUrl = isValidETHAddress(props.address) ? toDataUrl(props.address) : '';
|
2017-07-02 05:49:06 +00:00
|
|
|
return (
|
2017-12-15 00:51:42 +00:00
|
|
|
<div style={{ position: 'relative', width: size, height: size }} title="Address Identicon">
|
2017-07-16 21:02:13 +00:00
|
|
|
<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
|
|
|
|
`
|
|
|
|
}}
|
|
|
|
/>
|
2017-12-15 00:51:42 +00:00
|
|
|
{identiconDataUrl && (
|
2017-07-16 21:02:13 +00:00
|
|
|
<img
|
|
|
|
src={identiconDataUrl}
|
|
|
|
style={{
|
|
|
|
borderRadius: '50%',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%'
|
|
|
|
}}
|
2017-12-15 00:51:42 +00:00
|
|
|
/>
|
|
|
|
)}
|
2017-07-16 21:02:13 +00:00
|
|
|
</div>
|
2017-07-02 05:49:06 +00:00
|
|
|
);
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|