From 90d2ca0727878bee2c06fc30701301aa1ac3e0eb Mon Sep 17 00:00:00 2001 From: Nidhi Kumari Date: Thu, 19 Jan 2023 23:01:13 +0530 Subject: [PATCH] updated initial state of new imported nfts to expanded (#17285) --- ui/pages/add-collectible/add-collectible.js | 44 ++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/ui/pages/add-collectible/add-collectible.js b/ui/pages/add-collectible/add-collectible.js index 33353f900be8..f579154e3558 100644 --- a/ui/pages/add-collectible/add-collectible.js +++ b/ui/pages/add-collectible/add-collectible.js @@ -19,10 +19,19 @@ import { getTokenStandardAndDetails, ignoreTokens, setNewCollectibleAddedMessage, + updateCollectibleDropDownState, } from '../../store/actions'; import FormField from '../../components/ui/form-field'; -import { getIsMainnet, getUseNftDetection } from '../../selectors'; -import { getCollectiblesDetectionNoticeDismissed } from '../../ducks/metamask/metamask'; +import { + getCurrentChainId, + getIsMainnet, + getSelectedAddress, + getUseNftDetection, +} from '../../selectors'; +import { + getCollectiblesDetectionNoticeDismissed, + getCollectiblesDropdownState, +} from '../../ducks/metamask/metamask'; import CollectiblesDetectionNotice from '../../components/app/collectibles-detection-notice'; import { MetaMetricsContext } from '../../contexts/metametrics'; import { AssetType } from '../../../shared/constants/transaction'; @@ -37,12 +46,15 @@ export default function AddCollectible() { const collectibleDetectionNoticeDismissed = useSelector( getCollectiblesDetectionNoticeDismissed, ); + const collectiblesDropdownState = useSelector(getCollectiblesDropdownState); + const selectedAddress = useSelector(getSelectedAddress); + const chainId = useSelector(getCurrentChainId); const addressEnteredOnImportTokensPage = history?.location?.state?.addressEnteredOnImportTokensPage; const contractAddressToConvertFromTokenToCollectible = history?.location?.state?.tokenAddress; - const [address, setAddress] = useState( + const [collectibleAddress, setCollectibleAddress] = useState( addressEnteredOnImportTokensPage ?? contractAddressToConvertFromTokenToCollectible ?? '', @@ -54,7 +66,19 @@ export default function AddCollectible() { const handleAddCollectible = async () => { try { - await dispatch(addNftVerifyOwnership(address, tokenId)); + await dispatch(addNftVerifyOwnership(collectibleAddress, tokenId)); + const newCollectibleDropdownState = { + ...collectiblesDropdownState, + [selectedAddress]: { + ...collectiblesDropdownState?.[selectedAddress], + [chainId]: { + ...collectiblesDropdownState?.[selectedAddress]?.[chainId], + [collectibleAddress]: true, + }, + }, + }; + + dispatch(updateCollectibleDropDownState(newCollectibleDropdownState)); } catch (error) { const { message } = error; dispatch(setNewCollectibleAddedMessage(message)); @@ -72,7 +96,7 @@ export default function AddCollectible() { dispatch(setNewCollectibleAddedMessage('success')); const tokenDetails = await getTokenStandardAndDetails( - address, + collectibleAddress, null, tokenId.toString(), ); @@ -81,7 +105,7 @@ export default function AddCollectible() { event: EVENT_NAMES.TOKEN_ADDED, category: 'Wallet', sensitiveProperties: { - token_contract_address: address, + token_contract_address: collectibleAddress, token_symbol: tokenDetails?.symbol, tokenId: tokenId.toString(), asset_type: AssetType.NFT, @@ -95,11 +119,13 @@ export default function AddCollectible() { const validateAndSetAddress = (val) => { setDisabled(!isValidHexAddress(val) || !tokenId); - setAddress(val); + setCollectibleAddress(val); }; const validateAndSetTokenId = (val) => { - setDisabled(!isValidHexAddress(address) || !val || isNaN(Number(val))); + setDisabled( + !isValidHexAddress(collectibleAddress) || !val || isNaN(Number(val)), + ); setTokenId(val); }; @@ -154,7 +180,7 @@ export default function AddCollectible() { dataTestId="address" titleText={t('address')} placeholder="0x..." - value={address} + value={collectibleAddress} onChange={(val) => { validateAndSetAddress(val); setCollectibleAddFailed(false);