Merge pull request #152 from trezor/fix/remove-selectedaccount-component

remove all references to SelectedAccount component
pull/159/head
Vladimir Volek 6 years ago committed by GitHub
commit 5e136a3015
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,115 +0,0 @@
/* @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<State, 'selectedAccount'>,
wallet: $ElementType<State, 'wallet'>,
blockchain: $ElementType<State, 'blockchain'>,
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 (<Notification type="info" title="Loading device..." />);
}
const accountState = props.selectedAccount;
const {
account,
discovery,
network,
} = accountState;
// corner case: accountState didn't finish loading state after LOCATION_CHANGE action
if (!network) return (<Notification type="info" title="Loading account state..." />);
const blockchain = props.blockchain.find(b => b.name === network.network);
if (blockchain && !blockchain.connected) {
return (
<Notification
type="error"
title="Backend not connected"
actions={
[{
label: 'Try again',
callback: async () => {
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 (
<Notification type="info" title="Loading accounts..." />
);
}
// case 2: device is unavailable (created with different passphrase settings) account cannot be accessed
return (
<Notification
type="info"
title={`Device ${device.instanceLabel} is unavailable`}
message="Change passphrase settings to use this device"
/>
);
}
// case 3: device is disconnected
return (
<Notification
type="info"
title={`Device ${device.instanceLabel} is disconnected`}
message="Connect device to load accounts"
/>
);
} if (discovery.completed) {
// case 5: account not found and discovery is completed
return (
<Notification type="warning" title="Account does not exist" />
);
}
// case 6: discovery is not completed yet
return (
<Notification type="info" title="Loading accounts..." />
);
}
let notification: ?React$Element<typeof Notification> = null;
if (!device.connected) {
notification = <Notification type="info" title={`Device ${device.instanceLabel} is disconnected`} />;
} else if (!device.available) {
notification = <Notification type="info" title={`Device ${device.instanceLabel} is unavailable`} message="Change passphrase settings to use this device" />;
}
if (discovery && !discovery.completed && !notification) {
notification = <Notification type="info" title="Loading accounts..." />;
}
return (
<section className={props.className}>
{ notification }
{ props.children }
</section>
);
};
export default SelectedAccount;

@ -2,41 +2,34 @@
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { reconnect } from 'actions/DiscoveryActions';
import { showAddress } from 'actions/ReceiveActions';
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
import type { State, Dispatch } from 'flowtype';
import type {
StateProps as BaseStateProps,
DispatchProps as BaseDispatchProps,
} from 'views/Wallet/components/SelectedAccount';
import Receive from './index';
type OwnProps = { }
type StateProps = BaseStateProps & {
type StateProps = {
selectedAccount: $ElementType<State, 'selectedAccount'>,
receive: $ElementType<State, 'receive'>,
modal: $ElementType<State, 'modal'>,
wallet: $ElementType<State, 'wallet'>,
}
type DispatchProps = BaseDispatchProps & {
type DispatchProps = {
showAddress: typeof showAddress
};
export type Props = StateProps & BaseStateProps & DispatchProps & BaseDispatchProps;
export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
className: 'receive',
selectedAccount: state.selectedAccount,
wallet: state.wallet,
blockchain: state.blockchain,
receive: state.receive,
modal: state.modal,
wallet: state.wallet,
});
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
blockchainReconnect: bindActionCreators(reconnect, dispatch),
showAddress: bindActionCreators(showAddress, dispatch),
});

@ -1,45 +1,38 @@
/* @flow */
import * as React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { reconnect } from 'actions/DiscoveryActions';
import SendFormActions from 'actions/SendFormActions';
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
import type { State, Dispatch } from 'flowtype';
import type { StateProps as BaseStateProps, DispatchProps as BaseDispatchProps } from 'views/Wallet/components/SelectedAccount';
import AccountSend from './index';
type OwnProps = { }
export type StateProps = BaseStateProps & {
export type StateProps = {
selectedAccount: $ElementType<State, 'selectedAccount'>,
sendForm: $ElementType<State, 'sendForm'>,
wallet: $ElementType<State, 'wallet'>,
fiat: $ElementType<State, 'fiat'>,
localStorage: $ElementType<State, 'localStorage'>,
children?: React.Node;
}
export type DispatchProps = BaseDispatchProps & {
export type DispatchProps = {
sendFormActions: typeof SendFormActions,
}
export type Props = StateProps & BaseStateProps & DispatchProps & BaseDispatchProps;
export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
className: 'send-from',
selectedAccount: state.selectedAccount,
wallet: state.wallet,
blockchain: state.blockchain,
sendForm: state.sendForm,
wallet: state.wallet,
fiat: state.fiat,
localStorage: state.localStorage,
});
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
blockchainReconnect: bindActionCreators(reconnect, dispatch),
sendFormActions: bindActionCreators(SendFormActions, dispatch),
});

@ -1,6 +1,6 @@
/* @flow */
import React from 'react';
import * as React from 'react';
import styled from 'styled-components';
import colors from 'config/colors';
@ -10,7 +10,11 @@ import Tooltip from 'components/Tooltip';
import Icon from 'components/Icon';
import ICONS from 'config/icons';
import type { Props } from '../../Container';
import type { Props as BaseProps } from '../../Container';
type Props = BaseProps & {
children: React.Node,
}
// TODO: Decide on a small screen width for the whole app
// and put it inside config/variables.js

@ -3,44 +3,40 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
import { reconnect } from 'actions/DiscoveryActions';
import * as TokenActions from 'actions/TokenActions';
import type { State, Dispatch } from 'flowtype';
import type { StateProps as BaseStateProps, DispatchProps as BaseDispatchProps } from 'views/Wallet/components/SelectedAccount';
import Summary from './index';
type OwnProps = { }
type StateProps = BaseStateProps & {
tokens: $ElementType<State, 'tokens'>,
type StateProps = {
selectedAccount: $ElementType<State, 'selectedAccount'>,
summary: $ElementType<State, 'summary'>,
wallet: $ElementType<State, 'wallet'>,
tokens: $ElementType<State, 'tokens'>,
fiat: $ElementType<State, 'fiat'>,
localStorage: $ElementType<State, 'localStorage'>,
};
type DispatchProps = BaseDispatchProps & {
type DispatchProps = {
addToken: typeof TokenActions.add,
loadTokens: typeof TokenActions.load,
removeToken: typeof TokenActions.remove,
}
export type Props = StateProps & BaseStateProps & DispatchProps & BaseDispatchProps;
export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
className: 'summary',
selectedAccount: state.selectedAccount,
summary: state.summary,
wallet: state.wallet,
blockchain: state.blockchain,
tokens: state.tokens,
summary: state.summary,
fiat: state.fiat,
localStorage: state.localStorage,
});
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
blockchainReconnect: bindActionCreators(reconnect, dispatch),
addToken: bindActionCreators(TokenActions.add, dispatch),
loadTokens: bindActionCreators(TokenActions.load, dispatch),
removeToken: bindActionCreators(TokenActions.remove, dispatch),

Loading…
Cancel
Save