From f97e605bf6769a17d0352219f5fb1133f7cb2430 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 18 Jun 2018 16:55:52 -0700 Subject: Consolidate account state messaging logic --- .../website/ts/components/portal/drawer_menu.tsx | 28 +++++++++++------ .../ts/components/top_bar/provider_display.tsx | 35 +++++++++------------ packages/website/ts/components/top_bar/top_bar.tsx | 9 +++++- packages/website/ts/components/ui/identicon.tsx | 36 ++++++++++++---------- packages/website/ts/utils/utils.ts | 19 ++++++++++++ 5 files changed, 80 insertions(+), 47 deletions(-) (limited to 'packages/website') diff --git a/packages/website/ts/components/portal/drawer_menu.tsx b/packages/website/ts/components/portal/drawer_menu.tsx index 8ac2b9091..4bd07769f 100644 --- a/packages/website/ts/components/portal/drawer_menu.tsx +++ b/packages/website/ts/components/portal/drawer_menu.tsx @@ -2,10 +2,12 @@ import { Styles } from '@0xproject/react-shared'; import * as _ from 'lodash'; import * as React from 'react'; +import { Blockchain } from 'ts/blockchain'; import { defaultMenuItemEntries, Menu } from 'ts/components/portal/menu'; import { Identicon } from 'ts/components/ui/identicon'; +import { Text } from 'ts/components/ui/text'; import { colors } from 'ts/style/colors'; -import { WebsitePaths } from 'ts/types'; +import { ProviderType, WebsitePaths } from 'ts/types'; import { utils } from 'ts/utils/utils'; const IDENTICON_DIAMETER = 45; @@ -25,14 +27,15 @@ const styles: Styles = { MozBorderRadius: BORDER_RADIUS, WebkitBorderRadius: BORDER_RADIUS, }, - userAddress: { - color: colors.white, - }, }; export interface DrawerMenuProps { selectedPath?: string; userAddress?: string; + injectedProviderName: string; + providerType: ProviderType; + blockchain?: Blockchain; + blockchainIsLoaded: boolean; } export const DrawerMenu = (props: DrawerMenuProps) => { const relayerItemEntry = { @@ -41,9 +44,15 @@ export const DrawerMenu = (props: DrawerMenuProps) => { iconName: 'zmdi-portable-wifi', }; const menuItemEntries = _.concat(relayerItemEntry, defaultMenuItemEntries); + const displayMessage = utils.getReadableAccountState( + props.blockchainIsLoaded && !_.isUndefined(props.blockchain), + props.providerType, + props.injectedProviderName, + props.userAddress, + ); return (
-
+
); @@ -51,17 +60,16 @@ export const DrawerMenu = (props: DrawerMenuProps) => { interface HeaderProps { userAddress?: string; + displayMessage: string; } const Header = (props: HeaderProps) => { return (
- {!_.isUndefined(props.userAddress) && ( -
- {utils.getAddressBeginAndEnd(props.userAddress)} -
- )} + + {props.displayMessage} +
); diff --git a/packages/website/ts/components/top_bar/provider_display.tsx b/packages/website/ts/components/top_bar/provider_display.tsx index cb7c9b483..0e9954350 100644 --- a/packages/website/ts/components/top_bar/provider_display.tsx +++ b/packages/website/ts/components/top_bar/provider_display.tsx @@ -6,8 +6,10 @@ import * as React from 'react'; import { Blockchain } from 'ts/blockchain'; import { ProviderPicker } from 'ts/components/top_bar/provider_picker'; +import { Container } from 'ts/components/ui/container'; import { DropDown } from 'ts/components/ui/drop_down'; import { Identicon } from 'ts/components/ui/identicon'; +import { Text } from 'ts/components/ui/text'; import { Dispatcher } from 'ts/redux/dispatcher'; import { colors } from 'ts/style/colors'; import { ProviderType } from 'ts/types'; @@ -40,23 +42,16 @@ const styles: Styles = { export class ProviderDisplay extends React.Component { public render(): React.ReactNode { - const isAddressAvailable = !_.isEmpty(this.props.userAddress); const isExternallyInjectedProvider = utils.isExternallyInjected( this.props.providerType, this.props.injectedProviderName, ); - let displayMessage; - if (!this._isBlockchainReady()) { - displayMessage = 'loading account'; - } else if (isAddressAvailable) { - displayMessage = utils.getAddressBeginAndEnd(this.props.userAddress); - // tslint:disable-next-line: prefer-conditional-expression - } else if (isExternallyInjectedProvider) { - displayMessage = 'Account locked'; - } else { - displayMessage = '0x0000...0000'; - } - + const displayMessage = utils.getReadableAccountState( + this._isBlockchainReady(), + this.props.providerType, + this.props.injectedProviderName, + this.props.userAddress, + ); // If the "injected" provider is our fallback public node, then we want to // show the "connect a wallet" message instead of the providerName const injectedProviderName = isExternallyInjectedProvider @@ -66,7 +61,7 @@ export class ProviderDisplay extends React.Component +
{this._isBlockchainReady() ? ( @@ -74,13 +69,13 @@ export class ProviderDisplay extends React.Component )}
-
-
{displayMessage}
-
+ + + {displayMessage} + + {isProviderMetamask && ( -
- -
+ )}
); diff --git a/packages/website/ts/components/top_bar/top_bar.tsx b/packages/website/ts/components/top_bar/top_bar.tsx index 1a69827a4..537edc7bb 100644 --- a/packages/website/ts/components/top_bar/top_bar.tsx +++ b/packages/website/ts/components/top_bar/top_bar.tsx @@ -297,7 +297,14 @@ export class TopBar extends React.Component { openSecondary={true} onRequestChange={this._onMenuButtonClick.bind(this)} > - + ); } diff --git a/packages/website/ts/components/ui/identicon.tsx b/packages/website/ts/components/ui/identicon.tsx index 83c86a144..6a9b94e5b 100644 --- a/packages/website/ts/components/ui/identicon.tsx +++ b/packages/website/ts/components/ui/identicon.tsx @@ -1,7 +1,8 @@ import blockies = require('blockies'); import * as _ from 'lodash'; import * as React from 'react'; -import { constants } from 'ts/utils/constants'; + +import { colors } from 'ts/style/colors'; interface IdenticonProps { address: string; @@ -16,14 +17,9 @@ export class Identicon extends React.Component { style: {}, }; public render(): React.ReactNode { - let address = this.props.address; - if (_.isEmpty(address)) { - address = constants.NULL_ADDRESS; - } + const address = this.props.address; const diameter = this.props.diameter; - const icon = blockies({ - seed: address.toLowerCase(), - }); + const radius = diameter / 2; return (
{ ...this.props.style, }} > - + {!_.isEmpty(address) ? ( + + ) : ( + + + + )}
); } diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 414361c1b..0bd3dbcfa 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -190,6 +190,25 @@ export const utils = { const truncatedAddress = `${address.substring(0, 6)}...${address.substr(-4)}`; // 0x3d5a...b287 return truncatedAddress; }, + getReadableAccountState( + isBlockchainReady: boolean, + providerType: ProviderType, + injectedProviderName: string, + userAddress?: string, + ): string { + const isAddressAvailable = !_.isUndefined(userAddress) && !_.isEmpty(userAddress); + const isExternallyInjectedProvider = utils.isExternallyInjected(providerType, injectedProviderName); + if (!isBlockchainReady) { + return 'Loading account'; + } else if (isAddressAvailable) { + return utils.getAddressBeginAndEnd(userAddress); + // tslint:disable-next-line: prefer-conditional-expression + } else if (isExternallyInjectedProvider) { + return 'Account locked'; + } else { + return 'No wallet detected'; + } + }, hasUniqueNameAndSymbol(tokens: Token[], token: Token): boolean { if (token.isRegistered) { return true; // Since it's registered, it is the canonical token -- cgit v1.2.3