Make icon generation more robust (#632)

* Make icon generation more robust

* Update packages/ui-shared/src/icons/polkadot.ts
This commit is contained in:
Jaco authored and GitHub committed 2022-04-06 16:00:26 +03:00
1 parent fb360420e5
commit e598c7bb42
4 files changed
+39 -12

No files matched your search

@@ -4,15 +4,18 @@
import type { Props } from '../types';
import * as jdenticon from 'jdenticon';
import React from 'react';
import React, { useMemo } from 'react';
function Identicon ({ className = '', publicKey, size, style }: Props): React.ReactElement<Props> {
const html = useMemo(
() => ({ __html: jdenticon.toSvg(publicKey.substr(2), size) }),
[publicKey, size]
);
return (
<div
className={className}
dangerouslySetInnerHTML={{
__html: jdenticon.toSvg(publicKey.substr(2), size)
}}
dangerouslySetInnerHTML={html}
style={style}
/>
);
@@ -19,7 +19,7 @@
import type { Circle } from '@polkadot/ui-shared/icons/types';
import type { Props } from '../types';
import React from 'react';
import React, { useMemo } from 'react';
import { polkadotIcon } from '@polkadot/ui-shared';
@@ -36,6 +36,11 @@ function renderCircle ({ cx, cy, fill, r }: Circle, key: number): React.ReactNod
}
function Identicon ({ address, className = '', isAlternative = false, size, style }: Props): React.ReactElement<Props> {
const circles = useMemo(
() => polkadotIcon(address, { isAlternative }),
[address, isAlternative]
);
return (
<svg
className={className}
@@ -46,7 +51,7 @@ function Identicon ({ address, className = '', isAlternative = false, size, styl
viewBox='0 0 64 64'
width={size}
>
{polkadotIcon(address, { isAlternative }).map(renderCircle)}
{circles.map(renderCircle)}
</svg>
);
}