From 67eadc332d13516027756e7615d52ddfca7a4091 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Thu, 13 Sep 2018 14:41:06 +0200 Subject: [PATCH] added blockchain connect Notification --- .../components/SelectedAccount/index.js | 36 +++++++++++++++++-- .../Wallet/views/AccountReceive/Container.js | 3 ++ .../Wallet/views/AccountSend/Container.js | 4 ++- .../Wallet/views/AccountSummary/Container.js | 3 ++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/views/Wallet/components/SelectedAccount/index.js b/src/views/Wallet/components/SelectedAccount/index.js index 98f5c092..259a9773 100644 --- a/src/views/Wallet/components/SelectedAccount/index.js +++ b/src/views/Wallet/components/SelectedAccount/index.js @@ -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, wallet: $ElementType, + blockchain: $ElementType, 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 ( + { + 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 ( - + { + await props.blockchainReconnect(discovery.network); + } + }] + } /> ); } if (discovery.completed) { // case 5: account not found and discovery is completed diff --git a/src/views/Wallet/views/AccountReceive/Container.js b/src/views/Wallet/views/AccountReceive/Container.js index 5695877b..22f5eda6 100644 --- a/src/views/Wallet/views/AccountReceive/Container.js +++ b/src/views/Wallet/views/AccountReceive/Container.js @@ -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: St className: 'receive', selectedAccount: state.selectedAccount, wallet: state.wallet, + blockchain: state.blockchain, receive: state.receive, modal: state.modal, }); const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ + blockchainReconnect: bindActionCreators(reconnect, dispatch), showAddress: bindActionCreators(showAddress, dispatch), }); diff --git a/src/views/Wallet/views/AccountSend/Container.js b/src/views/Wallet/views/AccountSend/Container.js index 847bac63..0dee8fbc 100644 --- a/src/views/Wallet/views/AccountSend/Container.js +++ b/src/views/Wallet/views/AccountSend/Container.js @@ -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: 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: St }); const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ + blockchainReconnect: bindActionCreators(reconnect, dispatch), sendFormActions: bindActionCreators(SendFormActions, dispatch), saveSessionStorage: bindActionCreators(SessionStorageActions.save, dispatch), }); diff --git a/src/views/Wallet/views/AccountSummary/Container.js b/src/views/Wallet/views/AccountSummary/Container.js index e7239ebb..5163b737 100644 --- a/src/views/Wallet/views/AccountSummary/Container.js +++ b/src/views/Wallet/views/AccountSummary/Container.js @@ -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: 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: St }); const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ + blockchainReconnect: bindActionCreators(reconnect, dispatch), addToken: bindActionCreators(TokenActions.add, dispatch), loadTokens: bindActionCreators(TokenActions.load, dispatch), removeToken: bindActionCreators(TokenActions.remove, dispatch),