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 ? { this.setState({sending: false}); store.handleEvent({data: {psbt: '', fee: 0, error: '', "broadcast-fail": null}}); }} /> : Balance {this.copyAddress('string')}}> {this.state.copiedString ? "copied" : addressText} {value} {`${sats}${unconfirmedString} sats`}