import { connect } from 'react-redux';
import { DAEMON_SETTINGS, selectIsWalletReconnecting } from 'lbry-redux';
import {
  doSetDaemonSetting,
  doClearDaemonSetting,
  doGetDaemonStatus,
  doSaveCustomWalletServers,
} from 'redux/actions/settings';
import { selectSavedWalletServers, selectDaemonStatus, selectHasWalletServerPrefs } from 'redux/selectors/settings';
import SettingWalletServer from './view';

const select = state => ({
  daemonStatus: selectDaemonStatus(state),
  customWalletServers: selectSavedWalletServers(state),
  hasWalletServerPrefs: selectHasWalletServerPrefs(state),
  walletReconnecting: selectIsWalletReconnecting(state),
});

const perform = dispatch => ({
  setCustomWalletServers: value => dispatch(doSetDaemonSetting(DAEMON_SETTINGS.LBRYUM_SERVERS, value)),
  clearWalletServers: () => dispatch(doClearDaemonSetting(DAEMON_SETTINGS.LBRYUM_SERVERS)),
  getDaemonStatus: () => dispatch(doGetDaemonStatus()),
  saveServerConfig: servers => dispatch(doSaveCustomWalletServers(servers)),
});

export default connect(
  select,
  perform
)(SettingWalletServer);
