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
|
2017-07-16 21:02:13 +00:00
|
|
|
const identiconDataUrl = isValidETHAddress(props.address.toLowerCase())
|
|
|
|
? toDataUrl(props.address.toLowerCase())
|
|
|
|
: '';
|
2017-07-02 05:49:06 +00:00
|
|
|
return (
|
|
|
|
<div
|
2017-07-16 21:02:13 +00:00
|
|
|
style={{ position: 'relative', width: size, height: size }}
|
2017-07-02 05:49:06 +00:00
|
|
|
title="Address Indenticon"
|
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
|
|
|
|
`
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{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
|
|
|
}
|