mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
contract changed
This commit is contained in:
@@ -21,6 +21,7 @@ SocketMessage.AddressCoinBalance |
|
||||
SocketMessage.AddressTxs |
|
||||
SocketMessage.AddressTxsPending |
|
||||
SocketMessage.AddressTokenTransfer |
|
||||
SocketMessage.AddressChangedBytecode |
|
||||
SocketMessage.TokenTransfers |
|
||||
SocketMessage.TokenTotalSupply |
|
||||
SocketMessage.ContractVerification |
|
||||
@@ -49,6 +50,7 @@ export namespace SocketMessage {
|
||||
export type AddressTxs = SocketMessageParamsGeneric<'transaction', { transaction: Transaction }>;
|
||||
export type AddressTxsPending = SocketMessageParamsGeneric<'pending_transaction', { transaction: Transaction }>;
|
||||
export type AddressTokenTransfer = SocketMessageParamsGeneric<'token_transfer', { token_transfer: TokenTransfer }>;
|
||||
export type AddressChangedBytecode = SocketMessageParamsGeneric<'changed_bytecode', never>;
|
||||
export type TokenTransfers = SocketMessageParamsGeneric<'token_transfer', {token_transfer: number }>;
|
||||
export type TokenTotalSupply = SocketMessageParamsGeneric<'total_supply', {total_supply: number }>;
|
||||
export type ContractVerification = SocketMessageParamsGeneric<'verification_result', SmartContractVerificationResponse>;
|
||||
|
||||
@@ -2,8 +2,12 @@ import { Flex, Skeleton, Button, Grid, GridItem, Text, Alert, Link, chakra, Box
|
||||
import { route } from 'nextjs-routes';
|
||||
import React from 'react';
|
||||
|
||||
import type { SocketMessage } from 'lib/socket/types';
|
||||
|
||||
import useApiQuery from 'lib/api/useApiQuery';
|
||||
import dayjs from 'lib/date/dayjs';
|
||||
import useSocketChannel from 'lib/socket/useSocketChannel';
|
||||
import useSocketMessage from 'lib/socket/useSocketMessage';
|
||||
import Address from 'ui/shared/address/Address';
|
||||
import AddressIcon from 'ui/shared/address/AddressIcon';
|
||||
import AddressLink from 'ui/shared/address/AddressLink';
|
||||
@@ -26,14 +30,32 @@ const InfoItem = chakra(({ label, value, className }: { label: string; value: st
|
||||
));
|
||||
|
||||
const ContractCode = ({ addressHash }: Props) => {
|
||||
const [ isSocketOpen, setIsSocketOpen ] = React.useState(false);
|
||||
const [ isChangedBytecodeSocket, setIsChangedBytecodeSocket ] = React.useState<boolean>();
|
||||
|
||||
const { data, isLoading, isError } = useApiQuery('contract', {
|
||||
pathParams: { hash: addressHash },
|
||||
queryOptions: {
|
||||
enabled: Boolean(addressHash),
|
||||
enabled: Boolean(addressHash) && isSocketOpen,
|
||||
refetchOnMount: false,
|
||||
},
|
||||
});
|
||||
|
||||
const handleChangedBytecodeMessage: SocketMessage.AddressChangedBytecode['handler'] = React.useCallback(() => {
|
||||
setIsChangedBytecodeSocket(true);
|
||||
}, [ ]);
|
||||
|
||||
const channel = useSocketChannel({
|
||||
topic: `addresses:${ addressHash?.toLowerCase() }`,
|
||||
isDisabled: !addressHash,
|
||||
onJoin: () => setIsSocketOpen(true),
|
||||
});
|
||||
useSocketMessage({
|
||||
channel,
|
||||
event: 'changed_bytecode',
|
||||
handler: handleChangedBytecodeMessage,
|
||||
});
|
||||
|
||||
if (isError) {
|
||||
return <DataFetchAlert/>;
|
||||
}
|
||||
@@ -117,7 +139,7 @@ const ContractCode = ({ addressHash }: Props) => {
|
||||
{ data.sourcify_repo_url && <LinkExternal href={ data.sourcify_repo_url } fontSize="md">View contract in Sourcify repository</LinkExternal> }
|
||||
</Alert>
|
||||
) }
|
||||
{ data.is_changed_bytecode && (
|
||||
{ (data.is_changed_bytecode || isChangedBytecodeSocket) && (
|
||||
<Alert status="warning">
|
||||
Warning! Contract bytecode has been changed and does not match the verified one. Therefore, interaction with this smart contract may be risky.
|
||||
</Alert>
|
||||
|
||||
Reference in New Issue
Block a user