1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-05 23:44:56 +01:00
metamask-extension/ui/components/app/modals/convert-token-to-nft-modal/convert-token-to-nft-modal.js
Nidhi Kumari 5bc0ba7f3a
Move "Import NFTs" to Modal (#19806)
* moved import nft to modal

* fixed modal state

* updated port-nft-popup

* updated onChange for import nft modal

* updated tests

* updated tests

* updated tests

* added story and updated spec file

* updated spec file

* updated spec file

* updated spec file for import-nft

* added focus to form field

* added autofocus to tokenId
2023-07-14 21:48:41 +05:30

69 lines
2.2 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { useHistory } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import Modal from '../../modal';
import Typography from '../../../ui/typography';
import { TypographyVariant } from '../../../../helpers/constants/design-system';
import withModalProps from '../../../../helpers/higher-order-components/with-modal-props';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { ASSET_ROUTE } from '../../../../helpers/constants/routes';
import { getNfts } from '../../../../ducks/metamask/metamask';
import { ignoreTokens, showImportNftsModal } from '../../../../store/actions';
import { isEqualCaseInsensitive } from '../../../../../shared/modules/string-utils';
const ConvertTokenToNFTModal = ({ hideModal, tokenAddress }) => {
const history = useHistory();
const t = useI18nContext();
const dispatch = useDispatch();
const allNfts = useSelector(getNfts);
const tokenAddedAsNFT = allNfts.find(({ address }) =>
isEqualCaseInsensitive(address, tokenAddress),
);
return (
<Modal
onSubmit={async () => {
if (tokenAddedAsNFT) {
await dispatch(
ignoreTokens({
tokensToIgnore: tokenAddress,
dontShowLoadingIndicator: true,
}),
);
const { tokenId } = tokenAddedAsNFT;
history.push({
pathname: `${ASSET_ROUTE}/${tokenAddress}/${tokenId}`,
});
} else {
dispatch(showImportNftsModal());
}
hideModal();
}}
submitText={t('yes')}
onCancel={() => hideModal()}
cancelText={t('cancel')}
>
<div className="convert-token-to-nft-modal">
<Typography
variant={TypographyVariant.H6}
boxProps={{
marginTop: 2,
}}
>
{tokenAddedAsNFT
? t('convertTokenToNFTExistDescription')
: t('convertTokenToNFTDescription')}
</Typography>
</div>
</Modal>
);
};
ConvertTokenToNFTModal.propTypes = {
hideModal: PropTypes.func.isRequired,
tokenAddress: PropTypes.string,
};
export default withModalProps(ConvertTokenToNFTModal);