mirror of
https://github.com/trezor/trezor-wallet
synced 2025-06-01 05:38:45 +00:00
Merge pull request #152 from trezor/fix/remove-selectedaccount-component
remove all references to SelectedAccount component
This commit is contained in:
commit
5e136a3015
@ -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 { bindActionCreators } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { reconnect } from 'actions/DiscoveryActions';
|
|
||||||
import { showAddress } from 'actions/ReceiveActions';
|
import { showAddress } from 'actions/ReceiveActions';
|
||||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
||||||
import type { State, Dispatch } from 'flowtype';
|
import type { State, Dispatch } from 'flowtype';
|
||||||
import type {
|
|
||||||
StateProps as BaseStateProps,
|
|
||||||
DispatchProps as BaseDispatchProps,
|
|
||||||
} from 'views/Wallet/components/SelectedAccount';
|
|
||||||
import Receive from './index';
|
import Receive from './index';
|
||||||
|
|
||||||
type OwnProps = { }
|
type OwnProps = { }
|
||||||
|
|
||||||
type StateProps = BaseStateProps & {
|
type StateProps = {
|
||||||
|
selectedAccount: $ElementType<State, 'selectedAccount'>,
|
||||||
receive: $ElementType<State, 'receive'>,
|
receive: $ElementType<State, 'receive'>,
|
||||||
modal: $ElementType<State, 'modal'>,
|
modal: $ElementType<State, 'modal'>,
|
||||||
|
wallet: $ElementType<State, 'wallet'>,
|
||||||
}
|
}
|
||||||
|
|
||||||
type DispatchProps = BaseDispatchProps & {
|
type DispatchProps = {
|
||||||
showAddress: typeof showAddress
|
showAddress: typeof showAddress
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Props = StateProps & BaseStateProps & DispatchProps & BaseDispatchProps;
|
export type Props = StateProps & DispatchProps;
|
||||||
|
|
||||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
|
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
|
||||||
className: 'receive',
|
|
||||||
selectedAccount: state.selectedAccount,
|
selectedAccount: state.selectedAccount,
|
||||||
wallet: state.wallet,
|
|
||||||
blockchain: state.blockchain,
|
|
||||||
|
|
||||||
receive: state.receive,
|
receive: state.receive,
|
||||||
modal: state.modal,
|
modal: state.modal,
|
||||||
|
wallet: state.wallet,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
||||||
blockchainReconnect: bindActionCreators(reconnect, dispatch),
|
|
||||||
showAddress: bindActionCreators(showAddress, dispatch),
|
showAddress: bindActionCreators(showAddress, dispatch),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,45 +1,38 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
|
|
||||||
import * as React from 'react';
|
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import { reconnect } from 'actions/DiscoveryActions';
|
|
||||||
import SendFormActions from 'actions/SendFormActions';
|
import SendFormActions from 'actions/SendFormActions';
|
||||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
||||||
import type { State, Dispatch } from 'flowtype';
|
import type { State, Dispatch } from 'flowtype';
|
||||||
import type { StateProps as BaseStateProps, DispatchProps as BaseDispatchProps } from 'views/Wallet/components/SelectedAccount';
|
|
||||||
import AccountSend from './index';
|
import AccountSend from './index';
|
||||||
|
|
||||||
type OwnProps = { }
|
type OwnProps = { }
|
||||||
|
|
||||||
export type StateProps = BaseStateProps & {
|
export type StateProps = {
|
||||||
|
selectedAccount: $ElementType<State, 'selectedAccount'>,
|
||||||
sendForm: $ElementType<State, 'sendForm'>,
|
sendForm: $ElementType<State, 'sendForm'>,
|
||||||
|
wallet: $ElementType<State, 'wallet'>,
|
||||||
fiat: $ElementType<State, 'fiat'>,
|
fiat: $ElementType<State, 'fiat'>,
|
||||||
localStorage: $ElementType<State, 'localStorage'>,
|
localStorage: $ElementType<State, 'localStorage'>,
|
||||||
children?: React.Node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DispatchProps = BaseDispatchProps & {
|
export type DispatchProps = {
|
||||||
sendFormActions: typeof SendFormActions,
|
sendFormActions: typeof SendFormActions,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Props = StateProps & BaseStateProps & DispatchProps & BaseDispatchProps;
|
export type Props = StateProps & DispatchProps;
|
||||||
|
|
||||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
|
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
|
||||||
className: 'send-from',
|
|
||||||
selectedAccount: state.selectedAccount,
|
selectedAccount: state.selectedAccount,
|
||||||
wallet: state.wallet,
|
|
||||||
blockchain: state.blockchain,
|
|
||||||
|
|
||||||
sendForm: state.sendForm,
|
sendForm: state.sendForm,
|
||||||
|
wallet: state.wallet,
|
||||||
fiat: state.fiat,
|
fiat: state.fiat,
|
||||||
localStorage: state.localStorage,
|
localStorage: state.localStorage,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
||||||
blockchainReconnect: bindActionCreators(reconnect, dispatch),
|
|
||||||
sendFormActions: bindActionCreators(SendFormActions, dispatch),
|
sendFormActions: bindActionCreators(SendFormActions, dispatch),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import React from 'react';
|
import * as React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import colors from 'config/colors';
|
import colors from 'config/colors';
|
||||||
|
|
||||||
@ -10,7 +10,11 @@ import Tooltip from 'components/Tooltip';
|
|||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import ICONS from 'config/icons';
|
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
|
// TODO: Decide on a small screen width for the whole app
|
||||||
// and put it inside config/variables.js
|
// and put it inside config/variables.js
|
||||||
|
@ -3,44 +3,40 @@ import { bindActionCreators } from 'redux';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
||||||
import { reconnect } from 'actions/DiscoveryActions';
|
|
||||||
import * as TokenActions from 'actions/TokenActions';
|
import * as TokenActions from 'actions/TokenActions';
|
||||||
|
|
||||||
import type { State, Dispatch } from 'flowtype';
|
import type { State, Dispatch } from 'flowtype';
|
||||||
import type { StateProps as BaseStateProps, DispatchProps as BaseDispatchProps } from 'views/Wallet/components/SelectedAccount';
|
|
||||||
import Summary from './index';
|
import Summary from './index';
|
||||||
|
|
||||||
type OwnProps = { }
|
type OwnProps = { }
|
||||||
|
|
||||||
type StateProps = BaseStateProps & {
|
type StateProps = {
|
||||||
tokens: $ElementType<State, 'tokens'>,
|
selectedAccount: $ElementType<State, 'selectedAccount'>,
|
||||||
summary: $ElementType<State, 'summary'>,
|
summary: $ElementType<State, 'summary'>,
|
||||||
|
wallet: $ElementType<State, 'wallet'>,
|
||||||
|
tokens: $ElementType<State, 'tokens'>,
|
||||||
fiat: $ElementType<State, 'fiat'>,
|
fiat: $ElementType<State, 'fiat'>,
|
||||||
localStorage: $ElementType<State, 'localStorage'>,
|
localStorage: $ElementType<State, 'localStorage'>,
|
||||||
};
|
};
|
||||||
|
|
||||||
type DispatchProps = BaseDispatchProps & {
|
type DispatchProps = {
|
||||||
addToken: typeof TokenActions.add,
|
addToken: typeof TokenActions.add,
|
||||||
loadTokens: typeof TokenActions.load,
|
loadTokens: typeof TokenActions.load,
|
||||||
removeToken: typeof TokenActions.remove,
|
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 => ({
|
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
|
||||||
className: 'summary',
|
|
||||||
selectedAccount: state.selectedAccount,
|
selectedAccount: state.selectedAccount,
|
||||||
wallet: state.wallet,
|
|
||||||
blockchain: state.blockchain,
|
|
||||||
|
|
||||||
tokens: state.tokens,
|
|
||||||
summary: state.summary,
|
summary: state.summary,
|
||||||
|
wallet: state.wallet,
|
||||||
|
tokens: state.tokens,
|
||||||
fiat: state.fiat,
|
fiat: state.fiat,
|
||||||
localStorage: state.localStorage,
|
localStorage: state.localStorage,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
|
||||||
blockchainReconnect: bindActionCreators(reconnect, dispatch),
|
|
||||||
addToken: bindActionCreators(TokenActions.add, dispatch),
|
addToken: bindActionCreators(TokenActions.add, dispatch),
|
||||||
loadTokens: bindActionCreators(TokenActions.load, dispatch),
|
loadTokens: bindActionCreators(TokenActions.load, dispatch),
|
||||||
removeToken: bindActionCreators(TokenActions.remove, dispatch),
|
removeToken: bindActionCreators(TokenActions.remove, dispatch),
|
||||||
|
Loading…
Reference in New Issue
Block a user