diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 57d75d983..aab5b20e3 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1640,6 +1640,9 @@ "loading": { "message": "Loading..." }, + "loadingNFTs": { + "message": "Loading NFTs..." + }, "loadingTokens": { "message": "Loading Tokens..." }, diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 037359453..f63a883b6 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -134,16 +134,10 @@ export default class PreferencesController { /** * Setter for the `useCollectibleDetection` property * - * @param {boolean} val - Whether or not the user prefers to autodetect collectibles. + * @param {boolean} useCollectibleDetection - Whether or not the user prefers to autodetect collectibles. */ - setUseCollectibleDetection(val) { - const { openSeaEnabled } = this.store.getState(); - if (val && !openSeaEnabled) { - throw new Error( - 'useCollectibleDetection cannot be enabled if openSeaEnabled is false', - ); - } - this.store.updateState({ useCollectibleDetection: val }); + setUseCollectibleDetection(useCollectibleDetection) { + this.store.updateState({ useCollectibleDetection }); } /** diff --git a/ui/components/app/collectibles-items/collectibles-items.js b/ui/components/app/collectibles-items/collectibles-items.js index 43f2af6fc..90bf3e48b 100644 --- a/ui/components/app/collectibles-items/collectibles-items.js +++ b/ui/components/app/collectibles-items/collectibles-items.js @@ -17,7 +17,11 @@ import { } from '../../../helpers/constants/design-system'; import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app'; import { getEnvironmentType } from '../../../../app/scripts/lib/util'; -import { getIpfsGateway } from '../../../selectors'; +import { + getCurrentChainId, + getIpfsGateway, + getSelectedAddress, +} from '../../../selectors'; import { ASSET_ROUTE } from '../../../helpers/constants/routes'; import { getAssetImageURL } from '../../../helpers/utils/util'; import { updateCollectibleDropDownState } from '../../../store/actions'; @@ -39,22 +43,39 @@ export default function CollectiblesItems({ const collectionsKeys = Object.keys(collections); const collectiblesDropdownState = useSelector(getCollectiblesDropdownState); const previousCollectionKeys = usePrevious(collectionsKeys); + const selectedAddress = useSelector(getSelectedAddress); + const chainId = useSelector(getCurrentChainId); useEffect(() => { if ( - !Object.keys(collectiblesDropdownState).length && - previousCollectionKeys !== collectionsKeys + chainId !== undefined && + selectedAddress !== undefined && + previousCollectionKeys !== collectionsKeys && + (collectiblesDropdownState?.[selectedAddress]?.[chainId] === undefined || + Object.keys(collectiblesDropdownState?.[selectedAddress]?.[chainId]) + .length === 0) ) { const initState = {}; collectionsKeys.forEach((key) => { initState[key] = true; }); - dispatch(updateCollectibleDropDownState(initState)); + + const newCollectibleDropdownState = { + ...collectiblesDropdownState, + [selectedAddress]: { + ...collectiblesDropdownState?.[selectedAddress], + [chainId]: initState, + }, + }; + + dispatch(updateCollectibleDropDownState(newCollectibleDropdownState)); } }, [ collectionsKeys, previousCollectionKeys, collectiblesDropdownState, + selectedAddress, + chainId, dispatch, ]); @@ -84,6 +105,22 @@ export default function CollectiblesItems({ ); }; + const updateCollectibleDropDownStateKey = (key, isExpanded) => { + const currentAccountCollectibleDropdownState = + collectiblesDropdownState[selectedAddress][chainId]; + + const newCurrentAccountState = { + ...currentAccountCollectibleDropdownState, + [key]: !isExpanded, + }; + + collectiblesDropdownState[selectedAddress][ + chainId + ] = newCurrentAccountState; + + dispatch(updateCollectibleDropDownState(collectiblesDropdownState)); + }; + const renderCollection = ({ collectibles, collectionName, @@ -95,17 +132,13 @@ export default function CollectiblesItems({ return null; } - const isExpanded = collectiblesDropdownState[key]; + const isExpanded = + collectiblesDropdownState[selectedAddress]?.[chainId]?.[key]; return (