Skip to content

Commit

Permalink
Replacing deprecated components and code for import tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewrmarshall committed Jul 26, 2023
1 parent d3c9d4a commit 4a365e5
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 124 deletions.
2 changes: 1 addition & 1 deletion test/e2e/swaps/swaps-notifications.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('Swaps - notifications', function () {
swapToContractAddress: '0x72c9Fb7ED19D3ce51cea5C56B3e023cd918baaDf',
});
await driver.clickElement(
'[data-testid="page-container__import-button"]',
'[data-testid="import-tokens-import-button"]',
);
await checkNotification(driver, {
title: 'Token added manually',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

exports[`ModalContent should match snapshot 1`] = `
<div
class="box mm-modal-content box--padding-4 box--display-flex box--flex-direction-row box--justify-content-center box--align-items-flex-start box--width-screen box--height-screen"
class="mm-box mm-modal-content mm-box--padding-4 mm-box--display-flex mm-box--justify-content-center mm-box--align-items-flex-start mm-box--width-screen mm-box--height-screen"
data-testid="test"
>
<section
aria-modal="true"
class="box mm-modal-content__dialog mm-modal-content__dialog--size-sm box--margin-top-12 box--margin-bottom-12 box--padding-4 box--flex-direction-row box--width-full box--background-color-background-default box--rounded-lg"
class="mm-box mm-modal-content__dialog mm-modal-content__dialog--size-sm mm-box--sm:margin-top-8 mm-box--md:margin-top-12 mm-box--sm:margin-bottom-8 mm-box--md:margin-bottom-12 mm-box--padding-4 mm-box--width-full mm-box--background-color-background-default mm-box--rounded-lg"
role="dialog"
>
test
Expand Down
20 changes: 9 additions & 11 deletions ui/components/component-library/modal-content/modal-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import classnames from 'classnames';
import {
BackgroundColor,
BorderRadius,
BLOCK_SIZES,
DISPLAY,
BlockSize,
Display,
JustifyContent,
AlignItems,
} from '../../../helpers/constants/design-system';

import Box from '../../ui/box/box';

import { ModalFocus, useModalContext } from '..';
import { Box, ModalFocus, useModalContext } from '..';

import { ModalContentProps, ModalContentSize } from './modal-content.types';

Expand Down Expand Up @@ -83,9 +81,9 @@ export const ModalContent = forwardRef(
<Box
className={classnames('mm-modal-content', className)}
ref={ref}
display={DISPLAY.FLEX}
width={BLOCK_SIZES.SCREEN}
height={BLOCK_SIZES.SCREEN}
display={Display.Flex}
width={BlockSize.Screen}
height={BlockSize.Screen}
justifyContent={JustifyContent.center}
alignItems={AlignItems.flexStart}
padding={4}
Expand All @@ -101,9 +99,9 @@ export const ModalContent = forwardRef(
aria-modal="true"
backgroundColor={BackgroundColor.backgroundDefault}
borderRadius={BorderRadius.LG}
width={BLOCK_SIZES.FULL}
marginTop={12}
marginBottom={12}
width={BlockSize.Full}
marginTop={[null, 8, 12]}
marginBottom={[null, 8, 12]}
padding={4}
ref={modalDialogRef}
{...modalDialogProps}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import type { BoxProps } from '../../ui/box/box.d';
import type { StyleUtilityProps } from '../box';

/*
* ModalContent sizes
Expand All @@ -11,7 +11,7 @@ export enum ModalContentSize {
Sm = 'sm',
}

export interface ModalContentProps extends BoxProps {
export interface ModalContentProps extends StyleUtilityProps {
/**
* The additional className of the ModalContent component
*/
Expand All @@ -29,5 +29,5 @@ export interface ModalContentProps extends BoxProps {
/**
* Additional props to pass to the dialog node inside of ModalContent component
*/
modalDialogProps?: BoxProps | React.HTMLAttributes<HTMLElement>;
modalDialogProps?: any;
}
9 changes: 9 additions & 0 deletions ui/components/ui/url-icon/url-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import PropTypes from 'prop-types';
import classnames from 'classnames';
import IconWithFallback from '../icon-with-fallback';

/**
* @deprecated `<UrlIcon />` has been deprecated in favor of one of the avatar components `<AvatarNetwork />`, `<AvatarToken/>` or `<AvatarFavicon/>`
* component in ./ui/components/component-library/avatar-token/
* See storybook documentation for BannerAlert here:
* {@see {@link https://metamask.github.io/metamask-storybook/?path=/docs/components-componentlibrary-avatartoken--docs}}
*
* Help to replace `UrlIcon` with `AvatarToken` by submitting a PR
*/

export default function UrlIcon({ url, className, name, fallbackClassName }) {
return (
<IconWithFallback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default function DropdownSearchList({
tabIndex="0"
>
{tokenForImport && isImportTokenModalOpen && (
<ImportToken {...importTokenProps} />
<ImportToken isOpen {...importTokenProps} />
)}
{!isOpen && (
<div
Expand Down
134 changes: 73 additions & 61 deletions ui/pages/swaps/import-token/import-token.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,102 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { I18nContext } from '../../../contexts/i18n';
import UrlIcon from '../../../components/ui/url-icon';
import Popover from '../../../components/ui/popover';
import Button from '../../../components/ui/button';
import { Text, BannerAlert, Box } from '../../../components/component-library';
import {
TextVariant,
FONT_WEIGHT,
AlignItems,
DISPLAY,
Display,
Severity,
FlexDirection,
BlockSize,
} from '../../../helpers/constants/design-system';

import {
Text,
Box,
BannerAlert,
Button,
BUTTON_VARIANT,
Modal,
ModalContent,
ModalHeader,
AvatarToken,
AvatarTokenSize,
FormTextField,
BUTTON_SIZES,
ModalOverlay,
} from '../../../components/component-library';

export default function ImportToken({
onImportTokenCloseClick,
onImportTokenClick,
setIsImportTokenModalOpen,
tokenForImport,
isOpen,
}) {
const t = useContext(I18nContext);
const ImportTokenModalFooter = (
<>
<Button
type="secondary"
className="page-container__footer-button"
onClick={onImportTokenCloseClick}
>
{t('cancel')}
</Button>
<Button
type="primary"
className="page-container__footer-button"
onClick={onImportTokenClick}
data-testid="page-container__import-button"
>
{t('import')}
</Button>
</>
);

return (
<Popover
title={t('importTokenQuestion')}
onClose={() => setIsImportTokenModalOpen(false)}
footer={ImportTokenModalFooter}
>
<Box
paddingRight={6}
paddingBottom={4}
paddingLeft={4}
alignItems={AlignItems.center}
display={DISPLAY.FLEX}
className="import-token"
<Modal isOpen={isOpen} onClose={() => setIsImportTokenModalOpen(false)}>
<ModalOverlay />
<ModalContent
modalDialogProps={{
display: Display.Flex,
flexDirection: FlexDirection.Column,
alignItems: AlignItems.center,
gap: 4,
}}
>
<ModalHeader
onClose={() => setIsImportTokenModalOpen(false)}
width={BlockSize.Full}
>
{t('importTokenQuestion')}
</ModalHeader>
<BannerAlert
severity={Severity.Danger}
description={t('importTokenWarning')}
/>
<UrlIcon
url={tokenForImport.iconUrl}
className="import-token__token-icon"
fallbackClassName="import-token__token-icon"
<AvatarToken
src={tokenForImport.iconUrl}
name={tokenForImport.symbol}
size={AvatarTokenSize.Xl}
/>
<Text
variant={TextVariant.headingSm}
as="h4"
fontWeight={FONT_WEIGHT.BOLD}
marginTop={2}
marginBottom={3}
>
<Text variant={TextVariant.headingSm} as="h4">
{tokenForImport.name || ''}
</Text>
<Text variant={TextVariant.bodySm} as="h6">
{t('contract')}:
</Text>
<Text
variant={TextVariant.bodySm}
className="import-token__contract-address"
as="h6"
marginBottom={6}
<FormTextField
label={t('contract')}
id="import-tokens-input"
inputProps={{ variant: TextVariant.bodySm }}
readOnly
value={tokenForImport.address || ''}
width={BlockSize.Full}
/>
<Box
display={Display.Flex}
flexDirection={FlexDirection.Row}
gap={4}
width={BlockSize.Full}
>
{tokenForImport.address || ''}
</Text>
</Box>
</Popover>
<Button
variant={BUTTON_VARIANT.SECONDARY}
block
size={BUTTON_SIZES.LG}
onClick={onImportTokenCloseClick}
>
{t('cancel')}
</Button>
<Button
variant={BUTTON_VARIANT.PRIMARY}
block
size={BUTTON_SIZES.LG}
onClick={onImportTokenClick}
data-testid="import-tokens-import-button"
>
{t('import')}
</Button>
</Box>
</ModalContent>
</Modal>
);
}

Expand All @@ -94,4 +105,5 @@ ImportToken.propTypes = {
onImportTokenClick: PropTypes.func,
setIsImportTokenModalOpen: PropTypes.func,
tokenForImport: PropTypes.object,
isOpen: PropTypes.bool,
};
32 changes: 17 additions & 15 deletions ui/pages/swaps/import-token/import-token.stories.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import React from 'react';
import { action } from '@storybook/addon-actions';
import ImportToken from './import-token';

export default {
title: 'Pages/Swaps/ImportToken',
argTypes: {
onImportTokenClick: { action: 'Token Imported' },
isOpen: { control: 'boolean' },
tokenForImport: {
control: 'object',
},
},
args: {
isOpen: true,
tokenForImport: {
iconUrl: './BAT_icon.svg',
name: 'Basic Attention Token',
symbol: 'BAT',
address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
},
},
};

export const DefaultStory = () => {
const data = {
iconUrl: './BAT_icon.svg',
name: 'Basic Attention Token',
symbol: 'BAT',
address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
};
return (
<ImportToken
tokenForImport={data}
onImportTokenClick={action('Token Imported')}
/>
);
};
export const DefaultStory = (args) => <ImportToken {...args} />;

DefaultStory.storyName = 'Default';
7 changes: 5 additions & 2 deletions ui/pages/swaps/import-token/import-token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ const createProps = (customProps = {}) => {
name: 'PoSToken',
address: '0xee609fe292128cad03b786dbb9bc2634ccdbe7fc',
},
isOpen: true,
...customProps,
};
};

describe('ImportToken', () => {
it('renders the component with initial props', () => {
const props = createProps();
const { getByText } = renderWithProvider(<ImportToken {...props} />);
const { getByText, getByDisplayValue } = renderWithProvider(
<ImportToken {...props} />,
);
expect(getByText(props.tokenForImport.name)).toBeInTheDocument();
expect(getByText(props.tokenForImport.address)).toBeInTheDocument();
expect(getByDisplayValue(props.tokenForImport.address)).toBeInTheDocument();
});
});
26 changes: 0 additions & 26 deletions ui/pages/swaps/import-token/index.scss

This file was deleted.

1 change: 0 additions & 1 deletion ui/pages/swaps/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@import 'slippage-buttons/index';
@import 'swaps-footer/index';
@import 'view-quote/index';
@import 'import-token/index';
@import 'create-new-swap/index';
@import 'view-on-block-explorer/index';
@import 'transaction-settings/index';
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/swaps/prepare-swap-page/prepare-swap-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ export default function PrepareSwapPage({
<div className="prepare-swap-page">
<div className="prepare-swap-page__content">
{tokenForImport && isImportTokenModalOpen && (
<ImportToken {...importTokenProps} />
<ImportToken isOpen {...importTokenProps} />
)}
<Modal
onClose={onSwapToClose}
Expand Down

0 comments on commit 4a365e5

Please sign in to comment.