Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to abi-playground from ERC-1167 Minimal Proxy contracts #1540

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1540.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Detect ERC-1167 Minimal Proxy contracts
7 changes: 6 additions & 1 deletion src/app/components/Account/RuntimeAccountDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { FiatMoneyAmount } from '../Balance/FiatMoneyAmount'
import { getFiatCurrencyForScope, showFiatValues } from '../../../config'
import { CardEmptyState } from '../CardEmptyState'
import { extractMinimalProxyERC1167 } from '../ContractVerificationIcon/extractMinimalProxyERC1167'
import { AbiPlaygroundLink } from '../ContractVerificationIcon/AbiPlaygroundLink'
import Box from '@mui/material/Box'

type RuntimeAccountDetailsViewProps = {
isLoading?: boolean
Expand Down Expand Up @@ -108,7 +110,10 @@ export const RuntimeAccountDetailsView: FC<RuntimeAccountDetailsViewProps> = ({
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
<Box>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
<AbiPlaygroundLink scope={account} address_eth={account.address_eth!} />
</Box>
</dd>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { FC } from 'react'
import { Trans, useTranslation } from 'react-i18next'
import Link from '@mui/material/Link'
import { Layer } from '../../../oasis-nexus/api'
import { SearchScope } from '../../../types/searchScope'
import { Network } from '../../../types/network'
import * as externalLinks from '../../utils/externalLinks'

export const AbiPlaygroundLink: FC<{
address_eth: string
scope: SearchScope
}> = ({ address_eth, scope }) => {
const { t } = useTranslation()

const scopeToPlaygroundURL: Record<Network, Partial<Record<Layer, string>>> = {
[Network.mainnet]: {
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42262&contractAddress=${address_eth}`,
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23294&contractAddress=${address_eth}`,
},
[Network.testnet]: {
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42261&contractAddress=${address_eth}`,
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23295&contractAddress=${address_eth}`,
},
}
const abiPlaygroundLinkProps = {
href: scopeToPlaygroundURL[scope.network]?.[scope.layer],
rel: 'noopener noreferrer',
target: '_blank',
sx: { fontWeight: 400, color: 'inherit', textDecoration: 'underline' },
}

if (!abiPlaygroundLinkProps.href) return null
return (
<span>
{' | '}
<Trans
t={t}
i18nKey={'contract.verification.openInAbiPlayground'}
components={{
AbiPlaygroundLink: <Link {...abiPlaygroundLinkProps} />,
}}
/>
</span>
)
}
33 changes: 2 additions & 31 deletions src/app/components/ContractVerificationIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { styled } from '@mui/material/styles'
import { COLORS } from '../../../styles/theme/colors'
import Link from '@mui/material/Link'
import Typography from '@mui/material/Typography'
import { Layer } from '../../../oasis-nexus/api'
import { SearchScope } from '../../../types/searchScope'
import { Network } from '../../../types/network'
import * as externalLinks from '../../utils/externalLinks'
import { AbiPlaygroundLink } from './AbiPlaygroundLink'

type VerificationStatus = 'verified' | 'unverified'

Expand Down Expand Up @@ -77,23 +76,6 @@ export const VerificationIcon: FC<{
const Component = noLink ? Box : Link
const componentProps = noLink ? {} : sourcifyLinkProps

const scopeToPlaygroundURL: Record<Network, Partial<Record<Layer, string>>> = {
[Network.mainnet]: {
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42262&contractAddress=${address_eth}`,
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23294&contractAddress=${address_eth}`,
},
[Network.testnet]: {
[Layer.emerald]: `${externalLinks.dapps.abiPlayground}?network=42261&contractAddress=${address_eth}`,
[Layer.sapphire]: `${externalLinks.dapps.abiPlayground}?network=23295&contractAddress=${address_eth}`,
},
}
const abiPlaygroundLinkProps = {
href: scopeToPlaygroundURL[scope.network]?.[scope.layer],
rel: 'noopener noreferrer',
target: '_blank',
sx: { fontWeight: 400, color: 'inherit', textDecoration: 'underline' },
}

return (
<>
<StyledPill component={Component} verified={verified} address_eth={address_eth} {...componentProps}>
Expand All @@ -112,18 +94,7 @@ export const VerificationIcon: FC<{
SourcifyLink: <Link {...sourcifyLinkProps} />,
}}
/>
{abiPlaygroundLinkProps.href && (
<span>
{' | '}
<Trans
t={t}
i18nKey={'contract.verification.openInAbiPlayground'}
components={{
AbiPlaygroundLink: <Link {...abiPlaygroundLinkProps} />,
}}
/>
</span>
)}
<AbiPlaygroundLink address_eth={address_eth} scope={scope} />
</Typography>
) : (
<Typography component="span" sx={{ fontSize: '12px', color: COLORS.brandExtraDark }}>
Expand Down
7 changes: 6 additions & 1 deletion src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { RoundedBalance } from 'app/components/RoundedBalance'
import { HighlightedText } from '../../components/HighlightedText'
import { RuntimeBalanceDisplay } from '../../components/Balance/RuntimeBalanceDisplay'
import { extractMinimalProxyERC1167 } from '../../components/ContractVerificationIcon/extractMinimalProxyERC1167'
import { AbiPlaygroundLink } from '../../components/ContractVerificationIcon/AbiPlaygroundLink'
import Box from '@mui/material/Box'

export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchTerm: string }> = ({
scope,
Expand Down Expand Up @@ -71,7 +73,10 @@ export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchT
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
<Box>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
<AbiPlaygroundLink scope={account} address_eth={account.address_eth!} />
</Box>
</dd>
</>
)}
Expand Down
Loading