2022-01-19 19:42:41 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
2022-03-07 17:42:22 +01:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2022-01-19 19:42:41 +01:00
|
|
|
import Modal from '../../modal';
|
|
|
|
import Typography from '../../../ui/typography';
|
2023-02-02 21:15:26 +01:00
|
|
|
import { TypographyVariant } from '../../../../helpers/constants/design-system';
|
2022-01-19 19:42:41 +01:00
|
|
|
import withModalProps from '../../../../helpers/higher-order-components/with-modal-props';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
2022-03-07 17:42:22 +01:00
|
|
|
import {
|
|
|
|
ADD_COLLECTIBLE_ROUTE,
|
|
|
|
ASSET_ROUTE,
|
|
|
|
} from '../../../../helpers/constants/routes';
|
|
|
|
import { getCollectibles } from '../../../../ducks/metamask/metamask';
|
2022-07-18 16:43:30 +02:00
|
|
|
import { ignoreTokens } from '../../../../store/actions';
|
2022-03-10 03:31:04 +01:00
|
|
|
import { isEqualCaseInsensitive } from '../../../../../shared/modules/string-utils';
|
2022-01-19 19:42:41 +01:00
|
|
|
|
|
|
|
const ConvertTokenToNFTModal = ({ hideModal, tokenAddress }) => {
|
|
|
|
const history = useHistory();
|
|
|
|
const t = useI18nContext();
|
2022-03-07 17:42:22 +01:00
|
|
|
const dispatch = useDispatch();
|
2022-11-15 19:49:42 +01:00
|
|
|
const allNfts = useSelector(getCollectibles);
|
|
|
|
const tokenAddedAsNFT = allNfts.find(({ address }) =>
|
2022-03-07 17:42:22 +01:00
|
|
|
isEqualCaseInsensitive(address, tokenAddress),
|
|
|
|
);
|
|
|
|
|
2022-01-19 19:42:41 +01:00
|
|
|
return (
|
|
|
|
<Modal
|
2022-03-07 17:42:22 +01:00
|
|
|
onSubmit={async () => {
|
|
|
|
if (tokenAddedAsNFT) {
|
2022-07-18 16:43:30 +02:00
|
|
|
await dispatch(
|
|
|
|
ignoreTokens({
|
|
|
|
tokensToIgnore: tokenAddress,
|
|
|
|
dontShowLoadingIndicator: true,
|
|
|
|
}),
|
|
|
|
);
|
2022-03-07 17:42:22 +01:00
|
|
|
const { tokenId } = tokenAddedAsNFT;
|
|
|
|
history.push({
|
|
|
|
pathname: `${ASSET_ROUTE}/${tokenAddress}/${tokenId}`,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
history.push({
|
|
|
|
pathname: ADD_COLLECTIBLE_ROUTE,
|
|
|
|
state: { tokenAddress },
|
|
|
|
});
|
|
|
|
}
|
2022-01-19 19:42:41 +01:00
|
|
|
hideModal();
|
|
|
|
}}
|
|
|
|
submitText={t('yes')}
|
|
|
|
onCancel={() => hideModal()}
|
|
|
|
cancelText={t('cancel')}
|
|
|
|
>
|
|
|
|
<div className="convert-token-to-nft-modal">
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H6}
|
2022-01-19 19:42:41 +01:00
|
|
|
boxProps={{
|
|
|
|
marginTop: 2,
|
|
|
|
}}
|
|
|
|
>
|
2022-03-07 17:42:22 +01:00
|
|
|
{tokenAddedAsNFT
|
|
|
|
? t('convertTokenToNFTExistDescription')
|
|
|
|
: t('convertTokenToNFTDescription')}
|
2022-01-19 19:42:41 +01:00
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ConvertTokenToNFTModal.propTypes = {
|
|
|
|
hideModal: PropTypes.func.isRequired,
|
|
|
|
tokenAddress: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withModalProps(ConvertTokenToNFTModal);
|