Consolidate logic for common menu items
This commit is contained in:
@@ -5,8 +5,6 @@ import RaisedButton from 'material-ui/RaisedButton';
|
||||
import ActionAccountBalanceWallet from 'material-ui/svg-icons/action/account-balance-wallet';
|
||||
import Lock from 'material-ui/svg-icons/action/lock';
|
||||
import * as React from 'react';
|
||||
import * as CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Blockchain } from 'ts/blockchain';
|
||||
import { InstallPrompt } from 'ts/components/top_bar/install_prompt';
|
||||
@@ -15,7 +13,12 @@ import { Container } from 'ts/components/ui/container';
|
||||
import { DropDown } from 'ts/components/ui/drop_down';
|
||||
import { Identicon } from 'ts/components/ui/identicon';
|
||||
import { Island } from 'ts/components/ui/island';
|
||||
import { SimpleMenu, SimpleMenuItem } from 'ts/components/ui/simple_menu';
|
||||
import {
|
||||
CopyAddressSimpleMenuItem,
|
||||
DifferentWalletSimpleMenuItem,
|
||||
GoToAccountManagementSimpleMenuItem,
|
||||
SimpleMenu,
|
||||
} from 'ts/components/ui/simple_menu';
|
||||
import { Text } from 'ts/components/ui/text';
|
||||
import { Dispatcher } from 'ts/redux/dispatcher';
|
||||
import { colors } from 'ts/style/colors';
|
||||
@@ -79,13 +82,9 @@ export class ProviderDisplay extends React.Component<ProviderDisplayProps, Provi
|
||||
case AccountState.Ready:
|
||||
return (
|
||||
<SimpleMenu>
|
||||
<CopyToClipboard text={this.props.userAddress}>
|
||||
<SimpleMenuItem text="Copy Address to Clipboard" onClick={_.noop} />
|
||||
</CopyToClipboard>
|
||||
<SimpleMenuItem text="Use a Different Wallet..." onClick={this.props.onToggleLedgerDialog} />
|
||||
<Link to={`${WebsitePaths.Portal}/account`} style={{ textDecoration: 'none' }}>
|
||||
<SimpleMenuItem text="Manage Account" onClick={_.noop} />
|
||||
</Link>
|
||||
<CopyAddressSimpleMenuItem userAddress={this.props.userAddress} />
|
||||
<DifferentWalletSimpleMenuItem onClick={this.props.onToggleLedgerDialog} />
|
||||
<GoToAccountManagementSimpleMenuItem />
|
||||
</SimpleMenu>
|
||||
);
|
||||
case AccountState.Disconnected:
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import * as _ from 'lodash';
|
||||
import * as React from 'react';
|
||||
import * as CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Container } from 'ts/components/ui/container';
|
||||
import { Text } from 'ts/components/ui/text';
|
||||
import { colors } from 'ts/style/colors';
|
||||
import { WebsitePaths } from 'ts/types';
|
||||
|
||||
export interface SimpleMenuProps {
|
||||
minWidth?: number | string;
|
||||
@@ -23,18 +26,61 @@ export const SimpleMenu: React.StatelessComponent<SimpleMenuProps> = ({ children
|
||||
);
|
||||
};
|
||||
|
||||
export interface SimpleMenuItemProps {
|
||||
text: string;
|
||||
onClick?: () => void;
|
||||
}
|
||||
export const SimpleMenuItem: React.StatelessComponent<SimpleMenuItemProps> = ({ text, onClick }) => (
|
||||
<Container marginTop="16px" className="flex flex-column">
|
||||
<Text fontSize="14px" fontColor={colors.darkGrey} onClick={onClick} hoverColor={colors.mediumBlue}>
|
||||
{text}
|
||||
</Text>
|
||||
</Container>
|
||||
);
|
||||
|
||||
SimpleMenu.defaultProps = {
|
||||
minWidth: '220px',
|
||||
};
|
||||
|
||||
export interface SimpleMenuItemProps {
|
||||
displayText: string;
|
||||
onClick?: () => void;
|
||||
}
|
||||
export const SimpleMenuItem: React.StatelessComponent<SimpleMenuItemProps> = ({ displayText, onClick }) => {
|
||||
// Falling back to _.noop for onclick retains the hovering effect
|
||||
return (
|
||||
<Container marginTop="16px" className="flex flex-column">
|
||||
<Text
|
||||
fontSize="14px"
|
||||
fontColor={colors.darkGrey}
|
||||
onClick={onClick || _.noop}
|
||||
hoverColor={colors.mediumBlue}
|
||||
>
|
||||
{displayText}
|
||||
</Text>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export interface CopyAddressSimpleMenuItemProps {
|
||||
userAddress: string;
|
||||
onClick?: () => void;
|
||||
}
|
||||
export const CopyAddressSimpleMenuItem: React.StatelessComponent<CopyAddressSimpleMenuItemProps> = ({
|
||||
userAddress,
|
||||
onClick,
|
||||
}) => {
|
||||
return (
|
||||
<CopyToClipboard text={userAddress}>
|
||||
<SimpleMenuItem displayText="Copy Address to Clipboard" onClick={onClick} />
|
||||
</CopyToClipboard>
|
||||
);
|
||||
};
|
||||
|
||||
export interface LinkSimpleMenuItemProps {
|
||||
onClick?: () => void;
|
||||
}
|
||||
export const GoToAccountManagementSimpleMenuItem: React.StatelessComponent<LinkSimpleMenuItemProps> = ({ onClick }) => {
|
||||
return (
|
||||
<Link to={`${WebsitePaths.Portal}/account`} style={{ textDecoration: 'none' }}>
|
||||
<SimpleMenuItem displayText="Manage Account..." onClick={_.noop} />
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
export interface DifferentWalletSimpleMenuItemProps {
|
||||
onClick?: () => void;
|
||||
}
|
||||
export const DifferentWalletSimpleMenuItem: React.StatelessComponent<DifferentWalletSimpleMenuItemProps> = ({
|
||||
onClick,
|
||||
}) => {
|
||||
return <SimpleMenuItem displayText="Use a Different Wallet..." onClick={onClick} />;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,12 @@ import { DropDown } from 'ts/components/ui/drop_down';
|
||||
import { IconButton } from 'ts/components/ui/icon_button';
|
||||
import { Identicon } from 'ts/components/ui/identicon';
|
||||
import { Island } from 'ts/components/ui/island';
|
||||
import { SimpleMenu, SimpleMenuItem } from 'ts/components/ui/simple_menu';
|
||||
import {
|
||||
CopyAddressSimpleMenuItem,
|
||||
DifferentWalletSimpleMenuItem,
|
||||
GoToAccountManagementSimpleMenuItem,
|
||||
SimpleMenu,
|
||||
} from 'ts/components/ui/simple_menu';
|
||||
import { Text } from 'ts/components/ui/text';
|
||||
import { TokenIcon } from 'ts/components/ui/token_icon';
|
||||
import { BodyOverlay } from 'ts/components/wallet/body_overlay';
|
||||
@@ -37,7 +42,6 @@ import {
|
||||
TokenByAddress,
|
||||
TokenState,
|
||||
TokenStateByAddress,
|
||||
WebsitePaths,
|
||||
} from 'ts/types';
|
||||
import { analytics } from 'ts/utils/analytics';
|
||||
import { constants } from 'ts/utils/constants';
|
||||
@@ -88,7 +92,6 @@ const HEADER_ITEM_KEY = 'HEADER';
|
||||
const ETHER_ITEM_KEY = 'ETHER';
|
||||
const USD_DECIMAL_PLACES = 2;
|
||||
const NO_ALLOWANCE_TOGGLE_SPACE_WIDTH = 56;
|
||||
const ACCOUNT_PATH = `${WebsitePaths.Portal}/account`;
|
||||
const PLACEHOLDER_COLOR = colors.grey300;
|
||||
const LOADING_ROWS_COUNT = 6;
|
||||
|
||||
@@ -223,16 +226,9 @@ export class Wallet extends React.Component<WalletProps, WalletState> {
|
||||
}
|
||||
popoverContent={
|
||||
<SimpleMenu minWidth="150px">
|
||||
<CopyToClipboard text={this.props.userAddress}>
|
||||
<SimpleMenuItem text="Copy Address to Clipboard" onClick={_.noop} />
|
||||
</CopyToClipboard>
|
||||
<SimpleMenuItem
|
||||
text="Use a Different Wallet..."
|
||||
onClick={this.props.onToggleLedgerDialog}
|
||||
/>
|
||||
<Link to={`${WebsitePaths.Portal}/account`} style={{ textDecoration: 'none' }}>
|
||||
<SimpleMenuItem text="Manage Account" onClick={_.noop} />
|
||||
</Link>
|
||||
<CopyAddressSimpleMenuItem userAddress={this.props.userAddress} />
|
||||
<DifferentWalletSimpleMenuItem onClick={this.props.onToggleLedgerDialog} />
|
||||
<GoToAccountManagementSimpleMenuItem />
|
||||
</SimpleMenu>
|
||||
}
|
||||
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
|
||||
|
||||
Reference in New Issue
Block a user