Skip to content

Commit

Permalink
updated initial state of new imported nfts to expanded (#17285)
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiKJha authored Jan 19, 2023
1 parent 0fdff89 commit 90d2ca0
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions ui/pages/add-collectible/add-collectible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 ??
'',
Expand All @@ -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));
Expand All @@ -72,7 +96,7 @@ export default function AddCollectible() {
dispatch(setNewCollectibleAddedMessage('success'));

const tokenDetails = await getTokenStandardAndDetails(
address,
collectibleAddress,
null,
tokenId.toString(),
);
Expand All @@ -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,
Expand All @@ -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);
};

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 90d2ca0

Please sign in to comment.