2021-04-02 23:50:51 +03:00
|
|
|
import React, { Component } from 'react';
|
2021-06-19 20:47:24 +03:00
|
|
|
import { Row, Text, Button, Col } from '@tlon/indigo-react';
|
|
|
|
import Send from './send.js';
|
|
|
|
import CurrencyPicker from './currencyPicker.js';
|
|
|
|
import { satsToCurrency } from '../../lib/util.js';
|
|
|
|
import { store } from '../../store.js';
|
2021-04-02 23:50:51 +03:00
|
|
|
|
|
|
|
export default class Balance extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2021-04-14 19:56:01 +03:00
|
|
|
sending: false,
|
2021-05-21 20:32:15 +03:00
|
|
|
copiedButton: false,
|
|
|
|
copiedString: false,
|
2021-06-19 20:47:24 +03:00
|
|
|
};
|
2021-04-20 05:45:34 +03:00
|
|
|
|
|
|
|
this.copyAddress = this.copyAddress.bind(this);
|
2021-04-02 23:50:51 +03:00
|
|
|
}
|
|
|
|
|
2021-05-21 20:32:15 +03:00
|
|
|
copyAddress(arg) {
|
2021-04-20 05:45:34 +03:00
|
|
|
let address = this.props.state.address;
|
2021-06-15 13:33:46 +03:00
|
|
|
navigator.clipboard.writeText(address);
|
2021-06-19 20:47:24 +03:00
|
|
|
this.props.api.btcWalletCommand({ 'gen-new-address': null });
|
2021-05-21 20:32:15 +03:00
|
|
|
|
2021-06-19 20:47:24 +03:00
|
|
|
if (arg === 'button') {
|
|
|
|
this.setState({ copiedButton: true });
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({ copiedButton: false });
|
|
|
|
}, 2000);
|
2021-05-21 20:32:15 +03:00
|
|
|
} else if (arg === 'string') {
|
2021-06-19 20:47:24 +03:00
|
|
|
this.setState({ copiedString: true });
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({ copiedString: false });
|
|
|
|
}, 2000);
|
2021-05-21 20:32:15 +03:00
|
|
|
}
|
2021-04-20 05:45:34 +03:00
|
|
|
}
|
|
|
|
|
2021-04-02 23:50:51 +03:00
|
|
|
render() {
|
2021-06-19 20:47:24 +03:00
|
|
|
const sats = this.props.state.confirmedBalance || 0;
|
2021-04-26 17:46:44 +03:00
|
|
|
const unconfirmedSats = this.props.state.unconfirmedBalance;
|
|
|
|
|
|
|
|
const unconfirmedString = unconfirmedSats ? ` (${unconfirmedSats}) ` : '';
|
|
|
|
|
2021-04-20 08:02:56 +03:00
|
|
|
const denomination = this.props.state.denomination;
|
2021-06-19 20:47:24 +03:00
|
|
|
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);
|
2021-04-02 23:50:51 +03:00
|
|
|
|
2021-04-20 08:02:56 +03:00
|
|
|
const conversion = this.props.state.currencyRates[denomination].last;
|
|
|
|
|
2021-04-02 23:50:51 +03:00
|
|
|
return (
|
2021-04-15 15:38:51 +03:00
|
|
|
<>
|
2021-06-19 20:47:24 +03:00
|
|
|
{this.state.sending ? (
|
|
|
|
<Send
|
|
|
|
state={this.props.state}
|
|
|
|
api={this.props.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
|
|
|
|
disabled={sendDisabled}
|
|
|
|
fontSize={1}
|
|
|
|
fontWeight="bold"
|
|
|
|
color={sendDisabled ? 'lighterGray' : 'white'}
|
|
|
|
backgroundColor={sendDisabled ? 'veryLightGray' : 'orange'}
|
|
|
|
style={{ cursor: sendDisabled ? 'default' : 'pointer' }}
|
|
|
|
borderColor="none"
|
|
|
|
borderRadius="24px"
|
|
|
|
height="48px"
|
|
|
|
onClick={() => this.setState({ sending: true })}
|
|
|
|
>
|
|
|
|
Send
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
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"
|
|
|
|
height="48px"
|
|
|
|
onClick={() => {
|
|
|
|
this.copyAddress('button');
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{this.state.copiedButton ? 'Address Copied!' : 'Copy Address'}
|
|
|
|
</Button>
|
|
|
|
</Row>
|
2021-04-15 15:38:51 +03:00
|
|
|
</Col>
|
2021-06-19 20:47:24 +03:00
|
|
|
)}
|
2021-04-15 15:38:51 +03:00
|
|
|
</>
|
2021-04-02 23:50:51 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|