2022-07-11 17:53:07 +02:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import isEqual from 'lodash/isEqual';
|
|
|
|
|
|
|
|
import Box from '../../../components/ui/box';
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2023-04-03 17:31:04 +02:00
|
|
|
import { MetaMetricsEventCategory } from '../../../../shared/constants/metametrics';
|
2022-07-11 17:53:07 +02:00
|
|
|
import {
|
|
|
|
navigateBackToBuildQuote,
|
|
|
|
setSwapsFromToken,
|
|
|
|
} from '../../../ducks/swaps/swaps';
|
|
|
|
import { DEFAULT_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
import { getSwapsDefaultToken } from '../../../selectors';
|
|
|
|
|
|
|
|
export default function CreateNewSwap({ sensitiveTrackingProperties }) {
|
|
|
|
const t = useContext(I18nContext);
|
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const history = useHistory();
|
|
|
|
const defaultSwapsToken = useSelector(getSwapsDefaultToken, isEqual);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box marginBottom={3} className="create-new-swap">
|
|
|
|
<button
|
|
|
|
onClick={async () => {
|
|
|
|
trackEvent({
|
|
|
|
event: 'Make Another Swap',
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Swaps,
|
2022-07-11 17:53:07 +02:00
|
|
|
sensitiveProperties: sensitiveTrackingProperties,
|
|
|
|
});
|
|
|
|
history.push(DEFAULT_ROUTE); // It cleans up Swaps state.
|
|
|
|
await dispatch(navigateBackToBuildQuote(history));
|
|
|
|
dispatch(setSwapsFromToken(defaultSwapsToken));
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('makeAnotherSwap')}
|
|
|
|
</button>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateNewSwap.propTypes = {
|
|
|
|
sensitiveTrackingProperties: PropTypes.object.isRequired,
|
|
|
|
};
|