Skip to content

Commit

Permalink
feat: Proxy logs now support several other EVM chains.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbe37e committed Apr 30, 2023
1 parent 1bc8413 commit 50903e0
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 49 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metadock",
"version": "2.4.0",
"version": "2.4.1",
"repository": {
"type": "git",
"url": "https://github.com/blocksecteam/metadock.git"
Expand Down
2 changes: 1 addition & 1 deletion src/common/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export interface ProxyContractLog {
id: number
block: number
ts: number
proxyAddress: string
currentImpl: string
tx: string
hub: string
}
11 changes: 0 additions & 11 deletions src/common/constants/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,3 @@ export const ETHERVM_SUPPORT_DIRECT_LIST: ToolsSupportWebsite[] = [
url: 'https://ethervm.io/decompile/binance'
}
]

export const PROXY_LOG_SUPPORT_LIST = [
{
chain: 'eth',
value: 'etherscan'
},
{
chain: 'bsc',
value: 'bscscan'
}
] as const
27 changes: 18 additions & 9 deletions src/content/etherscan/components/ModalProxyLog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { type FC, useEffect, useState } from 'react'
import cls from 'classnames'
import ReactDOM from 'react-dom'
import { Table } from 'antd'
import { Table, Empty } from 'antd'
import type { ColumnsType } from 'antd/es/table'

import { getImageUrl } from '@common/utils'
Expand All @@ -22,6 +22,7 @@ interface Props {

const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
const [loading, setLoading] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
const [dataList, setDataList] = useState<ProxyContractLog[]>([])

const columns: ColumnsType<ProxyContractLog> = [
Expand All @@ -43,19 +44,19 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
)
},
{
title: 'Implementation address',
dataIndex: 'proxyAddress',
key: 'proxyAddress',
render: proxyAddress => (
title: 'Implementation Address',
dataIndex: 'currentImpl',
key: 'currentImpl',
render: currentImpl => (
<div className={styles.cell}>
<a
href={`${window.location.origin}/address/${proxyAddress}`}
href={`${window.location.origin}/address/${currentImpl}`}
target="_blank"
rel="noreferrer"
>
{proxyAddress}
{currentImpl}
</a>
<CopyButton className={styles.copyButton} text={proxyAddress} />
<CopyButton className={styles.copyButton} text={currentImpl} />
</div>
)
},
Expand Down Expand Up @@ -99,6 +100,7 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {

const getProxyLog = async () => {
setLoading(true)
setErrorMessage('')
const res = await chromeEvent.emit<
typeof GET_PROXY_CONTRACT_LOG,
ProxyContractLog[]
Expand All @@ -109,6 +111,8 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
setLoading(false)
if (res?.success && res?.data) {
setDataList(res.data)
} else {
setErrorMessage(res?.message ?? '')
}
}

Expand Down Expand Up @@ -138,7 +142,7 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
<header className={styles.header}>
<div className="align-center">
<TokenSymbol />
Proxy Log
Proxy Upgrade Log
<span className={styles.address}>({address})</span>
</div>
<div className={styles.btn} onClick={onClose}>
Expand All @@ -147,11 +151,16 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
</header>
<div className={styles.body}>
<Table
locale={{
emptyText: () =>
errorMessage || <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
}}
loading={loading}
className={styles.table}
columns={columns}
dataSource={dataList}
pagination={false}
rowKey="id"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ProxyLogReference: FC<Props> = ({ chain, address }) => {
>
<span className="nav-link">
<TokenSymbol mr={4} />
<span className="d-none d-sm-inline-block">Proxy Log</span>
<span className="d-none d-sm-inline-block">Proxy Upgrade Log</span>
</span>
</li>
<ModalProxyLog
Expand Down
8 changes: 1 addition & 7 deletions src/content/etherscan/feat-scripts/proxy-contract-log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ import $ from 'jquery'

import { pickAddress } from '@common/utils'
import { ProxyLogReference } from '@src/content/etherscan/components'
import { PROXY_LOG_SUPPORT_LIST } from '@common/constants'

/** Show proxy log */
const genProxyContractLog = async (chain: string) => {
const supportNetwork = PROXY_LOG_SUPPORT_LIST.find(
item => item.chain === chain
)
if (!supportNetwork) return

const mainAddress = pickAddress(window.location.pathname)
if (!mainAddress) return

Expand All @@ -26,7 +20,7 @@ const genProxyContractLog = async (chain: string) => {
rootEl.css('display', 'contents')
navTabsEl.append(rootEl)
createRoot(rootEl[0]).render(
<ProxyLogReference chain={supportNetwork.value} address={mainAddress} />
<ProxyLogReference chain={chain} address={mainAddress} />
)
}

Expand Down
27 changes: 18 additions & 9 deletions src/content/scans/components/ModalProxyLog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { type FC, useEffect, useState } from 'react'
import cls from 'classnames'
import ReactDOM from 'react-dom'
import { Table } from 'antd'
import { Table, Empty } from 'antd'
import type { ColumnsType } from 'antd/es/table'

import { getImageUrl } from '@common/utils'
Expand All @@ -22,6 +22,7 @@ interface Props {

const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
const [loading, setLoading] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
const [dataList, setDataList] = useState<ProxyContractLog[]>([])

const columns: ColumnsType<ProxyContractLog> = [
Expand All @@ -43,19 +44,19 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
)
},
{
title: 'Implementation address',
dataIndex: 'proxyAddress',
key: 'proxyAddress',
render: proxyAddress => (
title: 'Implementation Address',
dataIndex: 'currentImpl',
key: 'currentImpl',
render: currentImpl => (
<div className={styles.cell}>
<a
href={`${window.location.origin}/address/${proxyAddress}`}
href={`${window.location.origin}/address/${currentImpl}`}
target="_blank"
rel="noreferrer"
>
{proxyAddress}
{currentImpl}
</a>
<CopyButton className={styles.copyButton} text={proxyAddress} />
<CopyButton className={styles.copyButton} text={currentImpl} />
</div>
)
},
Expand Down Expand Up @@ -99,6 +100,7 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {

const getProxyLog = async () => {
setLoading(true)
setErrorMessage('')
const res = await chromeEvent.emit<
typeof GET_PROXY_CONTRACT_LOG,
ProxyContractLog[]
Expand All @@ -109,6 +111,8 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
setLoading(false)
if (res?.success && res?.data) {
setDataList(res.data)
} else {
setErrorMessage(res?.message ?? '')
}
}

Expand Down Expand Up @@ -138,7 +142,7 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
<header className={styles.header}>
<div className="align-center">
<TokenSymbol />
Proxy Log
Proxy Upgrade Log
<span className={styles.address}>({address})</span>
</div>
<div className={styles.btn} onClick={onClose}>
Expand All @@ -147,11 +151,16 @@ const ModalProxyLog: FC<Props> = ({ visible, onClose, chain, address }) => {
</header>
<div className={styles.body}>
<Table
locale={{
emptyText: () =>
errorMessage || <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
}}
loading={loading}
className={styles.table}
columns={columns}
dataSource={dataList}
pagination={false}
rowKey="id"
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/content/scans/components/ProxyLogReference/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ProxyLogReference: FC<Props> = ({ chain, address }) => {
>
<span className="nav-link">
<TokenSymbol mr={4} />
<span className="d-none d-sm-inline-block">Proxy Log</span>
<span className="d-none d-sm-inline-block">Proxy Upgrade Log</span>
</span>
</li>
<ModalProxyLog
Expand Down
10 changes: 2 additions & 8 deletions src/content/scans/feat-scripts/proxy-contract-log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ import { createRoot } from 'react-dom/client'
import $ from 'jquery'

import { pickAddress } from '@common/utils'
import { ProxyLogReference } from '@src/content/etherscan/components'
import { PROXY_LOG_SUPPORT_LIST } from '@common/constants'
import { ProxyLogReference } from '@src/content/scans/components'

/** Show proxy log */
const genProxyContractLog = async (chain: string) => {
const supportNetwork = PROXY_LOG_SUPPORT_LIST.find(
item => item.chain === chain
)
if (!supportNetwork) return

const mainAddress = pickAddress(window.location.pathname)
if (!mainAddress) return

Expand All @@ -26,7 +20,7 @@ const genProxyContractLog = async (chain: string) => {
rootEl.css('display', 'contents')
navTabsEl.append(rootEl)
createRoot(rootEl[0]).render(
<ProxyLogReference chain={supportNetwork.value} address={mainAddress} />
<ProxyLogReference chain={chain} address={mainAddress} />
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const ConfigExploresDrawer: FC<Props> = ({ visible, onClose, onChange }) => {
{/*/>*/}
<Cell
border={false}
title="Show proxy log"
title="Show proxy upgrade log"
action={
<Switch
checked={options.proxyLog as boolean}
Expand Down

0 comments on commit 50903e0

Please sign in to comment.