Skip to content

Commit

Permalink
fix: add missing update available and arrow icon (#21101)
Browse files Browse the repository at this point in the history
Adds a missing `Update Available` and arrow icon in the Add Snap Account Page.
  • Loading branch information
montelaidev authored Oct 4, 2023
1 parent e2c29e9 commit 54b2f70
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions ui/pages/keyring-snaps/index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "./snap-account-detail-page/snap-account-detail-page";
@import "./new-snap-account-page/new-snap-account-page";
@import "./snap-card/snap-card";
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 semver from 'semver';
import { Box, Text } from '../../../components/component-library';
import {
AlignItems,
Expand Down Expand Up @@ -116,11 +117,16 @@ export default function NewSnapAccountPage() {

const isInstalled = Boolean(foundSnap);

const updateAvailable = Boolean(
foundSnap?.version && semver.gt(snap.version, foundSnap.version),
);

return (
<SnapCard
{...snap}
key={index}
isInstalled={isInstalled}
updateAvailable={updateAvailable}
onClickFunc={() => {
history.push(`/add-snap-account/${snap.id}`);
}}
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/keyring-snaps/snap-account-detail-page/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const SnapDetailHeader = ({
<Box>
{isInstalled && updateAvailable && (
<Button
variant={ButtonVariant.Primary}
variant={ButtonVariant.Secondary}
marginRight={1}
onClick={() => {
setShowConfigPopoverType(ConfigureSnapPopupType.INSTALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ exports[`SnapCard should render 1`] = `
Secure your account with MetaMask Mobile
</h3>
<div
class="mm-box mm-box--display-flex mm-box--justify-content-space-between"
class="mm-box mm-box--margin-top-2 mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-space-between mm-box--align-items-center"
>
<span
class="mm-box mm-icon mm-icon--size-md mm-box--margin-left-auto mm-box--display-inline-block mm-box--color-icon-alternative"
class="mm-box mm-icon mm-icon--size-xs mm-box--margin-left-auto mm-box--display-inline-block mm-box--color-icon-alternative"
data-testid="to-snap-detail"
style="mask-image: url('./images/icons/arrow-2-right.svg');"
/>
Expand Down
7 changes: 7 additions & 0 deletions ui/pages/keyring-snaps/snap-card/snap-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.configure-button {
&:hover {
& > * {
color: var(--color-primary-inverse);
}
}
}
9 changes: 9 additions & 0 deletions ui/pages/keyring-snaps/snap-card/snap-card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ describe('SnapCard', () => {
).toBeInTheDocument();
});
});

it('should show `Update Available` tag', () => {
const { getByText } = renderComponent({
...snap,
isInstalled: true,
updateAvailable: true,
});
expect(getByText(messages.snapUpdateAvailable.message)).toBeInTheDocument();
});
});
27 changes: 25 additions & 2 deletions ui/pages/keyring-snaps/snap-card/snap-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Icon,
IconName,
Text,
IconSize,
} from '../../../components/component-library';
import {
AlignItems,
Expand All @@ -31,13 +32,14 @@ export default function SnapCard({
snapTitle,
snapSlug,
isInstalled,
updateAvailable,
website,
id,
onClickFunc,
}: Pick<
SnapCardProps,
'iconUrl' | 'snapTitle' | 'snapSlug' | 'isInstalled' | 'website' | 'id'
> & { onClickFunc: () => void }) {
> & { onClickFunc: () => void; updateAvailable: boolean }) {
const t = useI18nContext();
const history = useHistory();
const [showConfigPopover, setShowConfigPopover] = useState(false);
Expand Down Expand Up @@ -90,11 +92,20 @@ export default function SnapCard({
</Box>
{isInstalled ? (
<Button
className="configure-button"
data-testid="configure-snap-button"
variant={ButtonVariant.Secondary}
onClick={() => setShowConfigPopover(true)}
>
{t('snapConfigure')}
<Icon
as="span"
marginLeft={2}
name={IconName.Arrow2UpRight}
style={{
verticalAlign: 'middle',
}}
/>
</Button>
) : (
<Button
Expand All @@ -119,11 +130,23 @@ export default function SnapCard({
{snapSlug}
</Text>

<Box display={Display.Flex} justifyContent={JustifyContent.spaceBetween}>
<Box
display={Display.Flex}
flexDirection={FlexDirection.Row}
justifyContent={JustifyContent.spaceBetween}
alignItems={AlignItems.center}
marginTop={2}
>
{updateAvailable && (
<Text color={TextColor.textAlternative}>
{t('snapUpdateAvailable')}
</Text>
)}
<Icon
data-testid="to-snap-detail"
name={IconName.Arrow2Right}
color={IconColor.iconAlternative}
size={IconSize.Xs}
onClick={onClickFunc}
marginLeft="auto"
/>
Expand Down

0 comments on commit 54b2f70

Please sign in to comment.