1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-02-03 11:51:32 +00:00

added blockchain connect Notification

This commit is contained in:
Szymon Lesisz 2018-09-13 14:41:06 +02:00
parent 1379a2e745
commit 67eadc332d
4 changed files with 42 additions and 4 deletions

View File

@ -1,6 +1,7 @@
/* @flow */
import * as React from 'react';
import { Notification } from 'components/Notification';
import { reconnect } from 'actions/DiscoveryActions';
import type { State } from 'flowtype';
@ -8,11 +9,12 @@ 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;
@ -28,8 +30,26 @@ const SelectedAccount = (props: Props) => {
const {
account,
discovery,
network
} = accountState;
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) {
@ -57,10 +77,20 @@ const SelectedAccount = (props: Props) => {
message="Connect device to load accounts"
/>
);
} if (discovery.waitingForBackend) {
} if (discovery.waitingForBlockchain) {
// case 4: backend is not working
return (
<Notification type="warning" title="Backend not working" />
<Notification
type="error"
title="Backend not connected"
actions={
[{
label: "Try again",
callback: async () => {
await props.blockchainReconnect(discovery.network);
}
}]
} />
);
} if (discovery.completed) {
// case 5: account not found and discovery is completed

View File

@ -2,6 +2,7 @@
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';
@ -28,12 +29,14 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
className: 'receive',
selectedAccount: state.selectedAccount,
wallet: state.wallet,
blockchain: state.blockchain,
receive: state.receive,
modal: state.modal,
});
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
blockchainReconnect: bindActionCreators(reconnect, dispatch),
showAddress: bindActionCreators(showAddress, dispatch),
});

View File

@ -5,6 +5,7 @@ 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 * as SessionStorageActions from 'actions/SessionStorageActions';
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
@ -12,7 +13,6 @@ 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 & {
@ -33,6 +33,7 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
className: 'send-from',
selectedAccount: state.selectedAccount,
wallet: state.wallet,
blockchain: state.blockchain,
sendForm: state.sendForm,
fiat: state.fiat,
@ -40,6 +41,7 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
});
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({
blockchainReconnect: bindActionCreators(reconnect, dispatch),
sendFormActions: bindActionCreators(SendFormActions, dispatch),
saveSessionStorage: bindActionCreators(SessionStorageActions.save, dispatch),
});

View File

@ -3,6 +3,7 @@ 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';
@ -30,6 +31,7 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
className: 'summary',
selectedAccount: state.selectedAccount,
wallet: state.wallet,
blockchain: state.blockchain,
tokens: state.tokens,
summary: state.summary,
@ -38,6 +40,7 @@ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: St
});
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),