<commit_before>import React, { Component } from 'react';
import {
  Box,
  Icon,
  Row,
  Text,
  Button,
  Col,
} from '@tlon/indigo-react';

import Send from './send.js'
import CurrencyPicker from './currencyPicker.js'
import { currencyToSats, satsToCurrency } from '../../lib/util.js';


export default class Balance extends Component {
  constructor(props) {
    super(props);

    this.state = {
      sending: false,
      copiedButton: false,
      copiedString: false,
    }

    this.copyAddress = this.copyAddress.bind(this);
  }

  copyAddress(arg) {
    let address = this.props.state.address;
    function listener(e) {
      e.clipboardData.setData('text/plain', address);
      e.preventDefault();
    }

    document.addEventListener('copy', listener);
    document.execCommand('copy');
    document.removeEventListener('copy', listener);

    this.props.api.btcWalletCommand({'gen-new-address': null});

    if (arg === 'button'){
      this.setState({copiedButton: true});
      setTimeout(() => { this.setState({copiedButton: false}); }, 2000);
    } else if (arg === 'string') {
      this.setState({copiedString: true});
      setTimeout(() => { this.setState({copiedString: false}); }, 2000);
    }
  }


  render() {
    const sats = (this.props.state.confirmedBalance || 0);
    const unconfirmedSats = this.props.state.unconfirmedBalance;

    const unconfirmedString = unconfirmedSats ? ` (${unconfirmedSats}) ` : '';

    const denomination = this.props.state.denomination;
    const value = satsToCurrency(sats, denomination, this.props.state.currencyRates);
    const sendDisabled = (sats === 0);
    const addressText = (this.props.state.address === null) ? '' :
      this.props.state.address.slice(0, 6) + '...' +
      this.props.state.address.slice(-6);

    const conversion = this.props.state.currencyRates[denomination].last;

    return (
      <>
        {this.state.sending ?
         <Send
           state={this.props.state}
           api={api}
           psbt={this.props.state.psbt}
           fee={this.props.state.fee}
           currencyRates={this.props.state.currencyRates}
           shipWallets={this.props.state.shipWallets}
           value={value}
           denomination={denomination}
           sats={sats}
           conversion={conversion}
           network={this.props.network}
           error={this.props.state.error}
           stopSending={() => {
             this.setState({sending: false});
             store.handleEvent({data: {psbt: '', fee: 0, error: '', "broadcast-fail": null}});
           }}
         /> :
         <Col
           height="400px"
           width='100%'
           backgroundColor="white"
           borderRadius="48px"
           justifyContent="space-between"
           mb={5}
           p={5}
         >
           <Row justifyContent="space-between">
             <Text color="orange" fontSize={1}>Balance</Text>
             <Text color="lightGray" fontSize="14px" mono style={{cursor: "pointer"}}
                   onClick={() => {this.copyAddress('string')}}>
              {this.state.copiedString ? "copied" : addressText}
             </Text>
             <CurrencyPicker
               api={this.props.api}
               denomination={denomination}
               currencies={this.props.state.currencyRates}
             />
           </Row>
           <Col justifyContent="center" alignItems="center">
             <Text fontSize="40px" color="orange" style={{whiteSpace: "nowrap"}} >
               {value}
             </Text>
             <Text fontSize={1} color="orange">{`${sats}${unconfirmedString} sats`}</Text>
           </Col>
           <Row flexDirection="row-reverse">
             <Button children="Send"
                     disabled={sendDisabled}
                     fontSize={1}
                     fontWeight="bold"
                     color={sendDisabled ? "lighterGray" : "white"}
                     backgroundColor={sendDisabled ? "veryLightGray" : "orange"}
                     style={{cursor: sendDisabled ? "default" : "pointer" }}
                     borderColor="none"
                     borderRadius="24px"
                     py="24px"
                     px="24px"
                     onClick={() => this.setState({sending: true})}
             />
             <Button children={(this.state.copiedButton) ? "Address Copied!" : "Copy Address"}
                     mr={3}
                     disabled={this.state.copiedButton}
                     fontSize={1}
                     fontWeight="bold"
                     color={(this.state.copiedButton) ? "green" : "orange"}
                     backgroundColor={(this.state.copiedButton) ? "veryLightGreen" : "midOrange" }
                     style={{cursor: (this.state.copiedButton) ? "default" : "pointer"}}
                     borderColor="none"
                     borderRadius="24px"
                     py="24px"
                     px="24px"
                     onClick={() => {this.copyAddress('button')}}
             />
           </Row>
          </Col>
        }
      </>
    );
  }
}
<commit_msg>btc: fix safari bitcoin address copy to clipboard<commit_after>import React, { Component } from 'react';
import {
  Box,
  Icon,
  Row,
  Text,
  Button,
  Col,
} from '@tlon/indigo-react';

import Send from './send.js'
import CurrencyPicker from './currencyPicker.js'
import { currencyToSats, satsToCurrency } from '../../lib/util.js';


export default class Balance extends Component {
  constructor(props) {
    super(props);

    this.state = {
      sending: false,
      copiedButton: false,
      copiedString: false,
    }

    this.copyAddress = this.copyAddress.bind(this);
  }

  copyAddress(arg) {
    let address = this.props.state.address;
    navigator.clipboard.writeText(address);
    this.props.api.btcWalletCommand({'gen-new-address': null});

    if (arg === 'button'){
      this.setState({copiedButton: true});
      setTimeout(() => { this.setState({copiedButton: false}); }, 2000);
    } else if (arg === 'string') {
      this.setState({copiedString: true});
      setTimeout(() => { this.setState({copiedString: false}); }, 2000);
    }
  }


  render() {
    const sats = (this.props.state.confirmedBalance || 0);
    const unconfirmedSats = this.props.state.unconfirmedBalance;

    const unconfirmedString = unconfirmedSats ? ` (${unconfirmedSats}) ` : '';

    const denomination = this.props.state.denomination;
    const value = satsToCurrency(sats, denomination, this.props.state.currencyRates);
    const sendDisabled = (sats === 0);
    const addressText = (this.props.state.address === null) ? '' :
      this.props.state.address.slice(0, 6) + '...' +
      this.props.state.address.slice(-6);

    const conversion = this.props.state.currencyRates[denomination].last;

    return (
      <>
        {this.state.sending ?
         <Send
           state={this.props.state}
           api={api}
           psbt={this.props.state.psbt}
           fee={this.props.state.fee}
           currencyRates={this.props.state.currencyRates}
           shipWallets={this.props.state.shipWallets}
           value={value}
           denomination={denomination}
           sats={sats}
           conversion={conversion}
           network={this.props.network}
           error={this.props.state.error}
           stopSending={() => {
             this.setState({sending: false});
             store.handleEvent({data: {psbt: '', fee: 0, error: '', "broadcast-fail": null}});
           }}
         /> :
         <Col
           height="400px"
           width='100%'
           backgroundColor="white"
           borderRadius="48px"
           justifyContent="space-between"
           mb={5}
           p={5}
         >
           <Row justifyContent="space-between">
             <Text color="orange" fontSize={1}>Balance</Text>
             <Text color="lightGray" fontSize="14px" mono style={{cursor: "pointer"}}
                   onClick={() => {this.copyAddress('string')}}>
              {this.state.copiedString ? "copied" : addressText}
             </Text>
             <CurrencyPicker
               api={this.props.api}
               denomination={denomination}
               currencies={this.props.state.currencyRates}
             />
           </Row>
           <Col justifyContent="center" alignItems="center">
             <Text fontSize="40px" color="orange" style={{whiteSpace: "nowrap"}} >
               {value}
             </Text>
             <Text fontSize={1} color="orange">{`${sats}${unconfirmedString} sats`}</Text>
           </Col>
           <Row flexDirection="row-reverse">
             <Button children="Send"
                     disabled={sendDisabled}
                     fontSize={1}
                     fontWeight="bold"
                     color={sendDisabled ? "lighterGray" : "white"}
                     backgroundColor={sendDisabled ? "veryLightGray" : "orange"}
                     style={{cursor: sendDisabled ? "default" : "pointer" }}
                     borderColor="none"
                     borderRadius="24px"
                     py="24px"
                     px="24px"
                     onClick={() => this.setState({sending: true})}
             />
             <Button children={(this.state.copiedButton) ? "Address Copied!" : "Copy Address"}
                     mr={3}
                     disabled={this.state.copiedButton}
                     fontSize={1}
                     fontWeight="bold"
                     color={(this.state.copiedButton) ? "green" : "orange"}
                     backgroundColor={(this.state.copiedButton) ? "veryLightGreen" : "midOrange" }
                     style={{cursor: (this.state.copiedButton) ? "default" : "pointer"}}
                     borderColor="none"
                     borderRadius="24px"
                     py="24px"
                     px="24px"
                     onClick={() => {this.copyAddress('button')}}
             />
           </Row>
          </Col>
        }
      </>
    );
  }
}

{'fraction_non_alphanumeric': 0.14409136047666335, 'fraction_numerical': 0.00893743793445879, 'mean_word_length': 1.8465234595816846, 'pattern_counts': {'":': 2, '<': 47, '<?xml version=': 0, '>': 59, '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': '3741128', 'n_tokens_mistral': 2886, 'n_tokens_neox': 2775, 'n_words': 468}