<commit_before>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { getPlatform } from 'cozy-device-helper'
import { Button } from 'cozy-ui/react'
//import flag from 'cozy-flags'

import { nativeLinkOpen } from '../LinkManager'

import { generateObjectForUrl, clearState } from '../utils/onboarding'

export class ButtonLinkRegistration extends Component {
  state = {
    url: ''
  }
  render() {
    const {
      className = '',
      label,
      size,
      subtle = false,
      type = 'submit',
      theme = 'primary'
    } = this.props

    return (
      <Button
        onClick={async () => {
          await clearState()
          const {
            clientName,
            redirectURI,
            softwareID,
            softwareVersion,
            clientURI,
            logoURI,
            policyURI,
            scope
          } = this.props.onboarding.oauth
          const onboardingObject = await generateObjectForUrl({
            clientName,
            redirectURI,
            softwareID,
            softwareVersion,
            clientURI,
            logoURI,
            policyURI,
            scope
          })
          const url = `https://staging-manager.cozycloud.cc/cozy/create?domain=cozy.works&pk_campaign=drive-${getPlatform() ||
            'browser'}&onboarding=${onboardingObject}`
          this.setState({ url })
          return nativeLinkOpen({ url })
        }}
        theme={theme}
        href={this.state.url}
        label={label}
        size={size}
        className={className}
        subtle={subtle}
        type={type}
      />
    )<commit_msg>refactor: Generate url outside the handler<commit_after>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { getPlatform } from 'cozy-device-helper'
import { Button } from 'cozy-ui/react'
//import flag from 'cozy-flags'

import { nativeLinkOpen } from '../LinkManager'

import { generateObjectForUrl, clearState } from '../utils/onboarding'

export class ButtonLinkRegistration extends Component {
  state = {
    url: ''
  }
  async generateUrl() {
    await clearState()
    const {
      clientName,
      redirectURI,
      softwareID,
      softwareVersion,
      clientURI,
      logoURI,
      policyURI,
      scope
    } = this.props.onboarding.oauth
    const onboardingObject = await generateObjectForUrl({
      clientName,
      redirectURI,
      softwareID,
      softwareVersion,
      clientURI,
      logoURI,
      policyURI,
      scope
    })
    const url = `https://staging-manager.cozycloud.cc/cozy/create?domain=cozy.works&pk_campaign=drive-${getPlatform() ||
      'browser'}&onboarding=${onboardingObject}`
    this.setState({ url })
    return url
  }
  render() {
    const {
      className = '',
      label,
      size,
      subtle = false,
      type = 'submit',
      theme = 'primary'
    } = this.props
    const { url } = this.state
    return (
      <Button
        onClick={async () => {
          const generatedUrl = await this.generateUrl()
          return nativeLinkOpen({ url: generatedUrl })
        }}
        theme={theme}
        href={url}
        label={label}
        size={size}
        className={className}
        subtle={subtle}
        type={type}
      />
    )
{'fraction_non_alphanumeric': 0.11121239744758432, 'fraction_numerical': 0.0, 'mean_word_length': 2.0063926940639267, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '823852', 'n_tokens_mistral': 916, 'n_tokens_neox': 915, 'n_words': 201}