/* @flow */ 'use strict'; import React, { Component } from 'react'; import { Notification } from '../../common/Notification'; import { findDevice } from '../../../utils/reducerUtils'; import type { TrezorDevice } from '../../../reducers/TrezorConnectReducer'; export type AccountState = { device: TrezorDevice; discovery: any; account: any; } export default class AbstractAccount extends Component { device: TrezorDevice; discovery: any; account: any; deviceStatusNotification: any; constructor(props: any) { super(props); this.state = { } } setLocalVars(vars: any) { this.device = vars.device; this.discovery = vars.discovery; } componentDidMount() { this.props.initAccount(); } componentWillUpdate(newProps: any) { this.device = null; this.discovery = null; this.account = null; this.deviceStatusNotification = null; this.props.updateAccount(); } componentWillUnmount() { this.props.disposeAccount(); this.device = null; this.discovery = null; this.account = null; this.deviceStatusNotification = null; } render(state: any): any { const props = this.props; if (!state.deviceState) { return (
); } const device = findDevice(this.props.devices, state.deviceState, state.deviceId, state.deviceInstance); if (!device) { return (
Device with state {state.deviceState} not found
); } const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === state.network); const account = props.accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network); let deviceStatusNotification = null; if (!account) { if (!discovery || discovery.waitingForDevice) { if (device.connected) { if (device.available) { return (
); } else { return (
); } } else { return (
); } } else if (discovery.completed) { return (
); } else { return (
); } } else { if (!device.connected) { deviceStatusNotification = ; } else if (!device.available) { deviceStatusNotification = ; } } // Set class variables for extender classes this.device = device; this.discovery = discovery; this.account = account; this.deviceStatusNotification = deviceStatusNotification; return null; } }