Skip to content

Commit

Permalink
Merge pull request #1540 from oasisprotocol/lw/erc1167-playground
Browse files Browse the repository at this point in the history
Link to abi-playground from ERC-1167 Minimal Proxy contracts
  • Loading branch information
lukaw3d authored Sep 12, 2024
2 parents 3a9b147 + 07c18a6 commit 4bb69ac
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 33 deletions.
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
45 changes: 45 additions & 0 deletions src/app/components/ContractVerificationIcon/AbiPlaygroundLink.tsx
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

0 comments on commit 4bb69ac

Please sign in to comment.