Skip to content

Commit

Permalink
ChainLogo bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed May 9, 2024
1 parent 16fa06f commit 8c47ba8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/icons/ChainLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, memo, useEffect, useState } from 'react';
import React, { ReactElement, useEffect, useState } from 'react';

import { IRegistry } from '@hyperlane-xyz/registry';

Expand All @@ -15,20 +15,25 @@ export interface ChainLogoProps {
Icon?: SvgIcon; // Override the default set used above. Necessary for PI chain logos.
}

function _ChainLogo({ chainName, registry, size = 32, background = false, Icon }: ChainLogoProps) {
export function ChainLogo({
chainName,
registry,
size = 32,
background = false,
Icon,
}: ChainLogoProps) {
const title = chainName || 'Unknown';
const bgColorSeed = chainName.charCodeAt(0);
console.log('bgColorSeed', bgColorSeed);
const bgColorSeed = title.charCodeAt(0);
const iconSize = Math.floor(size / 1.9);

const [svgLogo, setSvgLogo] = useState('');
useEffect(() => {
if (!chainName || Icon) return;
if (!chainName || svgLogo || Icon) return;
registry
.getChainLogoUri(chainName)
.then((uri) => uri && setSvgLogo(uri))
.catch((err) => console.error(err));
}, []);
}, [chainName, registry, svgLogo, Icon]);

if (!svgLogo) {
return (
Expand Down Expand Up @@ -60,5 +65,3 @@ function _ChainLogo({ chainName, registry, size = 32, background = false, Icon }
);
}
}

export const ChainLogo = memo(_ChainLogo);

0 comments on commit 8c47ba8

Please sign in to comment.