mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Token address component for Tokens Detected page (#14104)
This commit is contained in:
parent
cf0bc662c1
commit
85d3c888ac
3
app/_locales/en/messages.json
generated
3
app/_locales/en/messages.json
generated
@ -3537,6 +3537,9 @@
|
||||
"token": {
|
||||
"message": "Token"
|
||||
},
|
||||
"tokenAddress": {
|
||||
"message": "Token address"
|
||||
},
|
||||
"tokenAlreadyAdded": {
|
||||
"message": "Token has already been added."
|
||||
},
|
||||
|
@ -83,3 +83,4 @@
|
||||
@import 'advanced-gas-fee-popover/advanced-gas-fee-input-subtext/index';
|
||||
@import 'advanced-gas-fee-popover/advanced-gas-fee-defaults/index';
|
||||
@import 'currency-input/index';
|
||||
@import 'detected-token/detected-token-address/index';
|
||||
|
@ -0,0 +1,57 @@
|
||||
import React, { useContext } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { I18nContext } from '../../../../contexts/i18n';
|
||||
import { useCopyToClipboard } from '../../../../hooks/useCopyToClipboard';
|
||||
|
||||
import Box from '../../../ui/box';
|
||||
import Button from '../../../ui/button';
|
||||
import Typography from '../../../ui/typography';
|
||||
import Tooltip from '../../../ui/tooltip';
|
||||
|
||||
import {
|
||||
COLORS,
|
||||
DISPLAY,
|
||||
TYPOGRAPHY,
|
||||
} from '../../../../helpers/constants/design-system';
|
||||
|
||||
import { shortenAddress } from '../../../../helpers/utils/util';
|
||||
|
||||
const DetectedTokenAddress = ({ address }) => {
|
||||
const t = useContext(I18nContext);
|
||||
const [copied, handleCopy] = useCopyToClipboard();
|
||||
|
||||
return (
|
||||
<Box display={DISPLAY.INLINE_FLEX} className="detected-token-address">
|
||||
<Typography variant={TYPOGRAPHY.H7} color={COLORS.TEXT_DEFAULT}>
|
||||
{`${t('tokenAddress')}:`}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant={TYPOGRAPHY.H7}
|
||||
color={COLORS.PRIMARY_DEFAULT}
|
||||
margin={[1, 2]}
|
||||
>
|
||||
{shortenAddress(address)}
|
||||
</Typography>
|
||||
<Tooltip
|
||||
position="bottom"
|
||||
title={copied ? t('copiedExclamation') : t('copyToClipboard')}
|
||||
>
|
||||
<Button
|
||||
type="link"
|
||||
className="detected-token-address__copy-link"
|
||||
onClick={() => {
|
||||
handleCopy(address);
|
||||
}}
|
||||
>
|
||||
<i className="fa fa-copy" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
DetectedTokenAddress.propTypes = {
|
||||
address: PropTypes.string,
|
||||
};
|
||||
|
||||
export default DetectedTokenAddress;
|
@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
|
||||
import DetectedTokenAddress from './detected-token-address';
|
||||
|
||||
export default {
|
||||
title: 'Components/App/DetectedToken/DetectedTokenAddress',
|
||||
id: __filename,
|
||||
argTypes: {
|
||||
address: { control: 'text' },
|
||||
},
|
||||
args: {
|
||||
address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
|
||||
},
|
||||
};
|
||||
|
||||
const Template = (args) => {
|
||||
return <DetectedTokenAddress address={args.address} />;
|
||||
};
|
||||
|
||||
export const DefaultStory = Template.bind({});
|
||||
|
||||
DefaultStory.storyName = 'Default';
|
@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
import { renderWithProvider, screen } from '../../../../../test/jest';
|
||||
import configureStore from '../../../../store/store';
|
||||
|
||||
import DetectedTokenAddress from './detected-token-address';
|
||||
|
||||
describe('DetectedTokenAddress', () => {
|
||||
const args = {
|
||||
address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
|
||||
};
|
||||
|
||||
it('should render the detected token address', async () => {
|
||||
const store = configureStore({});
|
||||
renderWithProvider(<DetectedTokenAddress {...args} />, store);
|
||||
|
||||
expect(screen.getByText('Token address:')).toBeInTheDocument();
|
||||
expect(screen.getByText('0xc01...2a6f')).toBeInTheDocument();
|
||||
});
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
.detected-token-address {
|
||||
& &__copy-link {
|
||||
@include H7;
|
||||
|
||||
padding: 4px 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user