Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token info popover to Funding and Token Activation #3067

Merged
merged 2 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/modules/core/components/InfoPopover/InfoPopover.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@
width: 100%;
overflow: hidden;
}

.addToWallet {
float: right;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export const nativeTokenMessage: string;
export const etherscanLink: string;
export const container: string;
export const textContainer: string;
export const addToWallet: string;
32 changes: 30 additions & 2 deletions src/modules/core/components/InfoPopover/TokenInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React from 'react';
import React, { useCallback } from 'react';
import { defineMessages, FormattedMessage } from 'react-intl';
import { addToken } from '@purser/metamask/lib-esm/helpers';
import { AddressZero } from 'ethers/constants';

import CopyableAddress from '~core/CopyableAddress';
import TokenLink from '~core/TokenLink';
import Button from '~core/Button';

import TokenIcon from '~dashboard/HookedTokenIcon';
import { AnyToken } from '~data/index';
import { DEFAULT_NETWORK_INFO } from '~constants';
Expand All @@ -18,6 +22,10 @@ const MSG = defineMessages({
id: 'InfoPopover.TokenInfoPopover.TokenInfo.viewOnEtherscan',
defaultMessage: 'View on {blockExplorerName}',
},
addToWallet: {
id: 'InfoPopover.TokenInfoPopover.TokenInfo.addToWallet',
defaultMessage: 'Add token to Metamask',
},
});

interface Props {
Expand All @@ -28,7 +36,18 @@ interface Props {
const displayName = 'InfoPopover.TokenInfoPopover.TokenInfo';

const TokenInfo = ({ token, isTokenNative }: Props) => {
const { name, symbol, address } = token;
const { name, symbol, address, decimals } = token;

const handleAddAssetToMetamask = useCallback(
() =>
addToken({
address,
symbol,
decimals,
}),
[address, symbol, decimals],
);

return (
<div className={styles.main}>
<div className={styles.section}>
Expand Down Expand Up @@ -65,6 +84,15 @@ const TokenInfo = ({ token, isTokenNative }: Props) => {
blockExplorerName: DEFAULT_NETWORK_INFO.blockExplorerName,
}}
/>
{address !== AddressZero && (
<span className={styles.addToWallet}>
<Button
appearance={{ theme: 'blue' }}
text={MSG.addToWallet}
onClick={handleAddAssetToMetamask}
/>
</span>
)}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/modules/dashboard/components/TokenCard/TokenCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
display: flex;
align-items: center;
height: headerFooterHeights;
cursor: pointer;
}

.iconContainer {
Expand Down
40 changes: 23 additions & 17 deletions src/modules/dashboard/components/TokenCard/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Card from '~core/Card';
import EthUsd from '~core/EthUsd';
import Numeral from '~core/Numeral';
import CopyableAddress from '~core/CopyableAddress';
import InfoPopover from '~core/InfoPopover';
import TokenIcon from '~dashboard/HookedTokenIcon';
import { Address } from '~types/index';
import { ColonyTokens, UserTokens } from '~data/index';
Expand Down Expand Up @@ -42,24 +43,29 @@ const TokenCard = ({ domainId, nativeTokenAddress, token }: Props) => {

return (
<Card key={token.address} className={styles.main}>
<div className={styles.cardHeading}>
<TokenIcon token={token} name={token.name || undefined} size="xs" />
<div className={styles.tokenSymbol}>
{token.symbol ? (
token.symbol
) : (
<>
<FormattedMessage {...MSG.unknownToken} />
<CopyableAddress>{token.address}</CopyableAddress>
</>
)}
{token.address === nativeTokenAddress && (
<span className={styles.nativeTokenText}>
<FormattedMessage {...MSG.nativeToken} />
</span>
)}
<InfoPopover
token={token}
isTokenNative={token.address === nativeTokenAddress}
>
<div className={styles.cardHeading}>
<TokenIcon token={token} name={token.name || undefined} size="xs" />
<div className={styles.tokenSymbol}>
{token.symbol ? (
token.symbol
) : (
<>
<FormattedMessage {...MSG.unknownToken} />
<CopyableAddress>{token.address}</CopyableAddress>
</>
)}
{token.address === nativeTokenAddress && (
<span className={styles.nativeTokenText}>
<FormattedMessage {...MSG.nativeToken} />
</span>
)}
</div>
</div>
</div>
</InfoPopover>
<div
className={
tokenBalanceIsNotPositive(token, parseInt(domainId as string, 10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
padding: 16px;
min-height: 60px;
width: 100%;
cursor: pointer;
}

.tokenSymbol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BigNumber } from 'ethers/utils';

import { SMALL_TOKEN_AMOUNT_FORMAT } from '~constants';
import Icon from '~core/Icon';
import InfoPopover from '~core/InfoPopover';
import TokenIcon from '~dashboard/HookedTokenIcon';

import { UserToken } from '~data/generated';
Expand Down Expand Up @@ -119,30 +120,32 @@ const TokensTab = ({

return (
<>
<div className={styles.totalTokensContainer}>
<div
className={
totalTokensWidth <= widthLimit
? styles.tokenSymbol
: styles.tokenSymbolSmall
}
>
<TokenIcon
token={token || {}}
size={totalTokensWidth <= widthLimit ? 'xs' : 'xxs'}
/>
<InfoPopover token={token} isTokenNative>
<div className={styles.totalTokensContainer}>
<div
className={
totalTokensWidth <= widthLimit
? styles.tokenSymbol
: styles.tokenSymbolSmall
}
>
<TokenIcon
token={token || {}}
size={totalTokensWidth <= widthLimit ? 'xs' : 'xxs'}
/>
</div>
<p
ref={targetRef}
className={
totalTokensWidth <= widthLimit
? styles.totalTokens
: styles.totalTokensSmall
}
>
{formattedTotalAmount} <span>{token?.symbol}</span>
</p>
</div>
<p
ref={targetRef}
className={
totalTokensWidth <= widthLimit
? styles.totalTokens
: styles.totalTokensSmall
}
>
{formattedTotalAmount} <span>{token?.symbol}</span>
</p>
</div>
</InfoPopover>
<div className={styles.tokensDetailsContainer}>
<ul>
<li>
Expand Down