<commit_before>import { saveTransaction, updateTransaction } from './actions'
import { Dispatch } from 'redux'
import { TransactionReceipt, PromiEvent } from 'web3/types'

/* sends a transactions to the chain, and saves it into state
   Params:
   @dispatch is needed to send the updates to state
   @transaction is a function that sends a tx to the chain (i.e., it calls a contract method, supplies any expected parameters)
   @userAddress, @assessmentAddress and @purpose are used to mark the place where the transaction was triggered
   @callbacks: callback functions to be called in different transaction circumstances
*/

export function sendAndReactToTransaction (
  dispatch: Dispatch<any, any>,
  transaction: () => PromiEvent<any>,
  purpose: 'makeAssessment' | 'meetingPointChange' | 'refund',
  userAddress: string,
  assessmentAddress: string,
  callbacks: {
    transactionHash: (hash: string) => void | null,
    confirmation: (status: boolean, receipt: TransactionReceipt | Error) => void,
    error: (error: Error) => void
  }
  ) {
  transaction()
    .on('transactionHash', (hash: string) => {
      dispatch(saveTransaction(assessmentAddress, userAddress, purpose, hash))
      if (callbacks.transactionHash) callbacks.transactionHash(hash)
    })
    .on('confirmation', (confirmationNumber, receipt) => {
      // TODO: choose a good confirmation number (kovan and rinkeby accept 2, but local textnet requires 8)
      if (confirmationNumber === 4) {
        dispatch(updateTransaction(
          receipt.transactionHash,
          assessmentAddress,
          userAddress,
          purpose,
          receipt.status ? 'confirmed' : 'failed'
        ))
        if (callbacks.confirmation) {
          if (receipt.status) {
            callbacks.confirmation(false, receipt)
          } else {<commit_msg>changed assessmentAddress to contractAddress<commit_after>import { saveTransaction, updateTransaction } from './actions'
import { Dispatch } from 'redux'
import { TransactionReceipt, PromiEvent } from 'web3/types'

/* sends a transactions to the chain, and saves it into state
   Params:
   @dispatch is needed to send the updates to state
   @transaction is a function that sends a tx to the chain (i.e., it calls a contract method, supplies any expected parameters)
   @userAddress, @contractAddress and @purpose are used to mark the place where the transaction was triggered
   @callbacks: callback functions to be called in different transaction circumstances
*/

export function sendAndReactToTransaction (
  dispatch: Dispatch<any, any>,
  transaction: () => PromiEvent<any>,
  purpose: 'makeAssessment' | 'meetingPointChange' | 'refund',
  userAddress: string,
  contractAddress: string,
  callbacks: {
    transactionHash: (hash: string) => void | null,
    confirmation: (status: boolean, receipt: TransactionReceipt | Error) => void,
    error: (error: Error) => void
  }
  ) {
  transaction()
    .on('transactionHash', (hash: string) => {
      dispatch(saveTransaction(contractAddress, userAddress, purpose, hash))
      if (callbacks.transactionHash) callbacks.transactionHash(hash)
    })
    .on('confirmation', (confirmationNumber, receipt) => {
      // TODO: choose a good confirmation number (kovan and rinkeby accept 2, but local textnet requires 8)
      if (confirmationNumber === 4) {
        dispatch(updateTransaction(
          receipt.transactionHash,
          contractAddress,
          userAddress,
          purpose,
          receipt.status ? 'confirmed' : 'failed'
        ))
        if (callbacks.confirmation) {
          if (receipt.status) {
            callbacks.confirmation(false, receipt)
          } else {
{'fraction_non_alphanumeric': 0.09687074829931973, 'fraction_numerical': 0.0021768707482993197, 'mean_word_length': 3.515970515970516, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '113381', 'n_tokens_mistral': 980, 'n_tokens_neox': 961, 'n_words': 327}