2021-02-04 19:15:23 +01:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { I18nContext } from '../../../../contexts/i18n';
|
2021-05-19 16:51:47 +02:00
|
|
|
import { useNewMetricEvent } from '../../../../hooks/useMetricEvent';
|
2021-08-25 00:28:16 +02:00
|
|
|
import { getURLHostName } from '../../../../helpers/utils/util';
|
2020-10-06 20:28:38 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function ViewOnEtherScanLink({
|
2020-10-06 20:28:38 +02:00
|
|
|
txHash,
|
|
|
|
blockExplorerUrl,
|
|
|
|
isCustomBlockExplorerUrl,
|
|
|
|
}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useContext(I18nContext);
|
2021-05-19 16:51:47 +02:00
|
|
|
|
|
|
|
const blockExplorerLinkClickedEvent = useNewMetricEvent({
|
|
|
|
category: 'Swaps',
|
|
|
|
event: 'Clicked Block Explorer Link',
|
|
|
|
properties: {
|
|
|
|
link_type: 'Transaction Block Explorer',
|
|
|
|
action: 'Swap Transaction',
|
2021-08-25 00:28:16 +02:00
|
|
|
block_explorer_domain: getURLHostName(blockExplorerUrl),
|
2021-05-19 16:51:47 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-10-06 20:28:38 +02:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classnames('awaiting-swap__view-on-etherscan', {
|
|
|
|
'awaiting-swap__view-on-etherscan--visible': txHash,
|
|
|
|
'awaiting-swap__view-on-etherscan--invisible': !txHash,
|
|
|
|
})}
|
2021-05-19 16:51:47 +02:00
|
|
|
onClick={() => {
|
|
|
|
blockExplorerLinkClickedEvent();
|
|
|
|
global.platform.openTab({ url: blockExplorerUrl });
|
|
|
|
}}
|
2020-10-06 20:28:38 +02:00
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{isCustomBlockExplorerUrl
|
2021-09-24 19:14:07 +02:00
|
|
|
? t('viewOnCustomBlockExplorer', [
|
|
|
|
t('blockExplorerSwapAction'),
|
|
|
|
getURLHostName(blockExplorerUrl),
|
|
|
|
])
|
|
|
|
: t('viewOnEtherscan', [t('blockExplorerSwapAction')])}
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewOnEtherScanLink.propTypes = {
|
|
|
|
txHash: PropTypes.string,
|
|
|
|
blockExplorerUrl: PropTypes.string,
|
|
|
|
isCustomBlockExplorerUrl: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|