Implement simple menu
This commit is contained in:
@@ -5,19 +5,21 @@ 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';
|
||||
import { ProviderPicker } from 'ts/components/top_bar/provider_picker';
|
||||
import { AccountConnection } from 'ts/components/ui/account_connection';
|
||||
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 { Text } from 'ts/components/ui/text';
|
||||
import { Dispatcher } from 'ts/redux/dispatcher';
|
||||
import { colors } from 'ts/style/colors';
|
||||
import { AccountState, ProviderType } from 'ts/types';
|
||||
import { AccountState, ProviderType, WebsitePaths } from 'ts/types';
|
||||
import { constants } from 'ts/utils/constants';
|
||||
import { utils } from 'ts/utils/utils';
|
||||
|
||||
@@ -76,19 +78,20 @@ export class ProviderDisplay extends React.Component<ProviderDisplayProps, Provi
|
||||
const accountState = this._getAccountState();
|
||||
switch (accountState) {
|
||||
case AccountState.Ready:
|
||||
case AccountState.Locked:
|
||||
return (
|
||||
<ProviderPicker
|
||||
dispatcher={this.props.dispatcher}
|
||||
networkId={this.props.networkId}
|
||||
injectedProviderName={this.props.injectedProviderName}
|
||||
providerType={this.props.providerType}
|
||||
onToggleLedgerDialog={this.props.onToggleLedgerDialog}
|
||||
blockchain={this.props.blockchain}
|
||||
/>
|
||||
<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>
|
||||
</SimpleMenu>
|
||||
);
|
||||
case AccountState.Disconnected:
|
||||
return <InstallPrompt onToggleLedgerDialog={this.props.onToggleLedgerDialog} />;
|
||||
case AccountState.Locked:
|
||||
case AccountState.Loading:
|
||||
default:
|
||||
return null;
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
import { colors, constants as sharedConstants } from '@0xproject/react-shared';
|
||||
import { RadioButton, RadioButtonGroup } from 'material-ui/RadioButton';
|
||||
import * as React from 'react';
|
||||
import { Blockchain } from 'ts/blockchain';
|
||||
import { Dispatcher } from 'ts/redux/dispatcher';
|
||||
import { ProviderType } from 'ts/types';
|
||||
|
||||
interface ProviderPickerProps {
|
||||
networkId: number;
|
||||
injectedProviderName: string;
|
||||
providerType: ProviderType;
|
||||
onToggleLedgerDialog: () => void;
|
||||
dispatcher: Dispatcher;
|
||||
blockchain: Blockchain;
|
||||
}
|
||||
|
||||
interface ProviderPickerState {}
|
||||
|
||||
export class ProviderPicker extends React.Component<ProviderPickerProps, ProviderPickerState> {
|
||||
public render(): React.ReactNode {
|
||||
const isLedgerSelected = this.props.providerType === ProviderType.Ledger;
|
||||
const menuStyle = {
|
||||
padding: 10,
|
||||
paddingTop: 15,
|
||||
paddingBottom: 15,
|
||||
};
|
||||
// Show dropdown with two options
|
||||
return (
|
||||
<div style={{ width: 225, overflow: 'hidden' }}>
|
||||
<RadioButtonGroup name="provider" defaultSelected={this.props.providerType}>
|
||||
<RadioButton
|
||||
onClick={this._onProviderRadioChanged.bind(this, ProviderType.Injected)}
|
||||
style={{ ...menuStyle, backgroundColor: !isLedgerSelected && colors.grey50 }}
|
||||
value={ProviderType.Injected}
|
||||
label={this._renderLabel(this.props.injectedProviderName, !isLedgerSelected)}
|
||||
/>
|
||||
<RadioButton
|
||||
onClick={this._onProviderRadioChanged.bind(this, ProviderType.Ledger)}
|
||||
style={{ ...menuStyle, backgroundColor: isLedgerSelected && colors.grey50 }}
|
||||
value={ProviderType.Ledger}
|
||||
label={this._renderLabel('Ledger Nano S', isLedgerSelected)}
|
||||
/>
|
||||
</RadioButtonGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
private _renderLabel(title: string, shouldShowNetwork: boolean): React.ReactNode {
|
||||
const label = (
|
||||
<div className="flex">
|
||||
<div style={{ fontSize: 14 }}>{title}</div>
|
||||
{shouldShowNetwork && this._renderNetwork()}
|
||||
</div>
|
||||
);
|
||||
return label;
|
||||
}
|
||||
private _renderNetwork(): React.ReactNode {
|
||||
const networkName = sharedConstants.NETWORK_NAME_BY_ID[this.props.networkId];
|
||||
return (
|
||||
<div className="flex" style={{ marginTop: 1 }}>
|
||||
<div className="relative" style={{ width: 14, paddingLeft: 14 }}>
|
||||
<img
|
||||
src={`/images/network_icons/${networkName.toLowerCase()}.png`}
|
||||
className="absolute"
|
||||
style={{ top: 6, width: 10 }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ color: colors.lightGrey, fontSize: 11 }}>{networkName}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
private _onProviderRadioChanged(value: string): void {
|
||||
if (value === ProviderType.Ledger) {
|
||||
this.props.onToggleLedgerDialog();
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
this.props.blockchain.updateProviderToInjectedAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user