Skip to content

Commit

Permalink
fixup! Detect ERC-1167 Minimal Proxy contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Sep 12, 2024
1 parent 79a33b0 commit b8d6ae2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
9 changes: 3 additions & 6 deletions src/app/components/Account/RuntimeAccountDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import { calculateFiatValue } from '../Balance/hooks'
import { FiatMoneyAmount } from '../Balance/FiatMoneyAmount'
import { getFiatCurrencyForScope, showFiatValues } from '../../../config'
import { CardEmptyState } from '../CardEmptyState'
import {
extractMinimalProxyERC1167,
isMinimalProxyERC1167,
} from '../ContractVerificationIcon/isMinimalProxyERC1167'
import { extractMinimalProxyERC1167 } from '../ContractVerificationIcon/extractMinimalProxyERC1167'

type RuntimeAccountDetailsViewProps = {
isLoading?: boolean
Expand Down Expand Up @@ -107,11 +104,11 @@ export const RuntimeAccountDetailsView: FC<RuntimeAccountDetailsViewProps> = ({
</>
)}

{isMinimalProxyERC1167(account) && (
{extractMinimalProxyERC1167(account) && (
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)} />
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
</dd>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@ import { base64ToHex } from '../../utils/helpers'
import { toChecksumAddress } from '@ethereumjs/util'

/** https://eips.ethereum.org/EIPS/eip-1167 */
export function isMinimalProxyERC1167(account: RuntimeAccount) {
try {
extractMinimalProxyERC1167(account)
return true
} catch (e) {
return false
}
}

export function extractMinimalProxyERC1167(account: RuntimeAccount) {
if (!account?.evm_contract?.runtime_bytecode) throw new Error('Not ERC-1167')
if (!account?.evm_contract?.runtime_bytecode) return undefined

const hexBytecode = base64ToHex(account.evm_contract.runtime_bytecode)

Expand All @@ -28,5 +19,5 @@ export function extractMinimalProxyERC1167(account: RuntimeAccount) {
)?.[1]
if (proxyToAddress2) return toChecksumAddress(`0x00000000${proxyToAddress2}`)

throw new Error('Not ERC-1167')
return undefined
}
9 changes: 3 additions & 6 deletions src/app/pages/TokenDashboardPage/TokenDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import { tokenHoldersContainerId } from '../../pages/TokenDashboardPage/TokenHol
import { RoundedBalance } from 'app/components/RoundedBalance'
import { HighlightedText } from '../../components/HighlightedText'
import { RuntimeBalanceDisplay } from '../../components/Balance/RuntimeBalanceDisplay'
import {
extractMinimalProxyERC1167,
isMinimalProxyERC1167,
} from '../../components/ContractVerificationIcon/isMinimalProxyERC1167'
import { extractMinimalProxyERC1167 } from '../../components/ContractVerificationIcon/extractMinimalProxyERC1167'

export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchTerm: string }> = ({
scope,
Expand Down Expand Up @@ -70,11 +67,11 @@ export const TokenDetailsCard: FC<{ scope: SearchScope; address: string; searchT
/>
</dd>

{isMinimalProxyERC1167(account) && (
{extractMinimalProxyERC1167(account) && (
<>
<dt>{t('contract.verification.proxyERC1167')}</dt>
<dd>
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)} />
<AccountLink scope={account} address={extractMinimalProxyERC1167(account)!} />
</dd>
</>
)}
Expand Down

0 comments on commit b8d6ae2

Please sign in to comment.