Skip to content

Commit

Permalink
tiny bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Jan 30, 2024
1 parent 25ff9e5 commit 32bdf46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/product/AddressLink/AddressLink.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const columns: ColumnsType<DataType> = [
suffixCount={6}
canCopy
textMinWidth={150}
// chainId={421614}
// supportedChains={[{ id: 100 }]}
/>
),
Expand Down
14 changes: 12 additions & 2 deletions src/components/product/AddressLink/AddressLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ type GetRedirectLinkArgs = {
isIpfsLink: boolean;
supportedChains?: Chain[];
chainName?: SolanaChainNames;
chainId?: number;
};

const getRedirectLink = ({
text,
isIpfsLink,
supportedChains,
chainName,
chainId,
}: GetRedirectLinkArgs) => {
if (isIpfsLink) {
const hash = text.substring(2);
Expand All @@ -67,9 +69,13 @@ const getRedirectLink = ({
: `https://solscan.io/account/${text}`;
}

const getCurrentChainId = () => {
if (chainId) return chainId;
if (supportedChains) return getChainId(supportedChains);
return 1;
};
const explorerUrl = getExplorerURL(getCurrentChainId());
const isTransaction = /^0x([A-Fa-f0-9]{64})$/.test(text);
const currentChainId = supportedChains ? getChainId(supportedChains) : 1;
const explorerUrl = getExplorerURL(currentChainId);

return isTransaction
? `${explorerUrl}/tx/${text}`
Expand Down Expand Up @@ -109,6 +115,8 @@ type AddressLinkType = {
onClick?: (text: string) => void;
/** chain name */
chainName?: SolanaChainNames;
/** chain ID */
chainId?: number;
};

export const AddressLink = ({
Expand All @@ -122,6 +130,7 @@ export const AddressLink = ({
cannotClick,
supportedChains,
onClick,
chainId,
chainName,
}: AddressLinkType) => {
const trimmedText = getTrimmedText(text, suffixCount);
Expand All @@ -130,6 +139,7 @@ export const AddressLink = ({
isIpfsLink,
supportedChains,
chainName,
chainId,
});

return (
Expand Down

0 comments on commit 32bdf46

Please sign in to comment.