Skip to content

Commit 912adae

Browse files
authored
UI/UX: Contract verification alert cases (#3234)
* UI/UX: Contract verification alert cases Resolves #3199 * fixes
1 parent 5fc23fd commit 912adae

13 files changed

+74
-56
lines changed
-419 Bytes
Loading
-411 Bytes
Loading
-429 Bytes
Loading
-410 Bytes
Loading
-426 Bytes
Loading
-287 Bytes
Loading

ui/address/contract/alerts/ContractDetailsAlertVerificationSource.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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);

ui/address/contract/alerts/ContractDetailsAlerts.pw.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test.describe.configure({ mode: 'serial' });
1313

1414
test('verified with changed byte code socket', async({ render, createSocket }) => {
1515
const props = {
16-
data: contractMock.verified,
16+
data: { ...contractMock.verified, is_partially_verified: true },
1717
isLoading: false,
1818
addressData: addressMock.contract,
1919
};

ui/address/contract/alerts/ContractDetailsAlerts.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import { Alert } from 'toolkit/chakra/alert';
1313
import { Link } from 'toolkit/chakra/link';
1414
import AddressEntity from 'ui/shared/entities/address/AddressEntity';
1515

16-
import ContractDetailsVerificationButton from '../ContractDetailsVerificationButton';
1716
import ContractDetailsAlertProxyPattern from './ContractDetailsAlertProxyPattern';
18-
import ContractDetailsAlertVerificationSource from './ContractDetailsAlertVerificationSource';
17+
import ContractDetailsAlertVerificationStatus from './ContractDetailsAlertVerificationStatus';
1918

2019
export interface Props {
2120
data: SmartContract | undefined;
@@ -47,27 +46,14 @@ const ContractDetailsAlerts = ({ data, isLoading, addressData, channel }: Props)
4746
</Link>
4847
</Box>
4948
) }
50-
{ data?.is_verified && (
51-
<Alert status="success" loading={ isLoading } descriptionProps={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 2, columnGap: 5 }}>
52-
<span>Contract Source Code Verified ({ data.is_partially_verified ? 'Partial' : 'Exact' } Match)</span>
53-
{
54-
data.is_partially_verified ? (
55-
<ContractDetailsVerificationButton
56-
isLoading={ isLoading }
57-
addressHash={ addressData.hash }
58-
/>
59-
) : null
60-
}
61-
</Alert>
62-
) }
49+
<ContractDetailsAlertVerificationStatus data={ data } isLoading={ isLoading } addressData={ addressData }/>
6350
{ addressData.proxy_type && (
6451
<ContractDetailsAlertProxyPattern
6552
type={ addressData.proxy_type }
6653
isLoading={ isLoading }
6754
conflictingImplementations={ data?.conflicting_implementations ?? undefined }
6855
/>
6956
) }
70-
<ContractDetailsAlertVerificationSource data={ data }/>
7157
{ (data?.is_changed_bytecode || isChangedBytecodeSocket) && (
7258
<Alert status="warning">
7359
Warning! Contract bytecode has been changed and does not match the verified one. Therefore, interaction with this smart contract may be risky.

0 commit comments

Comments
 (0)