import * as _ from 'lodash'; import * as React from 'react'; import { Blockchain } from 'ts/blockchain'; import { Container } from 'ts/components/ui/container'; import { Image } from 'ts/components/ui/image'; import { Island } from 'ts/components/ui/island'; import { Text } from 'ts/components/ui/text'; import { Dispatcher } from 'ts/redux/dispatcher'; import { colors } from 'ts/style/colors'; import { styled } from 'ts/style/theme'; import { AccountState, BrowserType, ProviderType, OperatingSystemType } from 'ts/types'; import { constants } from 'ts/utils/constants'; import { utils } from 'ts/utils/utils'; const METAMASK_IMG_SRC = '/images/metamask_icon.png'; const TOSHI_IMG_SRC = '/images/toshi_logo.jpg'; export interface BodyOverlayProps { dispatcher: Dispatcher; userAddress: string; injectedProviderName: string; providerType: ProviderType; onToggleLedgerDialog: () => void; blockchain?: Blockchain; blockchainIsLoaded: boolean; } interface BodyOverlayState {} export class BodyOverlay extends React.Component { public render(): React.ReactNode { const accountState = this._getAccountState(); switch (accountState) { case AccountState.Locked: return ; case AccountState.Disconnected: return ; case AccountState.Ready: case AccountState.Loading: default: return null; } } private _isBlockchainReady(): boolean { return this.props.blockchainIsLoaded && !_.isUndefined(this.props.blockchain); } private _getAccountState(): AccountState { return utils.getAccountState( this._isBlockchainReady(), this.props.providerType, this.props.injectedProviderName, this.props.userAddress, ); } } interface LockedOverlayProps { className?: string; onUseDifferentWalletClicked?: () => void; } const PlainLockedOverlay: React.StatelessComponent = ({ className, onUseDifferentWalletClicked, }) => (
Please Unlock MetaMask
); const LockedOverlay = styled(PlainLockedOverlay)` background: ${colors.metaMaskTransparentOrange}; border: 1px solid ${colors.metaMaskOrange}; border-radius: 10px; `; interface DisconnectedOverlayProps { onUseDifferentWalletClicked?: () => void; } const DisconnectedOverlay = (props: DisconnectedOverlayProps) => { return (
{!utils.isMobileOperatingSystem() && ( )}
); }; interface UseDifferentWallet { fontColor: string; onClick?: () => void; } const UseDifferentWallet = (props: UseDifferentWallet) => { return ( Use a different wallet ); }; const GetWalletCallToAction = () => { const browserType = utils.getBrowserType(); const isOnMobile = utils.isMobileOperatingSystem(); const operatingSystem = utils.getOperatingSystem(); const imageUrl = isOnMobile ? TOSHI_IMG_SRC : METAMASK_IMG_SRC; const text = isOnMobile ? 'Get Toshi Wallet' : 'Get MetaMask Wallet'; let downloadLink; if (isOnMobile) { switch (operatingSystem) { case OperatingSystemType.Android: downloadLink = constants.URL_TOSHI_ANDROID_APP_STORE; break; case OperatingSystemType.iOS: downloadLink = constants.URL_TOSHI_IOS_APP_STORE; break; default: // Toshi is only supported on these mobile OSes - just default to iOS downloadLink = constants.URL_TOSHI_IOS_APP_STORE; } } else { switch (browserType) { case BrowserType.Chrome: downloadLink = constants.URL_METAMASK_CHROME_STORE; break; case BrowserType.Firefox: downloadLink = constants.URL_METAMASK_FIREFOX_STORE; break; case BrowserType.Opera: downloadLink = constants.URL_METAMASK_OPERA_STORE; break; default: downloadLink = constants.URL_METAMASK_HOMEPAGE; } } return ( {text} ); };