/* @flow */ import * as React from 'react'; import { Notification } from 'components/common/Notification'; import type { State, TrezorDevice, Action, ThunkAction, } from 'flowtype'; import type { Account } from 'reducers/AccountsReducer'; import type { Discovery } from 'reducers/DiscoveryReducer'; export type StateProps = { className: string; selectedAccount: $ElementType, wallet: $ElementType, children?: React.Node } export type DispatchProps = { } export type Props = StateProps & DispatchProps; const SelectedAccount = (props: Props) => { const device = props.wallet.selectedDevice; if (!device || !device.state) { return (
); } const accountState = props.selectedAccount; const { account, discovery, } = accountState; // account not found (yet). checking why... if (!account) { if (!discovery || discovery.waitingForDevice) { if (device.connected) { // case 1: device is connected but discovery not started yet (probably waiting for auth) if (device.available) { return (
); } // case 2: device is unavailable (created with different passphrase settings) account cannot be accessed return (
); } // case 3: device is disconnected return (
); } if (discovery.waitingForBackend) { // case 4: backend is not working return (
); } if (discovery.completed) { // case 5: account not found and discovery is completed return (
); } // case 6: discovery is not completed yet return (
); } let notification: ?React$Element = null; if (!device.connected) { notification = ; } else if (!device.available) { notification = ; } if (discovery && !discovery.completed && !notification) { notification = ; } return (
{ notification } { props.children }
); }; export default SelectedAccount;