Skip to content

Commit

Permalink
Merge pull request #21 from tom2drum/blockscout/v1
Browse files Browse the repository at this point in the history
feat: Integration with Blockscout explorer
  • Loading branch information
cong1223 authored Mar 18, 2024
2 parents 67b9273 + a9a9216 commit 0262ce6
Show file tree
Hide file tree
Showing 33 changed files with 1,095 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/common/config/allowlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export default {
BLOCKSEC_MATCHES: ['*://*.blocksec.com/*'],
OPENSEA_MATCHES: ['*://*.opensea.io/*'],
TRONSCAN_MATCHES: ['*://*.tronscan.org/*'],
SNOWTRACE_MATCHES: ['*://*.snowtrace.io/*']
SNOWTRACE_MATCHES: ['*://*.snowtrace.io/*'],
BLOCKSCOUT_MATCHES: ['*://*.blockscout.com/*']
}
26 changes: 26 additions & 0 deletions src/common/constants/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const TRONSCAN_PAGE_NAMES = [
'ADVANCED_FILTER'
] as const

export const BLOCKSCOUT_PAGE_NAMES = ['TX', 'ADDRESS'] as const

export const ETHERSCAN_PAGES: Record<
(typeof ETHERSCAN_PAGE_NAMES)[number],
{
Expand Down Expand Up @@ -115,3 +117,27 @@ export const TRONSCAN_PAGES: Record<
pattern: /\/tools\/advanced-filter(\?[\w%=&]*)?/
}
}

export type BlockscoutPageName = (typeof BLOCKSCOUT_PAGE_NAMES)[number]
export const BLOCKSCOUT_ROUTER_EVENTS = ['PATHNAME_CHANGED', 'TAB_CHANGED']
export type BlockscoutRouterEvent = (typeof BLOCKSCOUT_ROUTER_EVENTS)[number]

export const BLOCKSCOUT_PAGES: Record<
(typeof BLOCKSCOUT_PAGE_NAMES)[number],
{
pattern: RegExp
name: BlockscoutPageName
routerEvents: Array<BlockscoutRouterEvent>
}
> = {
TX: {
name: 'TX',
pattern: /^\/tx\/(0x[a-fA-F\d]{64})/i,
routerEvents: ['PATHNAME_CHANGED', 'TAB_CHANGED']
},
ADDRESS: {
name: 'ADDRESS',
pattern: /^\/address\/(0x[a-fA-F\d]{40})/i,
routerEvents: ['PATHNAME_CHANGED']
}
}
76 changes: 76 additions & 0 deletions src/common/constants/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
}
]
},
{
name: 'ETH (Blockscout)',
domains: ['eth.blockscout.com'],
chainID: 1,
chain: 'eth',
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/ethereum.png',
testNets: [
{
name: 'Sepolia (Blockscout)',
domains: ['eth-sepolia.blockscout.com'],
chainID: 11_155_111,
chain: 'sepolia.eth',
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/ethereum.png'
},
{
name: 'Goerli (Blockscout)',
domains: ['eth-goerli.blockscout.com'],
chainID: 5,
chain: 'gor.eth',
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/ethereum.png'
}
]
},
{
name: 'BSC',
chainID: 56,
Expand Down Expand Up @@ -93,6 +119,14 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
}
]
},
{
name: 'Polygon (Blockscout)',
chainID: 137,
chain: 'polygon',
domains: ['polygon.blockscout.com'],
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/polygon.png'
},
{
name: 'Fantom',
domains: ['ftmscan.com'],
Expand Down Expand Up @@ -191,6 +225,24 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
}
]
},
{
name: 'Optimism (Blockscout)',
chainID: 10,
chain: 'optimism',
domains: ['optimism.blockscout.com'],
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/optimism.png',
testNets: [
{
name: 'Optimism Goerli (Blockscout)',
chainID: 420,
chain: 'gor.optimism',
domains: ['optimism-goerli.blockscout.com'],
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/optimism.png'
}
]
},
{
name: 'Arbitrum Nova',
domains: ['nova.arbiscan.io'],
Expand Down Expand Up @@ -251,6 +303,14 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
siteName: 'ETHERSCAN',
logo: 'https://assets.blocksec.com/image/1695197286815-3.png'
},
{
name: 'Gnosis (Blockscout)',
chainID: 100,
chain: 'gnosis',
domains: ['gnosis.blockscout.com'],
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/gnosis.png'
},
{
name: 'Base',
chainID: 8453,
Expand All @@ -269,6 +329,14 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
}
]
},
{
name: 'Base (Blockscout)',
chainID: 8453,
chain: 'base',
domains: ['base.blockscout.com'],
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/base.png'
},
{
name: 'Polygon zkEVM',
chainID: 1101,
Expand All @@ -287,6 +355,14 @@ export const EXT_SUPPORT_WEB_LIST: ExtSupportWebsite[] = [
}
]
},
{
name: 'Polygon zkEVM (Blockscout)',
chainID: 1101,
chain: 'zkevm',
domains: ['zkevm.blockscout.com'],
siteName: 'BLOCKSCOUT',
logo: 'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/meta-suites-logos/polygon_zk-evm.png'
},
{
name: 'Linea',
chainID: 59_144,
Expand Down
4 changes: 3 additions & 1 deletion src/common/utils/biz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import $ from 'jquery'
import {
EXT_SUPPORT_WEB_LIST,
ETHERSCAN_PAGES,
BLOCKSCOUT_PAGES,
TRONSCAN_PAGES,
OPENSEA_PAGES,
PHALCON_SUPPORT_LIST
Expand All @@ -20,7 +21,8 @@ export const getPageName = (
const PAGES: Record<string, object> = {
OPENSEA_PAGES,
ETHERSCAN_PAGES,
TRONSCAN_PAGES
TRONSCAN_PAGES,
BLOCKSCOUT_PAGES
}
const siteName = EXT_SUPPORT_WEB_LIST.flatMap(item => [
item,
Expand Down
26 changes: 26 additions & 0 deletions src/content/blockscout/components/ExplorerLink/index.module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.container {
display: flex;
align-items: center;
}

.icon {
width: 20px;
height: 20px;
margin-right: 8px;
}

.name {
color: var(--chakra-colors-link);

&:hover {
text-decoration: underline;
color: var(--chakra-colors-link_hovered);
}
}

.arrow {
width: 16px;
height: 16px;
color: var(--chakra-colors-gray-400);
flex-shrink: 0;
}
27 changes: 27 additions & 0 deletions src/content/blockscout/components/ExplorerLink/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { type FC } from 'react'

import styles from './index.module.less'

interface Props {
iconUrl: string
name: string
href: string
}

const ExplorerLink: FC<Props> = props => {
return (
<a href={props.href} target="_blank" className={styles.container}>
<img
src={props.iconUrl}
alt={props.name + ' explorer'}
className={styles.icon}
/>
<span className={styles.name}>{props.name}</span>
<svg className={styles.arrow}>
<use href="/icons/sprite.svg#arrows/north-east"></use>
</svg>
</a>
)
}

export default ExplorerLink
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.container {
display: flex;
align-items: center;
}

.implementation {
display: flex;
align-items: center;
}

.arrow {
width: 20px;
height: 20px;
transform: rotate(180deg);
}

:global(.ant-tag) a.link {
color: var(--chakra-colors-link);

&:hover {
color: var(--chakra-colors-link_hovered);
}
}
62 changes: 62 additions & 0 deletions src/content/blockscout/components/MainAddressLabel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { type FC } from 'react'
import { Tooltip } from 'antd'
import cls from 'classnames'

import type { AddressLabel } from '@common/api/types'
import { TokenSymbol } from '@common/components'
import styles from './index.module.less'

import { Tag } from '../index'
import { address } from '../../utils'

const BUG_REPORT_URL =
'https://docs.google.com/forms/d/e/1FAIpQLSfWk-74XOBL6sU7SgFRIuDzbFwaUt0wf7C4KE8U_E5FUcboog/viewform?usp=pp_url&entry.1591633300=Bug/Label+Reports'

interface Props {
data: AddressLabel
}

const MainAddressLabel: FC<Props> = ({
data: { label, implementLabel, implementAddress, implementLogo }
}) => {
return (
<Tooltip
title={
<a href={BUG_REPORT_URL} target="_blank" className={cls(styles.link)}>
Report
</a>
}
>
<div>
<Tag icon={<TokenSymbol color="var(--chakra-colors-gray-500)" />}>
<div className={cls(styles.container)}>
{label.startsWith('0x') ? address.truncate(label) : label}
{implementLabel?.trim() && implementAddress && (
<div className={cls(styles.implementation)}>
<svg className={styles.arrow}>
<use href="/icons/sprite.svg#arrows/east-mini"></use>
</svg>
<TokenSymbol
logo={implementLogo}
color="var(--chakra-colors-gray-500)"
/>
<a
href={`/address/${implementAddress}`}
target="_blank"
className={cls(styles.link)}
>
{' '}
{implementLabel.startsWith('0x')
? address.truncate(implementAddress)
: implementLabel}
</a>
</div>
)}
</div>
</Tag>
</div>
</Tooltip>
)
}

export default MainAddressLabel
24 changes: 24 additions & 0 deletions src/content/blockscout/components/Tag/index.module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.container:global(.ant-tag):global(.ant-tag-borderless) {
display: flex;
align-items: center;
font-size: var(--chakra-fontSizes-sm);
line-height: var(--chakra-lineHeights-5);
padding: 2px 8px;
border-radius: var(--chakra-radii-sm);
border: none;
margin: 0;
}

:global(.chakra-ui-dark) {
.container:global(.ant-tag):global(.ant-tag-borderless) {
background-color: var(--chakra-colors-whiteAlpha-400);
color: var(--chakra-colors-gray-50);
}
}

:global(.chakra-ui-light) {
.container:global(.ant-tag):global(.ant-tag-borderless) {
background-color: var(--chakra-colors-blackAlpha-100);
color: var(--chakra-colors-chakra-body-text);
}
}
24 changes: 24 additions & 0 deletions src/content/blockscout/components/Tag/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { type FC } from 'react'
import { Tag as AntdTag } from 'antd'
import cls from 'classnames'
import styles from './index.module.less'

interface Props {
className?: string
children: React.ReactNode
icon?: React.ReactNode
}

const Tag: FC<Props> = ({ className, children, icon }) => {
return (
<AntdTag
icon={icon}
bordered={false}
className={cls(styles.container, className)}
>
{children}
</AntdTag>
)
}

export default Tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.btn {
display: flex;
align-items: center;
margin: 2px 0;

@media screen and (max-width: 1000px) {
margin: 0 0 0 28px;
}

&:global(.ant-btn-default):global(.ant-btn) {
font-weight: 600;
line-height: 20px;
border-width: 2px;
border-radius: 8px;
padding: 4px 6px;
color: var(--chakra-colors-link);
border-color: var(--chakra-colors-link);
background-color: transparent;

&:hover {
color: var(--chakra-colors-link_hovered) !important;
border-color: var(--chakra-colors-link_hovered) !important;
background-color: transparent !important;
}
}
}
Loading

0 comments on commit 0262ce6

Please sign in to comment.