import { Snap } from '@metamask/snaps-utils'; import React, { useState, useEffect } from 'react'; import { shallowEqual, useSelector } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { Box } from '../../../components/component-library'; import { Text } from '../../../components/component-library/text/deprecated'; import { AlignItems, Display, FlexDirection, FlexWrap, JustifyContent, TextColor, TextVariant, } from '../../../helpers/constants/design-system'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { getSnaps, getsnapsAddSnapAccountModalDismissed, getSnapRegistry, } from '../../../selectors'; import { setSnapsAddSnapAccountModalDismissed, updateSnapRegistry, } from '../../../store/actions'; import AddSnapAccountModal from '../add-snap-account-modal'; import SnapCard from '../snap-card/snap-card'; export interface SnapDetails { id: string; snapId: string; iconUrl: string; snapTitle: string; snapSlug: string; snapDescription: string; tags: string[]; developer: string; website: string; auditUrls: string[]; version: string; lastUpdated: string; } export interface SnapCardProps extends SnapDetails { isInstalled: boolean; updateAvailable: boolean; } export default function NewSnapAccountPage() { const t = useI18nContext(); const history = useHistory(); const [showPopup, setShowPopup] = useState(true); const installedSnaps: Record = useSelector(getSnaps); const snapRegistryList: Record = useSelector( getSnapRegistry, shallowEqual, ); useEffect(() => { updateSnapRegistry().catch((err) => console.log(`Failed to fetch snap list: ${err}`), ); }, []); const hidePopup = async () => { setShowPopup(false); await setSnapsAddSnapAccountModalDismissed(); }; const snapsAddSnapAccountModalDismissed = useSelector( getsnapsAddSnapAccountModalDismissed, ); return ( { await hidePopup(); }} isOpen={showPopup && !snapsAddSnapAccountModalDismissed} /> {t('snapCreateAccountTitle', [ {t('snapCreateAccountTitle2')} , ])} {t('snapCreateAccountSubtitle')} {Object.values(snapRegistryList).map( (snap: SnapDetails, index: number) => { const foundSnap = Object.values(installedSnaps).find( (installedSnap) => installedSnap.id === snap.snapId, ); const isInstalled = Boolean(foundSnap); return ( { history.push(`/add-snap-account/${snap.id}`); }} /> ); }, )} ); }