Commit 2c43d825 authored by tom's avatar tom

success case

parent 5eca4db9
import { Button, chakra } from '@chakra-ui/react'; import { Button, chakra } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import type { SubmitHandler } from 'react-hook-form'; import type { SubmitHandler } from 'react-hook-form';
import { useForm, FormProvider } from 'react-hook-form'; import { useForm, FormProvider } from 'react-hook-form';
...@@ -9,6 +10,7 @@ import type { SmartContractVerificationMethod, SmartContractVerificationConfig } ...@@ -9,6 +10,7 @@ import type { SmartContractVerificationMethod, SmartContractVerificationConfig }
import useApiFetch from 'lib/api/useApiFetch'; import useApiFetch from 'lib/api/useApiFetch';
import useToast from 'lib/hooks/useToast'; import useToast from 'lib/hooks/useToast';
import link from 'lib/link/link';
import useSocketChannel from 'lib/socket/useSocketChannel'; import useSocketChannel from 'lib/socket/useSocketChannel';
import useSocketMessage from 'lib/socket/useSocketMessage'; import useSocketMessage from 'lib/socket/useSocketMessage';
...@@ -48,6 +50,7 @@ const ContractVerificationForm = ({ method: methodFromQuery, config, hash }: Pro ...@@ -48,6 +50,7 @@ const ContractVerificationForm = ({ method: methodFromQuery, config, hash }: Pro
const apiFetch = useApiFetch(); const apiFetch = useApiFetch();
const toast = useToast(); const toast = useToast();
const router = useRouter();
const onFormSubmit: SubmitHandler<FormFields> = React.useCallback(async(data) => { const onFormSubmit: SubmitHandler<FormFields> = React.useCallback(async(data) => {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
...@@ -79,10 +82,22 @@ const ContractVerificationForm = ({ method: methodFromQuery, config, hash }: Pro ...@@ -79,10 +82,22 @@ const ContractVerificationForm = ({ method: methodFromQuery, config, hash }: Pro
if (payload.status === 'error') { if (payload.status === 'error') {
const errors = formatSocketErrors(payload.errors); const errors = formatSocketErrors(payload.errors);
errors.forEach(([ field, error ]) => setError(field, error)); errors.forEach(([ field, error ]) => setError(field, error));
submitPromiseResolver.current?.(null);
return;
} }
submitPromiseResolver.current?.(null); toast({
}, [ setError ]); position: 'top-right',
title: 'Success',
description: 'Contract is successfully verified.',
status: 'success',
variant: 'subtle',
isClosable: true,
onCloseComplete: () => {
router.push(link('address_index', { id: hash }, { tab: 'contract' }), undefined, { shallow: true });
},
});
}, [ hash, router, setError, toast ]);
const handleSocketError = React.useCallback(() => { const handleSocketError = React.useCallback(() => {
submitPromiseResolver.current?.(null); submitPromiseResolver.current?.(null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment