2021-04-02 23:50:51 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Icon,
|
|
|
|
Row,
|
|
|
|
Text,
|
|
|
|
Button,
|
|
|
|
Col,
|
|
|
|
} from '@tlon/indigo-react';
|
|
|
|
|
2021-04-12 19:24:27 +03:00
|
|
|
import Send from './send.js'
|
2021-04-20 08:02:56 +03:00
|
|
|
import CurrencyPicker from './currencyPicker.js'
|
|
|
|
import { currencyToSats, satsToCurrency } from '../../lib/util.js';
|
2021-04-12 19:24:27 +03:00
|
|
|
|
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-04-02 23:50:51 +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-04-20 05:45:34 +03:00
|
|
|
this.props.api.btcWalletCommand({'gen-new-address': null});
|
2021-05-21 20:32:15 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2021-04-20 05:45:34 +03:00
|
|
|
}
|
|
|
|
|
2021-04-02 23:50:51 +03:00
|
|
|
|
|
|
|
render() {
|
2021-04-26 17:46:44 +03:00
|
|
|
const sats = (this.props.state.confirmedBalance || 0);
|
|
|
|
const unconfirmedSats = this.props.state.unconfirmedBalance;
|
|
|
|
|
|
|
|
const unconfirmedString = unconfirmedSats ? ` (${unconfirmedSats}) ` : '';
|
|
|
|
|
2021-04-20 08:02:56 +03:00
|
|
|
const denomination = this.props.state.denomination;
|
|
|
|
const value = satsToCurrency(sats, denomination, this.props.state.currencyRates);
|
2021-04-16 17:11:03 +03:00
|
|
|
const sendDisabled = (sats === 0);
|
2021-04-20 05:45:34 +03:00
|
|
|
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-04-12 19:24:27 +03:00
|
|
|
{this.state.sending ?
|
|
|
|
<Send
|
2021-05-26 22:19:33 +03:00
|
|
|
state={this.props.state}
|
2021-04-12 19:24:27 +03:00
|
|
|
api={api}
|
2021-04-20 15:45:29 +03:00
|
|
|
psbt={this.props.state.psbt}
|
2021-06-04 00:28:12 +03:00
|
|
|
fee={this.props.state.fee}
|
2021-04-22 16:53:13 +03:00
|
|
|
currencyRates={this.props.state.currencyRates}
|
2021-04-20 05:45:34 +03:00
|
|
|
shipWallets={this.props.state.shipWallets}
|
2021-04-12 19:24:27 +03:00
|
|
|
value={value}
|
2021-04-20 08:02:56 +03:00
|
|
|
denomination={denomination}
|
2021-04-12 19:24:27 +03:00
|
|
|
sats={sats}
|
2021-04-20 08:02:56 +03:00
|
|
|
conversion={conversion}
|
2021-04-23 23:18:20 +03:00
|
|
|
network={this.props.network}
|
2021-05-12 17:06:18 +03:00
|
|
|
error={this.props.state.error}
|
2021-04-22 15:54:31 +03:00
|
|
|
stopSending={() => {
|
|
|
|
this.setState({sending: false});
|
2021-05-26 22:19:33 +03:00
|
|
|
store.handleEvent({data: {psbt: '', fee: 0, error: '', "broadcast-fail": null}});
|
2021-04-22 15:54:31 +03:00
|
|
|
}}
|
2021-04-12 19:24:27 +03:00
|
|
|
/> :
|
2021-04-15 15:38:51 +03:00
|
|
|
<Col
|
|
|
|
height="400px"
|
|
|
|
width='100%'
|
|
|
|
backgroundColor="white"
|
2021-04-26 08:55:51 +03:00
|
|
|
borderRadius="48px"
|
2021-04-16 17:11:03 +03:00
|
|
|
justifyContent="space-between"
|
2021-04-15 15:38:51 +03:00
|
|
|
mb={5}
|
|
|
|
p={5}
|
|
|
|
>
|
2021-04-12 19:24:27 +03:00
|
|
|
<Row justifyContent="space-between">
|
|
|
|
<Text color="orange" fontSize={1}>Balance</Text>
|
2021-05-21 20:32:15 +03:00
|
|
|
<Text color="lightGray" fontSize="14px" mono style={{cursor: "pointer"}}
|
|
|
|
onClick={() => {this.copyAddress('string')}}>
|
|
|
|
{this.state.copiedString ? "copied" : addressText}
|
|
|
|
</Text>
|
2021-04-20 08:02:56 +03:00
|
|
|
<CurrencyPicker
|
2021-05-21 23:02:26 +03:00
|
|
|
api={this.props.api}
|
2021-04-20 08:02:56 +03:00
|
|
|
denomination={denomination}
|
|
|
|
currencies={this.props.state.currencyRates}
|
|
|
|
/>
|
2021-04-12 19:24:27 +03:00
|
|
|
</Row>
|
2021-04-20 05:45:34 +03:00
|
|
|
<Col justifyContent="center" alignItems="center">
|
2021-05-21 23:02:26 +03:00
|
|
|
<Text fontSize="40px" color="orange" style={{whiteSpace: "nowrap"}} >
|
|
|
|
{value}
|
|
|
|
</Text>
|
2021-04-26 17:46:44 +03:00
|
|
|
<Text fontSize={1} color="orange">{`${sats}${unconfirmedString} sats`}</Text>
|
2021-04-12 19:24:27 +03:00
|
|
|
</Col>
|
|
|
|
<Row flexDirection="row-reverse">
|
|
|
|
<Button children="Send"
|
2021-04-16 17:11:03 +03:00
|
|
|
disabled={sendDisabled}
|
2021-04-12 19:24:27 +03:00
|
|
|
fontSize={1}
|
|
|
|
fontWeight="bold"
|
2021-04-16 17:11:03 +03:00
|
|
|
color={sendDisabled ? "lighterGray" : "white"}
|
|
|
|
backgroundColor={sendDisabled ? "veryLightGray" : "orange"}
|
|
|
|
style={{cursor: sendDisabled ? "default" : "pointer" }}
|
2021-04-12 19:24:27 +03:00
|
|
|
borderColor="none"
|
|
|
|
borderRadius="24px"
|
2021-06-15 14:01:49 +03:00
|
|
|
height="48px"
|
2021-04-12 19:24:27 +03:00
|
|
|
onClick={() => this.setState({sending: true})}
|
|
|
|
/>
|
2021-05-21 20:32:15 +03:00
|
|
|
<Button children={(this.state.copiedButton) ? "Address Copied!" : "Copy Address"}
|
2021-04-20 05:45:34 +03:00
|
|
|
mr={3}
|
2021-05-21 20:32:15 +03:00
|
|
|
disabled={this.state.copiedButton}
|
2021-04-12 19:24:27 +03:00
|
|
|
fontSize={1}
|
|
|
|
fontWeight="bold"
|
2021-05-21 20:32:15 +03:00
|
|
|
color={(this.state.copiedButton) ? "green" : "orange"}
|
|
|
|
backgroundColor={(this.state.copiedButton) ? "veryLightGreen" : "midOrange" }
|
|
|
|
style={{cursor: (this.state.copiedButton) ? "default" : "pointer"}}
|
2021-04-12 19:24:27 +03:00
|
|
|
borderColor="none"
|
|
|
|
borderRadius="24px"
|
2021-06-15 14:01:49 +03:00
|
|
|
height="48px"
|
2021-05-21 20:32:15 +03:00
|
|
|
onClick={() => {this.copyAddress('button')}}
|
2021-04-12 19:24:27 +03:00
|
|
|
/>
|
|
|
|
</Row>
|
2021-04-15 15:38:51 +03:00
|
|
|
</Col>
|
2021-04-12 19:24:27 +03:00
|
|
|
}
|
2021-04-15 15:38:51 +03:00
|
|
|
</>
|
2021-04-02 23:50:51 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|