import { chakra, Spinner, Box } from '@chakra-ui/react';
import React from 'react';
import type { UseWaitForTransactionReceiptReturnType } from 'wagmi';
import { useWaitForTransactionReceipt } from 'wagmi';
import type { FormSubmitResultWalletClient } from '../types';
import { route } from 'nextjs-routes';
import { Alert } from 'toolkit/chakra/alert';
import { Link } from 'toolkit/chakra/link';
interface Props {
data: FormSubmitResultWalletClient['data'];
onSettle: () => void;
}
const ContractMethodResultWalletClient = ({ data, onSettle }: Props) => {
const txHash = data && 'hash' in data ? data.hash as `0x${ string }` : undefined;
const txInfo = useWaitForTransactionReceipt({
hash: txHash,
});
return ;
};
export interface PropsDumb {
data: FormSubmitResultWalletClient['data'];
onSettle: () => void;
txInfo: UseWaitForTransactionReceiptReturnType;
}
export const ContractMethodResultWalletClientDumb = ({ data, onSettle, txInfo }: PropsDumb) => {
const txHash = data && 'hash' in data ? data.hash : undefined;
React.useEffect(() => {
if (txInfo.status !== 'pending') {
onSettle();
}
}, [ onSettle, txInfo.status ]);
if (!data) {
return null;
}
const isErrorResult = 'message' in data;
const txLink = txHash ? (
View transaction details
) : null;
const content = (() => {
if (isErrorResult) {
return (
{ data.message }
);
}
switch (txInfo.status) {
case 'success': {
return (
<>
Transaction has been confirmed.
{ txLink }
>
);
}
case 'pending': {
return (
<>
{ 'Waiting for transaction\'s confirmation. ' }
{ txLink }
>
);
}
case 'error': {
return (
Error: { txInfo.error ? txInfo.error.message : 'Something went wrong' } { txLink }
);
}
}
})();
return (
{ content }
);
};
export default React.memo(ContractMethodResultWalletClient);