mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-06-17 02:01:03 +00:00
Make icon generation more robust (#632)
* Make icon generation more robust * Update packages/ui-shared/src/icons/polkadot.ts
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user