<commit_before>import React from 'react'
import { bindActionCreators } from 'redux'
import Communications from 'react-native-communications'
import { connect } from 'react-redux'
import { Clipboard } from 'react-native'
import * as actions from '../../store/reducer/sendMoney'
import { openLoginForm, LOGIN_STATUSES } from '../../store/reducer/login'
import { setOverlayOpen } from '../../store/reducer/navigation'
import InputComponent from './InputComponent'
import Config from '@Config/config'

const Page = {
  Ready: 0,
  EnterAmount: 1,
  ConfirmAmount: 2,
  MakingPayment: 3,
  PaymentComplete: 4
}

let tempClipboardString = ''

class SendMoney extends React.Component {

  constructor () {
    super()
    this.state = {
      pin: ''
    }
  }

  setClipboardContent = async () => {
    try {
      tempClipboardString = await Clipboard.getString()
    } catch (e) {
    } finally {
      Clipboard.setString('')
    }
  }

  nextPage () {
    const nextPage = (this.props.inputPage + 1) % Object.keys(Page).length
    this.props.updatePage(nextPage)
    if (nextPage === Page.EnterAmount) {
      this.setClipboardContent()
    } else if (nextPage === Page.MakingPayment) {
      Clipboard.setString(tempClipboardString)
    }
  }

  prevPage () {
    this.props.updatePage(Page.EnterAmount)
  }

  componentDidUpdate (prevProps) {
    if (this.props.payeeId !== prevProps.payeeId) {
      this.props.updateAmount('')
      this.props.updatePage(Page.Ready)
    } else if (prevProps.loading && !this.props.loading && this.props.inputPage === Page.MakingPayment) {
      this.nextPage()
    } else if (prevProps.inputPage === Page.MakingPayment
      && this.props.inputPage === Page.PaymentComplete
      && !this.props.success) {
      setTimeout(() => this.props.inputPage === Page.PaymentComplete && this.nextPage(), 1800)
    }
  }

  isPinInvalid () {
    const { pin } = this.state
    return !this.props.connection && (pin.length < 4 || pin.indexOf('.') !== -1)
  }

  isInputInvalid () {
    const { amount } = this.props
    return (
      isNaN(Number(this.props.amount))
        || Number(amount) > this.props.balance
        || Number(amount) <= 0
        || (amount.charAt(0) === '0' && amount.charAt(1) !== '.')
        || amount.charAt(amount.length - 1) === '.'
        || (amount.split('.')[1] && amount.split('.')[1].length > 2)
        || this.isPinInvalid()
    )
  }

  payByTextOnPress () {
    var action = this.props.payee.fields && this.props.payee.fields.icon === 1 ? 'exc' : 'pay'
    var text = action + ' ' + this.state.pin + ' ' + (this.props.payee.shortDisplay || this.props.payee.fields.username) + ' ' + this.props.amount
    Communications.textWithoutEncoding(Config.TXT2PAY_NO, text)
    this.props.updateAmount('')
    this.setState({pin: ''})
    this.props.updatePage(Page.Ready)
    this.props.setOverlayOpen(false)
  }

  render () {
    let inputProps

    if (this.props.resetClipboard) {
      Clipboard.setString(tempClipboardString)
    }

    if (this.props.inputPage === Page.PaymentComplete) {
      inputProps = {
        buttonText: this.props.message,
        onButtonPress: () => {},
        accessibilityLabel: 'Payment complete'
      }
    } else if (this.props.loggedIn) {
      switch (this.props.inputPage) {
        case Page.Ready: // Initial state, ready to begin
        // sometimes when pressing on the 'no' on the alert triggers the onPress here
        //-> hence the !this.props.alertShouldPopUp check
          inputProps = {
            buttonText: (this.props.payee.paymentTypes && this.props.payee.paymentTypes.length == 0 ) ? 'No payment available' : 'Send Payment',
            onButtonPress: () => { !this.props.alertShouldPopUp && !(this.props.payee.paymentTypes && this.props.payee.paymentTypes.length == 0 ) && this.nextPage() },
            accessibilityLabel: 'Ready'
          }
          break
        case Page.EnterAmount: // provide amount
          inputProps = {
            buttonText: 'Pay ' + (this.props.payee.display || this.props.payee.name || ""),
            onButtonPress: () => { this.nextPage() },<commit_msg>button to show 'no payment available' as default<commit_after>import React from 'react'
import { bindActionCreators } from 'redux'
import Communications from 'react-native-communications'
import { connect } from 'react-redux'
import { Clipboard } from 'react-native'
import * as actions from '../../store/reducer/sendMoney'
import { openLoginForm, LOGIN_STATUSES } from '../../store/reducer/login'
import { setOverlayOpen } from '../../store/reducer/navigation'
import InputComponent from './InputComponent'
import Config from '@Config/config'

const Page = {
  Ready: 0,
  EnterAmount: 1,
  ConfirmAmount: 2,
  MakingPayment: 3,
  PaymentComplete: 4
}

let tempClipboardString = ''

class SendMoney extends React.Component {

  constructor () {
    super()
    this.state = {
      pin: ''
    }
  }

  setClipboardContent = async () => {
    try {
      tempClipboardString = await Clipboard.getString()
    } catch (e) {
    } finally {
      Clipboard.setString('')
    }
  }

  nextPage () {
    const nextPage = (this.props.inputPage + 1) % Object.keys(Page).length
    this.props.updatePage(nextPage)
    if (nextPage === Page.EnterAmount) {
      this.setClipboardContent()
    } else if (nextPage === Page.MakingPayment) {
      Clipboard.setString(tempClipboardString)
    }
  }

  prevPage () {
    this.props.updatePage(Page.EnterAmount)
  }

  componentDidUpdate (prevProps) {
    if (this.props.payeeId !== prevProps.payeeId) {
      this.props.updateAmount('')
      this.props.updatePage(Page.Ready)
    } else if (prevProps.loading && !this.props.loading && this.props.inputPage === Page.MakingPayment) {
      this.nextPage()
    } else if (prevProps.inputPage === Page.MakingPayment
      && this.props.inputPage === Page.PaymentComplete
      && !this.props.success) {
      setTimeout(() => this.props.inputPage === Page.PaymentComplete && this.nextPage(), 1800)
    }
  }

  isPinInvalid () {
    const { pin } = this.state
    return !this.props.connection && (pin.length < 4 || pin.indexOf('.') !== -1)
  }

  isInputInvalid () {
    const { amount } = this.props
    return (
      isNaN(Number(this.props.amount))
        || Number(amount) > this.props.balance
        || Number(amount) <= 0
        || (amount.charAt(0) === '0' && amount.charAt(1) !== '.')
        || amount.charAt(amount.length - 1) === '.'
        || (amount.split('.')[1] && amount.split('.')[1].length > 2)
        || this.isPinInvalid()
    )
  }

  payByTextOnPress () {
    var action = this.props.payee.fields && this.props.payee.fields.icon === 1 ? 'exc' : 'pay'
    var text = action + ' ' + this.state.pin + ' ' + (this.props.payee.shortDisplay || this.props.payee.fields.username) + ' ' + this.props.amount
    Communications.textWithoutEncoding(Config.TXT2PAY_NO, text)
    this.props.updateAmount('')
    this.setState({pin: ''})
    this.props.updatePage(Page.Ready)
    this.props.setOverlayOpen(false)
  }

  render () {
    let inputProps

    if (this.props.resetClipboard) {
      Clipboard.setString(tempClipboardString)
    }

    if (this.props.inputPage === Page.PaymentComplete) {
      inputProps = {
        buttonText: this.props.message,
        onButtonPress: () => {},
        accessibilityLabel: 'Payment complete'
      }
    } else if (this.props.loggedIn) {
      switch (this.props.inputPage) {
        case Page.Ready: // Initial state, ready to begin
        // sometimes when pressing on the 'no' on the alert triggers the onPress here
        //-> hence the !this.props.alertShouldPopUp check
          inputProps = {
            buttonText: 'No payment available',
            onButtonPress: () => {},
            accessibilityLabel: 'Ready'
          }
          if (this.props.payee.paymentTypes && this.props.payee.paymentTypes.length > 0 ) {
            inputProps.buttonText = 'Send Payment'
            inputProps.onButtonPress = () => { !this.props.alertShouldPopUp && this.nextPage() }
          }
          break
        case Page.EnterAmount: // provide amount
          inputProps = {
            buttonText: 'Pay ' + (this.props.payee.display || this.props.payee.name || ""),
            onButtonPress: () => { this.nextPage() },
{'fraction_non_alphanumeric': 0.14892077655854336, 'fraction_numerical': 0.005667430362956711, 'mean_word_length': 2.732673267326733, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '2539713', 'n_tokens_mistral': 2596, 'n_tokens_neox': 2535, 'n_words': 493}