|
| 1 | +import { Box } from '@chakra-ui/react'; |
| 2 | +import React from 'react'; |
| 3 | + |
| 4 | +import type { Address } from 'types/api/address'; |
| 5 | +import type { SmartContract } from 'types/api/contract'; |
| 6 | + |
| 7 | +import { Alert } from 'toolkit/chakra/alert'; |
| 8 | +import { Link } from 'toolkit/chakra/link'; |
| 9 | + |
| 10 | +import ContractDetailsVerificationButton from '../ContractDetailsVerificationButton'; |
| 11 | + |
| 12 | +interface Props { |
| 13 | + data: SmartContract | undefined; |
| 14 | + isLoading: boolean; |
| 15 | + addressData: Address; |
| 16 | +} |
| 17 | + |
| 18 | +const ContractDetailsAlertVerificationStatus = ({ data, isLoading, addressData }: Props) => { |
| 19 | + if (!data || !data.is_verified) { |
| 20 | + return null; |
| 21 | + } |
| 22 | + |
| 23 | + const sourceElement = (() => { |
| 24 | + if (data?.is_verified_via_eth_bytecode_db) { |
| 25 | + return ( |
| 26 | + <> |
| 27 | + <span>This contract has been { data.is_partially_verified ? 'partially ' : '' }verified using </span> |
| 28 | + <Link |
| 29 | + href="https://docs.blockscout.com/devs/verification/ethereum-bytecode-database-microservice" |
| 30 | + external |
| 31 | + > |
| 32 | + Blockscout Bytecode Database |
| 33 | + </Link> |
| 34 | + </> |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + if (data?.is_verified_via_sourcify) { |
| 39 | + return ( |
| 40 | + <> |
| 41 | + <span>This contract has been { data.is_partially_verified ? 'partially ' : '' }verified via Sourcify. </span> |
| 42 | + { data.sourcify_repo_url && <Link href={ data.sourcify_repo_url } textStyle="md" external>View contract in Sourcify repository</Link> } |
| 43 | + </> |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + return null; |
| 48 | + })(); |
| 49 | + |
| 50 | + if (!data.is_partially_verified) { |
| 51 | + return ( |
| 52 | + <Alert status="success" loading={ isLoading } descriptionProps={{ whiteSpace: 'pre-wrap' }}> |
| 53 | + <span>Contract source code verified (exact match){ sourceElement ? '. ' : '' }</span> |
| 54 | + { sourceElement } |
| 55 | + </Alert> |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + return ( |
| 60 | + <Alert status="success" loading={ isLoading } descriptionProps={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 2, columnGap: 3 }}> |
| 61 | + <span>Contract source code verified ({ data.is_partially_verified ? 'partial' : 'exact' } match){ sourceElement ? '.' : '' }</span> |
| 62 | + <ContractDetailsVerificationButton |
| 63 | + isLoading={ isLoading } |
| 64 | + addressHash={ addressData.hash } |
| 65 | + /> |
| 66 | + { sourceElement && <Box w="100%">{ sourceElement }</Box> } |
| 67 | + </Alert> |
| 68 | + ); |
| 69 | +}; |
| 70 | + |
| 71 | +export default React.memo(ContractDetailsAlertVerificationStatus); |
0 commit comments