1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/pages/swaps/create-new-swap/create-new-swap.js
Elliot Winkler 1304ec7af5
Convert shared/constants/metametrics to TS (#18353)
We want to convert NetworkController to TypeScript in order to be able
to compare differences in the controller between in this repo and the
core repo. To do this, however, we need to convert the dependencies of
the controller to TypeScript.

As a part of this effort, this commit converts
`shared/constants/metametrics` to TypeScript. Note that simple objects
have been largely replaced with enums. There are some cases where I even
split up some of these objects into multiple enums.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2023-04-03 09:31:04 -06:00

48 lines
1.6 KiB
JavaScript

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';
import { MetaMetricsEventCategory } from '../../../../shared/constants/metametrics';
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',
category: MetaMetricsEventCategory.Swaps,
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,
};