Skip to content

Commit

Permalink
Merge pull request #60 from valory-xyz/mohan/add-arbitrum-links
Browse files Browse the repository at this point in the history
feat: add Arbitrum links to <AddressLink /> component
  • Loading branch information
mohandast52 authored Jan 30, 2024
2 parents ca628ce + 32bdf46 commit 647feeb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@

## 0.4.22
- Add "Solana" support for <AddressLink /> component

## 0.4.23
- Add "Arbitrum" and "Arbitrum Sepolia" support for <AddressLink /> component
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The following table shows which versions of `autonolas-frontend-library` are cur

| Version | Supported |
| --------- | ------------------ |
| `0.4.22` | :white_check_mark: |
| `0.4.23` | :white_check_mark: |

## Reporting a Vulnerability

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autonolas/frontend-library",
"version": "0.4.22",
"version": "0.4.23",
"description": "Codebase to common style, components, settings, etc.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
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
11 changes: 11 additions & 0 deletions src/functions/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const getSymbolName = (chainId: number) => {
case 100:
case 10200:
return 'xDAI';
case 42161:
case 421614:
return 'ARB';
default:
return 'ETH';
}
Expand Down Expand Up @@ -76,6 +79,10 @@ export const getNetworkName = (networkId: number) => {
return 'Gnosis Chain';
case 10200:
return 'Gnosis Chain Testnet';
case 42161:
return 'Arbitrum';
case 421614:
return 'Arbitrum Sepolia';
default:
return 'Unknown Network';
}
Expand Down Expand Up @@ -103,6 +110,10 @@ export const getExplorerURL = (chainId = 1) => {
return `https://gnosisscan.io`;
case 10200:
return `https://gnosis.blockscout.com`;
case 42161:
return `https://arbiscan.io`;
case 421614:
return `https://sepolia.arbiscan.io`;
default:
return `https://etherscan.io`;
}
Expand Down

0 comments on commit 647feeb

Please sign in to comment.