/* @flow */ 'use strict'; import React, { Component } from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import Tooltip from 'rc-tooltip'; import { QRCode } from 'react-qr-svg'; import AbstractAccount from './account/AbstractAccount'; import { Notification } from '../common/Notification'; import { default as ReceiveActions } from '../../actions/ReceiveActions'; import { default as AbstractAccountActions } from '../../actions/AbstractAccountActions'; import type { MapStateToProps, MapDispatchToProps } from 'react-redux'; import type { State, Dispatch } from '../../flowtype'; import type { StateProps as BaseStateProps, DispatchProps as BaseDispatchProps, Props as BaseProps} from './account/AbstractAccount'; import type { AccountState } from './account/AbstractAccount'; type OwnProps = { } type StateProps = StateProps & { receive: $ElementType, } type DispatchProps = BaseDispatchProps & { showAddress: typeof ReceiveActions.showAddress } type Props = BaseProps & StateProps & DispatchProps; class Receive extends AbstractAccount { render() { return super.render() || _render(this.props, this.state); } } const _render = (props: Props, state: AccountState): React$Element => { const { device, account, deviceStatusNotification } = state; if (!device || !account) return
; const { addressVerified, addressUnverified, } = props.receive; let qrCode = null; let address = `${account.address.substring(0, 20)}...`; let className = 'address hidden'; let button = ( ); if (addressVerified || addressUnverified) { qrCode = ( ); address = account.address; className = addressUnverified ? 'address unverified' : 'address'; const tooltip = addressUnverified ? (
Unverified address.
{ device.connected && device.available ? 'Show on TREZOR' : 'Connect your TREZOR to verify it.' }
) : (
{ device.connected ? 'Show on TREZOR' : 'Connect your TREZOR to verify address.' }
); button = ( } overlay={ tooltip } placement="bottomRight"> ); } return (
{ deviceStatusNotification }

Receive Ethereum or tokens

{ address }
{ button }
{ qrCode }
); } const mapStateToProps: MapStateToProps = (state: State, own: OwnProps): StateProps => { return { abstractAccount: state.abstractAccount, devices: state.connect.devices, accounts: state.accounts, discovery: state.discovery, receive: state.receive }; } const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch): DispatchProps => { return { abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch), initAccount: bindActionCreators(ReceiveActions.init, dispatch), updateAccount: bindActionCreators(ReceiveActions.update, dispatch), disposeAccount: bindActionCreators(ReceiveActions.dispose, dispatch), showAddress: bindActionCreators(ReceiveActions.showAddress, dispatch), }; } export default connect(mapStateToProps, mapDispatchToProps)(Receive);