2022-04-06 22:27:08 +02:00
|
|
|
import React, { useRef, useEffect } from 'react';
|
2023-04-24 12:21:37 +02:00
|
|
|
import { useSelector } from 'react-redux';
|
2022-02-15 01:02:51 +01:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2023-04-25 16:32:51 +02:00
|
|
|
import SnapSettingsCard from '../../../../components/app/snaps/snap-settings-card';
|
2022-02-15 01:02:51 +01:00
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
JustifyContent,
|
|
|
|
AlignItems,
|
2023-04-24 16:19:19 +02:00
|
|
|
IconColor,
|
2023-03-21 16:52:13 +01:00
|
|
|
Color,
|
|
|
|
TEXT_ALIGN,
|
|
|
|
FLEX_DIRECTION,
|
|
|
|
Size,
|
2022-02-15 01:02:51 +01:00
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import Box from '../../../../components/ui/box';
|
|
|
|
import { SNAPS_VIEW_ROUTE } from '../../../../helpers/constants/routes';
|
2023-04-24 12:21:37 +02:00
|
|
|
import { getSnapsList } from '../../../../selectors';
|
2022-03-23 17:47:54 +01:00
|
|
|
import { handleSettingsRefs } from '../../../../helpers/utils/settings-search';
|
2023-04-04 18:48:04 +02:00
|
|
|
import {
|
|
|
|
BannerTip,
|
|
|
|
BannerTipLogoType,
|
|
|
|
ButtonLink,
|
2023-04-24 16:19:19 +02:00
|
|
|
Icon,
|
|
|
|
IconName,
|
|
|
|
IconSize,
|
2023-07-20 21:49:35 +02:00
|
|
|
Text,
|
2023-03-21 16:52:13 +01:00
|
|
|
} from '../../../../components/component-library';
|
2022-02-15 01:02:51 +01:00
|
|
|
|
|
|
|
const SnapListTab = () => {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const history = useHistory();
|
2022-04-06 22:27:08 +02:00
|
|
|
const settingsRef = useRef();
|
2022-02-15 01:02:51 +01:00
|
|
|
const onClick = (snap) => {
|
2022-05-11 22:14:53 +02:00
|
|
|
history.push(`${SNAPS_VIEW_ROUTE}/${encodeURIComponent(snap.id)}`);
|
2022-02-15 01:02:51 +01:00
|
|
|
};
|
|
|
|
|
2022-03-23 17:47:54 +01:00
|
|
|
useEffect(() => {
|
|
|
|
handleSettingsRefs(t, t('snaps'), settingsRef);
|
2022-04-06 22:27:08 +02:00
|
|
|
}, [settingsRef, t]);
|
2022-03-23 17:47:54 +01:00
|
|
|
|
2023-04-24 12:21:37 +02:00
|
|
|
const snapsList = useSelector((state) => getSnapsList(state));
|
|
|
|
|
2022-02-15 01:02:51 +01:00
|
|
|
return (
|
2022-03-23 17:47:54 +01:00
|
|
|
<div className="snap-list-tab" ref={settingsRef}>
|
2023-04-24 12:21:37 +02:00
|
|
|
{snapsList.length ? (
|
2022-02-15 01:02:51 +01:00
|
|
|
<div className="snap-list-tab__body">
|
|
|
|
<div className="snap-list-tab__wrapper">
|
2023-04-24 12:21:37 +02:00
|
|
|
{snapsList.map((snap) => {
|
2022-02-15 01:02:51 +01:00
|
|
|
return (
|
|
|
|
<SnapSettingsCard
|
|
|
|
className="snap-settings-card"
|
2023-04-24 12:21:37 +02:00
|
|
|
key={snap.key}
|
|
|
|
packageName={snap.packageName}
|
|
|
|
name={snap.name}
|
2022-02-15 01:02:51 +01:00
|
|
|
onClick={() => {
|
|
|
|
onClick(snap);
|
|
|
|
}}
|
2023-04-24 12:21:37 +02:00
|
|
|
snapId={snap.id}
|
2022-02-15 01:02:51 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Box
|
|
|
|
className="snap-list-tab__container--no-snaps"
|
|
|
|
width="full"
|
|
|
|
height="full"
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2023-03-21 16:52:13 +01:00
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
2022-02-15 01:02:51 +01:00
|
|
|
>
|
2023-03-21 16:52:13 +01:00
|
|
|
<Box
|
|
|
|
className="snap-list-tab__container--no-snaps_inner"
|
|
|
|
width="full"
|
|
|
|
height="full"
|
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
justifyContent={JustifyContent.center}
|
|
|
|
alignItems={AlignItems.center}
|
2023-02-02 21:15:26 +01:00
|
|
|
>
|
2023-03-21 16:52:13 +01:00
|
|
|
<Icon
|
2023-04-24 16:19:19 +02:00
|
|
|
name={IconName.Snaps}
|
|
|
|
color={IconColor.iconMuted}
|
2023-03-21 16:52:13 +01:00
|
|
|
className="snap-list-tab__no-snaps_icon"
|
2023-04-24 16:19:19 +02:00
|
|
|
size={IconSize.Inherit}
|
2023-03-21 16:52:13 +01:00
|
|
|
/>
|
|
|
|
<Text
|
|
|
|
color={Color.textMuted}
|
|
|
|
align={TEXT_ALIGN.CENTER}
|
|
|
|
marginTop={4}
|
|
|
|
>
|
|
|
|
{t('noSnaps')}
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
className="snap-list-tab__container--no-snaps_banner-tip"
|
|
|
|
width="full"
|
|
|
|
justifyContent={JustifyContent.center}
|
|
|
|
alignItems={AlignItems.flexEnd}
|
|
|
|
paddingLeft={4}
|
|
|
|
paddingRight={4}
|
|
|
|
paddingBottom={4}
|
|
|
|
>
|
|
|
|
<BannerTip
|
|
|
|
logoType={BannerTipLogoType.Greeting}
|
|
|
|
title={t('exploreMetaMaskSnaps')}
|
|
|
|
description={t('extendWalletWithSnaps')}
|
|
|
|
>
|
|
|
|
<ButtonLink
|
|
|
|
size={Size.auto}
|
|
|
|
href="https://metamask.io/snaps/"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{`${t('learnMoreUpperCase')}`}
|
|
|
|
</ButtonLink>
|
|
|
|
</BannerTip>
|
|
|
|
</Box>
|
2022-02-15 01:02:51 +01:00
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SnapListTab;
|