<commit_before>import React from 'react';
import { connect } from 'react-redux';
import { Action } from './actions';

const BaseNewPasswordRequired = props =>
  React.cloneElement(props.children, {
    error: props.error,
    onSubmit: props.onSubmit,
  });

const setNewPassword = (password, user, config, userAttributes, dispatch) =>
  user.completeNewPasswordChallenge(password, userAttributes, {
    onSuccess: () => dispatch(Action.authenticated(user)),
    onFailure: error => dispatch(Action.newPasswordRequiredFailure(user, error.message)),
    mfaRequired: () => dispatch(Action.mfaRequired(user)),
    newPasswordRequired: () => dispatch(Action.newPasswordRequired(user)),
  });

const mapStateToProps = state => ({
  error: state.cognito.error,
  user: state.cognito.user,
  config: state.cognito.config,
});

const mapDispatchToProps = dispatch => ({
  setNewPasswordPartial: (password, user, config, userAttributes) =>
    setNewPassword(password, user, config, userAttributes, dispatch),
});

const mergeProps = (stateProps, dispatchProps, ownProps) =>
  Object.assign({}, ownProps, stateProps, {
    onSubmit: (password, userAttributes) =>
     dispatchProps.setNewPasswordPartial(
      password,
      stateProps.user,
      stateProps.config,
      userAttributes),
  });<commit_msg>Refactor setNewPassword() to return a Promise. This (#20)<commit_after>import React from 'react';
import { connect } from 'react-redux';
import { Action } from './actions';

const BaseNewPasswordRequired = props =>
  React.cloneElement(props.children, {
    error: props.error,
    onSubmit: props.onSubmit,
  });

const setNewPassword = (password, user, config, userAttributes, dispatch) =>
  new Promise((resolve, reject) => {
    user.completeNewPasswordChallenge(password, userAttributes, {
      onSuccess: () => {
        dispatch(Action.authenticated(user));
        resolve();
      },
      onFailure: error => {
        dispatch(Action.newPasswordRequiredFailure(user, error.message));
        reject(error);
      },
      mfaRequired: () => {
        dispatch(Action.mfaRequired(user));
        resolve();
      },
      newPasswordRequired: () => {
        dispatch(Action.newPasswordRequired(user));
        resolve();
      },
    });
  });

const mapStateToProps = state => ({
  error: state.cognito.error,
  user: state.cognito.user,
  config: state.cognito.config,
});

const mapDispatchToProps = dispatch => ({
  setNewPasswordPartial: (password, user, config, userAttributes) =>
    setNewPassword(password, user, config, userAttributes, dispatch),
});

const mergeProps = (stateProps, dispatchProps, ownProps) =>
  Object.assign({}, ownProps, stateProps, {
    onSubmit: (password, userAttributes) =>
     dispatchProps.setNewPasswordPartial(
      password,
      stateProps.user,
      stateProps.config,
      userAttributes),
  });
{'fraction_non_alphanumeric': 0.1351067553377669, 'fraction_numerical': 0.0007000350017500875, 'mean_word_length': 4.040564373897707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2945671', 'n_tokens_mistral': 811, 'n_tokens_neox': 805, 'n_words': 168}