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-02 23:50:51 +03:00
|
|
|
function currencyFormat(sats, conversion, denomination) {
|
|
|
|
let val;
|
|
|
|
let text;
|
|
|
|
switch (denomination) {
|
|
|
|
case "USD":
|
|
|
|
case "CAD":
|
|
|
|
val = sats * 0.00000001 * conversion[denomination]
|
|
|
|
text = '$' + val.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
|
|
|
|
break;
|
|
|
|
case "BTC":
|
|
|
|
val = sats * 0.00000001;
|
|
|
|
text = 'BTC ' + val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Balance extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
conversion: {
|
|
|
|
USD: 50000,
|
|
|
|
CAD: 70000,
|
|
|
|
BTC: 1,
|
|
|
|
},
|
2021-04-07 20:10:39 +03:00
|
|
|
denomination: "USD",
|
2021-04-14 19:56:01 +03:00
|
|
|
sending: false,
|
2021-04-02 23:50:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 15:00:17 +03:00
|
|
|
componentDidMount() {
|
|
|
|
fetch('https://blockchain.info/tobtc?currency=USD&value=1')
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(n => {
|
|
|
|
this.setState({conversion: {USD: 1/n, CAD: 70000, BTC: 1}});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-02 23:50:51 +03:00
|
|
|
|
|
|
|
render() {
|
2021-04-16 17:11:03 +03:00
|
|
|
const sats = (this.props.state.balance || 0);
|
2021-04-02 23:50:51 +03:00
|
|
|
const value = currencyFormat(sats, this.state.conversion, this.state.denomination);
|
2021-04-16 17:11:03 +03:00
|
|
|
const sendDisabled = (sats === 0);
|
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
|
|
|
|
api={api}
|
|
|
|
value={value}
|
|
|
|
denomination={this.state.denomination}
|
|
|
|
sats={sats}
|
|
|
|
conversion={this.state.conversion}
|
|
|
|
stopSending={() => {this.setState({sending: false})}}
|
|
|
|
/> :
|
2021-04-15 15:38:51 +03:00
|
|
|
<Col
|
|
|
|
height="400px"
|
|
|
|
width='100%'
|
|
|
|
backgroundColor="white"
|
|
|
|
borderRadius="32px"
|
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>
|
|
|
|
<Text color="lighterGray" fontSize="14px">bc1qxy...hx0wlh</Text>
|
|
|
|
<Row>
|
|
|
|
<Icon icon="ChevronDouble" color="orange" pt="2px"/>
|
|
|
|
<Text color="orange" fontSize={1}>{this.state.denomination}</Text>
|
|
|
|
</Row>
|
|
|
|
</Row>
|
|
|
|
<Col justifyContent="center" alignItems="center" mt="100px" mb="100px">
|
|
|
|
<Text fontSize="52px" color="orange">{value}</Text>
|
|
|
|
<Text fontSize={1} color="orange">{sats} sats</Text>
|
|
|
|
</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"
|
|
|
|
py="24px"
|
|
|
|
px="24px"
|
|
|
|
onClick={() => this.setState({sending: true})}
|
|
|
|
/>
|
|
|
|
<Button children="Copy Address" mr={3}
|
|
|
|
fontSize={1}
|
|
|
|
fontWeight="bold"
|
|
|
|
color="orange"
|
|
|
|
backgroundColor="midOrange"
|
2021-04-16 17:11:03 +03:00
|
|
|
style={{cursor:"pointer"}}
|
2021-04-12 19:24:27 +03:00
|
|
|
borderColor="none"
|
|
|
|
borderRadius="24px"
|
|
|
|
py="24px"
|
|
|
|
px="24px"
|
|
|
|
/>
|
|
|
|
</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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|