1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/ui/components/app/modals/convert-token-to-nft-modal/convert-token-to-nft-modal.js
Nidhi Kumari 33cc8d587a
NFT: Replaced all the instances of collectibles with NFTs (#17741)
* replaced all the instances of collectibles with nfts

* updated actions

* updated e2e seeder

* updated confirm Approve test

* updated test dapp change

* updated test dapp change

* nit fix

* nit fix

* updated casing and snapshots

* updated casinG

* added migrations

* updated ,igration

* updated 078.test

* updated tests for 078 migration

* updated migration

* updated 078 index.js
2023-02-17 00:53:29 +05:30

75 lines
2.3 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 {
ADD_NFT_ROUTE,
ASSET_ROUTE,
} from '../../../../helpers/constants/routes';
import { getNfts } from '../../../../ducks/metamask/metamask';
import { ignoreTokens } 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 {
history.push({
pathname: ADD_NFT_ROUTE,
state: { tokenAddress },
});
}
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);