Skip to content

Commit

Permalink
feat: Add SnapsSection to confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Aug 22, 2024
1 parent 187da88 commit 59f7357
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { ReactComponentLike } from 'prop-types';
import { useSelector } from 'react-redux';

import { currentConfirmationSelector } from '../../../selectors';
import { SnapsSection } from '../snaps/snaps-section';

// Components to be plugged into confirmation page can be added to the array below
const pluggedInSections: ReactComponentLike[] = [];
const pluggedInSections: ReactComponentLike[] = [SnapsSection];

const PluggableSection = () => {
const currentConfirmation = useSelector(currentConfirmationSelector);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './snaps-insight';
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { SnapUIRenderer } from '../../../../../../components/app/snaps/snap-ui-renderer';
import { Delineator } from '../../../../../../components/ui/delineator';
import { IconName, Text } from '../../../../../../components/component-library';
import {
TextColor,
TextVariant,
} from '../../../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../../../hooks/useI18nContext';
import { getSnapMetadata } from '../../../../../../selectors';

export type SnapInsightProps = {
snapId: string;
interfaceId: string;
loading: boolean;
};

export const SnapInsight: React.FunctionComponent<SnapInsightProps> = ({
snapId,
interfaceId,
loading,
}) => {
const t = useI18nContext();
const { name: snapName } = useSelector((state) =>
getSnapMetadata(state, snapId),
);

const headerComponent = (
<Text
color={TextColor.textAlternative}
marginLeft={1}
variant={TextVariant.bodySm}
>
{t('insightsFromSnap', [snapName])}
</Text>
);

return (
<Delineator iconName={IconName.Snaps} headerComponent={headerComponent}>
<SnapUIRenderer
snapId={snapId}
interfaceId={interfaceId}
isLoading={loading}
useDelineator={false}
/>
</Delineator>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './snaps-section';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { currentConfirmationSelector } from '../../../../selectors';
import { useInsightSnaps } from '../../../../../../hooks/snaps/useInsightSnaps';
import { Box } from '../../../../../../components/component-library';
import { SnapInsight } from '../snaps-insight';
import { Display, FlexDirection } from '../../../../../../helpers/constants/design-system';

export const SnapsSection = () => {
const currentConfirmation = useSelector(currentConfirmationSelector);
const { data } = useInsightSnaps(currentConfirmation?.id);

return (
<Box display={Display.Flex} flexDirection={FlexDirection.Column} gap={2}>
{data.map(({ snapId, interfaceId, loading }) => (
<SnapInsight key={snapId} snapId={snapId} interfaceId={interfaceId} loading={loading} />
))}
</Box>
);
};

0 comments on commit 59f7357

Please sign in to comment.