summaryrefslogtreecommitdiffhomepage
path: root/app/containers/ConnectPage.js
blob: 6bcfc40cfe243f99c44fa6734e6de026aa697c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// @flow

import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { push } from 'react-router-redux';
import { links } from '../config';
import Connect from '../components/Connect';
import connectActions from '../redux/connection/actions';
import { open } from '../lib/platform';

import type { ReduxState, ReduxDispatch } from '../redux/store';
import type { SharedRouteProps } from '../routes';

const mapStateToProps = (state: ReduxState) => {
  return {
    accountExpiry: state.account.expiry,
    connection: state.connection,
    settings: state.settings,
  };
};

const mapDispatchToProps = (dispatch: ReduxDispatch, props: SharedRouteProps) => {
  const { connect, disconnect, copyIPAddress } = bindActionCreators(connectActions, dispatch);
  const { push: pushHistory } = bindActionCreators({ push }, dispatch);
  const { backend } = props;

  return {
    onSettings: () => {
      pushHistory('/settings');
    },
    onSelectLocation: () => {
      pushHistory('/select-location');
    },
    onConnect: () => {
      connect(backend);
    },
    onCopyIP: () => {
      copyIPAddress();
    },
    onDisconnect: () => {
      disconnect(backend);
    },
    onExternalLink: (type) => open(links[type]),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(Connect);