/* @flow */ import * as React from 'react'; import { Notification } from 'components/Notification'; import { reconnect } from 'actions/DiscoveryActions'; import type { State } from 'flowtype'; export type StateProps = { className: string; selectedAccount: $ElementType, wallet: $ElementType, blockchain: $ElementType, children?: React.Node } export type DispatchProps = { blockchainReconnect: typeof reconnect; } 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, network, } = accountState; // corner case: accountState didn't finish loading state after LOCATION_CHANGE action if (!network) return (); const blockchain = props.blockchain.find(b => b.name === network.network); if (blockchain && !blockchain.connected) { return ( { await props.blockchainReconnect(network.network); }, }] } /> ); } // 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.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;