Browse Source

Refactor wallestnav to use connect & mapstatetoprops

all-modes
Miika Turunen 8 years ago
parent
commit
89225b7ea5
  1. 2
      react/src/components/dashboard/main/dashboard.render.js
  2. 39
      react/src/components/dashboard/walletsNav/walletsNav.js
  3. 18
      react/src/components/dashboard/walletsNav/walletsNav.render.js

2
react/src/components/dashboard/main/dashboard.render.js

@ -27,7 +27,7 @@ const DashboardRender = function() {
<CoindDownModal {...this.props} /> <CoindDownModal {...this.props} />
<div className={ this.isSectionActive('wallets') ? 'show' : 'hide' }> <div className={ this.isSectionActive('wallets') ? 'show' : 'hide' }>
<CoinTile {...this.props} /> <CoinTile {...this.props} />
<WalletsNav {...this.props} /> <WalletsNav />
{ !this.isNativeMode() && <WalletsProgress {...this.props} /> } { !this.isNativeMode() && <WalletsProgress {...this.props} /> }
{ !this.isNativeMode() && <WalletsBalance {...this.props} />} { !this.isNativeMode() && <WalletsBalance {...this.props} />}
<SendCoin {...this.props} /> <SendCoin {...this.props} />

39
react/src/components/dashboard/walletsNav/walletsNav.js

@ -13,18 +13,17 @@ import {
WalletsNavNoWalletRender, WalletsNavNoWalletRender,
WalletsNavWithWalletRender WalletsNavWithWalletRender
} from './walletsNav.render'; } from './walletsNav.render';
import { connect } from 'react-redux';
class WalletsNav extends React.Component { class WalletsNav extends React.Component {
constructor(props) { constructor() {
super(props); super();
this.state = {
nativeOnly: Config.iguanaLessMode,
};
this.toggleSendReceiveCoinForms = this.toggleSendReceiveCoinForms.bind(this); this.toggleSendReceiveCoinForms = this.toggleSendReceiveCoinForms.bind(this);
} }
componentWillMount() { componentWillMount() {
Store.dispatch(iguanaEdexBalance(this.props.ActiveCoin.coin)); Store.dispatch(iguanaEdexBalance(this.props.activeCoin.coin));
} }
copyMyAddress(address) { copyMyAddress(address) {
@ -32,10 +31,10 @@ class WalletsNav extends React.Component {
} }
toggleSendReceiveCoinForms() { toggleSendReceiveCoinForms() {
if (this.props.ActiveCoin.mode === 'native') { if (this.props.activeCoin.mode === 'native') {
Store.dispatch( Store.dispatch(
toggleDashboardActiveSection( toggleDashboardActiveSection(
this.props.ActiveCoin.nativeActiveSection === 'settings' ? 'default' : 'settings' this.props.activeCoin.nativeActiveSection === 'settings' ? 'default' : 'settings'
) )
); );
} else { } else {
@ -44,10 +43,10 @@ class WalletsNav extends React.Component {
} }
toggleSendCoinForm(display) { toggleSendCoinForm(display) {
if (this.props.ActiveCoin.mode === 'native') { if (this.props.activeCoin.mode === 'native') {
Store.dispatch( Store.dispatch(
toggleDashboardActiveSection( toggleDashboardActiveSection(
this.props.ActiveCoin.nativeActiveSection === 'send' ? 'default' : 'send' this.props.activeCoin.nativeActiveSection === 'send' ? 'default' : 'send'
) )
); );
} else { } else {
@ -56,10 +55,10 @@ class WalletsNav extends React.Component {
} }
toggleReceiveCoinForm(display) { toggleReceiveCoinForm(display) {
if (this.props.ActiveCoin.mode === 'native') { if (this.props.activeCoin.mode === 'native') {
Store.dispatch( Store.dispatch(
toggleDashboardActiveSection( toggleDashboardActiveSection(
this.props.ActiveCoin.nativeActiveSection === 'receive' ? 'default' : 'receive' this.props.activeCoin.nativeActiveSection === 'receive' ? 'default' : 'receive'
) )
); );
} else { } else {
@ -69,8 +68,8 @@ class WalletsNav extends React.Component {
render() { render() {
if (this.props && if (this.props &&
this.props.ActiveCoin && this.props.activeCoin &&
!this.props.ActiveCoin.coin) { !this.props.activeCoin.coin) {
return WalletsNavNoWalletRender.call(this); return WalletsNavNoWalletRender.call(this);
} }
@ -78,4 +77,14 @@ class WalletsNav extends React.Component {
} }
} }
export default WalletsNav; const mapStateToProps = (state) => {
return {
activeCoin: state.ActiveCoin,
activeHandle: state.Dashboard.activeHandle,
activeSection: state.Dashboard.activeSection,
appSettings: state.Settings.appSettings
};
};
export default connect(mapStateToProps)(WalletsNav);

18
react/src/components/dashboard/walletsNav/walletsNav.render.js

@ -24,15 +24,15 @@ export const WalletsNavWithWalletRender = function() {
return ( return (
<div> <div>
<div <div
className={ 'page-header page-header-bordered header-easydex padding-bottom-' + (this.state.nativeOnly ? '40' : '20') } className={ 'page-header page-header-bordered header-easydex padding-bottom-' + (this.props.appSettings.iguanaLess ? '40' : '20') }
id="header-dashboard" id="header-dashboard"
style={{ marginBottom: this.props.ActiveCoin.mode === 'basilisk' ? '30px' : '0' }}> style={{ marginBottom: this.props.activeCoin.mode === 'basilisk' ? '30px' : '0' }}>
<ol className={ this.state.nativeOnly ? 'hide' : 'breadcrumb' }> <ol className={ this.props.appSettings.iguanaLess ? 'hide' : 'breadcrumb' }>
<strong>{ translate('INDEX.MY') } { this.props && this.props.ActiveCoin ? this.props.ActiveCoin.coin : '-' } { translate('INDEX.ADDRESS') }: </strong> <strong>{ translate('INDEX.MY') } { this.props.activeCoin ? this.props.activeCoin.coin : '-' } { translate('INDEX.ADDRESS') }: </strong>
{ this.props && this.props.Dashboard && this.props.Dashboard.activeHandle ? this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin] : '-' } { this.props.activeHandle ? this.props.activeHandle[this.props.activeCoin.coin] : '-' }
<button <button
className="btn btn-default btn-xs clipboard-edexaddr" className="btn btn-default btn-xs clipboard-edexaddr"
onClick={ () => this.copyMyAddress(this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin]) }> onClick={ () => this.copyMyAddress(this.props.activeHandle[this.props.activeCoin.coin]) }>
<i className="icon wb-copy"></i> { translate('INDEX.COPY') } <i className="icon wb-copy"></i> { translate('INDEX.COPY') }
</button> </button>
</ol> </ol>
@ -42,18 +42,18 @@ export const WalletsNavWithWalletRender = function() {
type="button" type="button"
className="btn btn-dark waves-effect waves-light" className="btn btn-dark waves-effect waves-light"
onClick={ this.toggleSendReceiveCoinForms }> onClick={ this.toggleSendReceiveCoinForms }>
<i className="icon md-view-dashboard"></i> { this.props.ActiveCoin.mode !== 'native' ? translate('INDEX.DASHBOARD') : translate('INDEX.WALLET_INFO') } <i className="icon md-view-dashboard"></i> { this.props.activeCoin.mode !== 'native' ? translate('INDEX.DASHBOARD') : translate('INDEX.WALLET_INFO') }
</button> </button>
<button <button
type="button" type="button"
className="btn btn-primary waves-effect waves-light" className="btn btn-primary waves-effect waves-light"
onClick={ () => this.toggleSendCoinForm(!this.props.ActiveCoin.send) }> onClick={ () => this.toggleSendCoinForm(!this.props.activeCoin.send) }>
<i className="icon fa-send"></i> { translate('INDEX.SEND') } <i className="icon fa-send"></i> { translate('INDEX.SEND') }
</button> </button>
<button <button
type="button" type="button"
className="btn btn-info waves-effect waves-light" className="btn btn-info waves-effect waves-light"
onClick={ () => this.toggleReceiveCoinForm(!this.props.ActiveCoin.receive) }> onClick={ () => this.toggleReceiveCoinForm(!this.props.activeCoin.receive) }>
<i className="icon fa-inbox"></i> { translate('INDEX.RECEIVE') } <i className="icon fa-inbox"></i> { translate('INDEX.RECEIVE') }
</button> </button>
</div> </div>

Loading…
Cancel
Save