mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* display methods accordion * add method_id to methods * query read method via public client * query read methods without inputs at accordion section open * add custom abi tabs * add proxy tabs * custom wagmi config if wc is not configured * remove ContractAbiItemConstant component * display tuple properties in method outputs * display read result * clean up * support nested arrays in the read result * re-write test for contract methods * change result view for address output * refactoring * fix tests * remove web3 provider fallback * fix tab loading * refactoring * add implementation contract selector * add "copy to clipboard" for address, remove top-level square brackets * add preview mode to contract method result * tests for read result * fix tests * change styles for result preview * review fix
126 lines
4.3 KiB
TypeScript
126 lines
4.3 KiB
TypeScript
import { Modal, ModalBody, ModalCloseButton, ModalContent, ModalHeader, ModalOverlay, Link } from '@chakra-ui/react';
|
|
import React from 'react';
|
|
|
|
import type { AddressVerificationFormFirstStepFields, AddressCheckStatusSuccess } from './types';
|
|
import type { VerifiedAddress } from 'types/api/account';
|
|
|
|
import config from 'configs/app';
|
|
import * as mixpanel from 'lib/mixpanel/index';
|
|
import IconSvg from 'ui/shared/IconSvg';
|
|
import Web3ModalProvider from 'ui/shared/Web3ModalProvider';
|
|
|
|
import AddressVerificationStepAddress from './steps/AddressVerificationStepAddress';
|
|
import AddressVerificationStepSignature from './steps/AddressVerificationStepSignature';
|
|
import AddressVerificationStepSuccess from './steps/AddressVerificationStepSuccess';
|
|
|
|
type StateData = AddressVerificationFormFirstStepFields & AddressCheckStatusSuccess & { isToken?: boolean };
|
|
|
|
interface Props {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
onSubmit: (address: VerifiedAddress) => void;
|
|
onAddTokenInfoClick: (address: string) => void;
|
|
onShowListClick: () => void;
|
|
defaultAddress?: string;
|
|
pageType: string;
|
|
}
|
|
|
|
const AddressVerificationModal = ({ defaultAddress, isOpen, onClose, onSubmit, onAddTokenInfoClick, onShowListClick, pageType }: Props) => {
|
|
const [ stepIndex, setStepIndex ] = React.useState(0);
|
|
const [ data, setData ] = React.useState<StateData>({ address: '', signingMessage: '' });
|
|
|
|
React.useEffect(() => {
|
|
isOpen && mixpanel.logEvent(
|
|
mixpanel.EventTypes.VERIFY_ADDRESS,
|
|
{ Action: 'Form opened', 'Page type': pageType },
|
|
);
|
|
}, [ isOpen, pageType ]);
|
|
|
|
const handleGoToSecondStep = React.useCallback((firstStepResult: typeof data) => {
|
|
setData(firstStepResult);
|
|
setStepIndex((prev) => prev + 1);
|
|
mixpanel.logEvent(
|
|
mixpanel.EventTypes.VERIFY_ADDRESS,
|
|
{ Action: 'Address entered', 'Page type': pageType },
|
|
);
|
|
}, [ pageType ]);
|
|
|
|
const handleGoToThirdStep = React.useCallback((address: VerifiedAddress, signMethod: 'wallet' | 'manual') => {
|
|
onSubmit(address);
|
|
setStepIndex((prev) => prev + 1);
|
|
setData((prev) => ({ ...prev, isToken: Boolean(address.metadata.tokenName) }));
|
|
mixpanel.logEvent(
|
|
mixpanel.EventTypes.VERIFY_ADDRESS,
|
|
{ Action: 'Sign ownership', 'Page type': pageType, 'Sign method': signMethod },
|
|
);
|
|
}, [ onSubmit, pageType ]);
|
|
|
|
const handleGoToPrevStep = React.useCallback(() => {
|
|
setStepIndex((prev) => prev - 1);
|
|
}, []);
|
|
|
|
const handleClose = React.useCallback(() => {
|
|
onClose();
|
|
setStepIndex(0);
|
|
setData({ address: '', signingMessage: '' });
|
|
}, [ onClose ]);
|
|
|
|
const handleAddTokenInfoClick = React.useCallback(() => {
|
|
onAddTokenInfoClick(data.address);
|
|
handleClose();
|
|
}, [ handleClose, data.address, onAddTokenInfoClick ]);
|
|
|
|
const steps = [
|
|
{
|
|
title: 'Verify new address ownership',
|
|
content: <AddressVerificationStepAddress onContinue={ handleGoToSecondStep } defaultAddress={ defaultAddress }/>,
|
|
},
|
|
{
|
|
title: 'Copy and sign message',
|
|
content: (
|
|
<AddressVerificationStepSignature
|
|
{ ...data }
|
|
onContinue={ handleGoToThirdStep }
|
|
noWeb3Provider={ !config.features.blockchainInteraction.isEnabled }
|
|
/>
|
|
),
|
|
},
|
|
{
|
|
title: 'Congrats! Address is verified.',
|
|
content: (
|
|
<AddressVerificationStepSuccess
|
|
onShowListClick={ onShowListClick }
|
|
onAddTokenInfoClick={ handleAddTokenInfoClick }
|
|
isToken={ data.isToken }
|
|
address={ data.address }
|
|
/>
|
|
),
|
|
},
|
|
];
|
|
const step = steps[stepIndex];
|
|
|
|
return (
|
|
<Modal isOpen={ isOpen } onClose={ handleClose } size={{ base: 'full', lg: 'md' }}>
|
|
<ModalOverlay/>
|
|
<ModalContent>
|
|
<ModalHeader fontWeight="500" textStyle="h3" mb={ 6 }>
|
|
{ stepIndex !== 0 && (
|
|
<Link mr={ 3 } onClick={ handleGoToPrevStep }>
|
|
<IconSvg name="arrows/east" boxSize={ 6 } transform="rotate(180deg)" verticalAlign="middle" color="gray.400"/>
|
|
</Link>
|
|
) }
|
|
<span>{ step.title }</span>
|
|
</ModalHeader>
|
|
<ModalCloseButton/>
|
|
<ModalBody mb={ 0 }>
|
|
<Web3ModalProvider>
|
|
{ step.content }
|
|
</Web3ModalProvider>
|
|
</ModalBody>
|
|
</ModalContent>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default React.memo(AddressVerificationModal);
|