slate/components/sidebars/SidebarWalletSendFunds.js

139 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-06-17 21:05:13 +03:00
import * as React from "react";
import * as Strings from "~/common/strings";
import * as Constants from "~/common/constants";
import * as System from "~/components/system";
2020-06-17 21:05:13 +03:00
import { css } from "@emotion/react";
const STYLES_FOCUS = css`
font-size: ${Constants.typescale.lvl1};
font-family: ${Constants.font.medium};
overflow-wrap: break-word;
width: 100%;
strong {
font-family: ${Constants.font.semiBold};
font-weight: 400;
}
`;
const STYLES_SUBTEXT = css`
margin-top: 8px;
font-size: 12px;
`;
const STYLES_ITEM = css`
margin-top: 16px;
`;
export default class SidebarWalletSendFunds extends React.Component {
state = {
2020-06-17 21:05:13 +03:00
address: "",
amount: "",
};
_handleSubmit = async () => {
this.setState({ loading: true });
let addresses = {};
this.props.viewer.addresses.forEach((a) => {
addresses[a.value] = a;
});
const currentAddress = addresses[this.props.selected.address];
if (currentAddress.address === this.state.address) {
2020-06-17 21:05:13 +03:00
alert(
"TODO: Proper message for not allowing poeple to send funds to the same address."
);
this.setState({ loading: false });
return;
}
await this.props.onSubmit({
2020-06-17 21:05:13 +03:00
type: "SEND_WALLET_ADDRESS_FILECOIN",
source: currentAddress.address,
target: this.state.address,
amount: this.state.amount,
});
this.setState({ loading: false });
};
_handleCancel = () => {
this.props.onCancel();
};
_handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
return (
<React.Fragment>
<System.P style={{ fontFamily: Constants.font.semiBold }}>
2020-06-17 21:05:13 +03:00
Send Filecoin
</System.P>
<System.SelectMenu
full
containerStyle={{ marginTop: 24 }}
name="address"
label="From"
value={this.props.selected.address}
category="address"
onChange={this.props.onSelectedChange}
2020-06-17 21:05:13 +03:00
options={this.props.viewer.addresses}
/>
<System.Input
containerStyle={{ marginTop: 24 }}
label="To"
name="address"
value={this.state.address}
onChange={this._handleChange}
/>
<System.Input
containerStyle={{ marginTop: 24 }}
label="Amount (Filecoin)"
name="amount"
2020-06-17 21:05:13 +03:00
type="number"
value={this.state.amount}
onChange={this._handleChange}
/>
<div css={STYLES_ITEM}>
<div css={STYLES_FOCUS}>0 FIL</div>
<div css={STYLES_SUBTEXT}>Transaction Fee</div>
</div>
<div css={STYLES_ITEM}>
2020-06-17 21:05:13 +03:00
<div css={STYLES_FOCUS}>
{Strings.formatNumber(this.state.amount)}
</div>
<div css={STYLES_SUBTEXT}>Total Filecoin</div>
</div>
2020-08-02 22:17:13 +03:00
<System.ButtonPrimary
full
2020-06-17 21:05:13 +03:00
style={{ marginTop: 48 }}
onClick={this._handleSubmit}
loading={this.state.loading}
2020-06-17 21:05:13 +03:00
>
Send
2020-08-02 22:17:13 +03:00
</System.ButtonPrimary>
2020-08-02 22:17:13 +03:00
<System.ButtonSecondary
full
style={{ marginTop: 16 }}
onClick={this._handleCancel}
>
Cancel
2020-08-02 22:17:13 +03:00
</System.ButtonSecondary>
</React.Fragment>
);
}
}