2022-04-20 19:37:44 +00:00
|
|
|
import React from 'react';
|
2022-06-07 18:24:43 +00:00
|
|
|
import { Callout, Loader } from '@vegaprotocol/ui-toolkit';
|
2022-04-20 19:37:44 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-06-01 00:30:02 +00:00
|
|
|
import { Link } from '@vegaprotocol/ui-toolkit';
|
2022-06-21 23:20:53 +00:00
|
|
|
import { useEnvironment } from '@vegaprotocol/environment';
|
2022-04-20 19:37:44 +00:00
|
|
|
|
|
|
|
export const TransactionPending = ({
|
|
|
|
hash,
|
|
|
|
heading,
|
|
|
|
footer,
|
|
|
|
body,
|
|
|
|
confirmations,
|
|
|
|
requiredConfirmations,
|
|
|
|
}: {
|
|
|
|
hash: string;
|
|
|
|
confirmations: number | null;
|
|
|
|
requiredConfirmations: number | null;
|
|
|
|
heading?: React.ReactElement | string;
|
|
|
|
footer?: React.ReactElement | string;
|
|
|
|
body?: React.ReactElement | string;
|
|
|
|
}) => {
|
2022-06-01 00:30:02 +00:00
|
|
|
const { ETHERSCAN_URL } = useEnvironment();
|
2022-04-20 19:37:44 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const remainingConfirmations = React.useMemo(() => {
|
|
|
|
if (requiredConfirmations) {
|
|
|
|
return Math.max(0, requiredConfirmations - (confirmations || 0));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}, [confirmations, requiredConfirmations]);
|
|
|
|
const title = React.useMemo(() => {
|
|
|
|
const defaultTitle = heading || t('Transaction in progress');
|
|
|
|
if (remainingConfirmations > 0) {
|
|
|
|
return `${defaultTitle}. ${t('blockCountdown', {
|
|
|
|
amount: remainingConfirmations,
|
|
|
|
})}`;
|
|
|
|
}
|
|
|
|
return defaultTitle;
|
|
|
|
}, [heading, remainingConfirmations, t]);
|
|
|
|
return (
|
2022-06-07 18:24:43 +00:00
|
|
|
<Callout icon={<Loader size="small" />} title={title}>
|
2022-06-28 13:41:43 +00:00
|
|
|
{body && <p data-testid="transaction-pending-body">{body}</p>}
|
|
|
|
<p>
|
2022-06-01 00:30:02 +00:00
|
|
|
<Link
|
|
|
|
title={t('View transaction on Etherscan')}
|
2022-06-07 18:24:43 +00:00
|
|
|
target="_blank"
|
2022-06-01 00:30:02 +00:00
|
|
|
href={`${ETHERSCAN_URL}/tx/${hash}`}
|
|
|
|
>
|
|
|
|
{hash}
|
|
|
|
</Link>
|
2022-04-20 19:37:44 +00:00
|
|
|
</p>
|
|
|
|
{footer && <p data-testid="transaction-pending-footer">{footer}</p>}
|
|
|
|
</Callout>
|
|
|
|
);
|
|
|
|
};
|