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-11-28 07:39:01 +03:00
|
|
|
import * as Events from "~/common/custom-events";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-11-30 08:24:22 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
|
|
|
const STYLES_FOCUS = css`
|
|
|
|
font-size: ${Constants.typescale.lvl1};
|
2020-07-02 11:24:14 +03:00
|
|
|
font-family: ${Constants.font.medium};
|
2020-04-09 00:29:13 +03:00
|
|
|
overflow-wrap: break-word;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
strong {
|
2020-07-02 11:24:14 +03:00
|
|
|
font-family: ${Constants.font.semiBold};
|
2020-04-09 00:29:13 +03:00
|
|
|
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: "",
|
2020-04-09 00:29:13 +03:00
|
|
|
};
|
|
|
|
|
2020-07-27 06:20:34 +03:00
|
|
|
_handleSubmit = async () => {
|
|
|
|
this.setState({ loading: true });
|
2020-06-04 09:26:20 +03:00
|
|
|
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-11-28 07:39:01 +03:00
|
|
|
Events.dispatchMessage({
|
|
|
|
message:
|
|
|
|
"You cannot send funds from an address to itself. Please enter a different address",
|
2020-09-12 01:25:33 +03:00
|
|
|
});
|
2020-07-27 06:20:34 +03:00
|
|
|
|
|
|
|
this.setState({ loading: false });
|
2020-06-04 09:26:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-20 07:03:30 +03:00
|
|
|
await Actions.sendFilecoin({
|
2020-06-04 09:26:20 +03:00
|
|
|
source: currentAddress.address,
|
|
|
|
target: this.state.address,
|
|
|
|
amount: this.state.amount,
|
|
|
|
});
|
2020-11-20 07:03:30 +03:00
|
|
|
this.props.onCancel();
|
2020-07-27 06:20:34 +03:00
|
|
|
|
|
|
|
this.setState({ loading: false });
|
2020-04-09 00:29:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
_handleCancel = () => {
|
|
|
|
this.props.onCancel();
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleChange = (e) => {
|
|
|
|
this.setState({ [e.target.name]: e.target.value });
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2021-07-07 23:50:57 +03:00
|
|
|
<System.P1
|
2020-09-08 02:28:50 +03:00
|
|
|
style={{
|
|
|
|
fontFamily: Constants.font.semiBold,
|
|
|
|
fontSize: Constants.typescale.lvl3,
|
|
|
|
}}
|
|
|
|
>
|
2020-06-17 21:05:13 +03:00
|
|
|
Send Filecoin
|
2021-07-07 23:50:57 +03:00
|
|
|
</System.P1>
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-07-05 09:13:13 +03:00
|
|
|
<System.SelectMenu
|
|
|
|
full
|
2020-04-09 00:29:13 +03:00
|
|
|
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}
|
2020-07-16 05:45:23 +03:00
|
|
|
/>
|
2020-04-09 00:29:13 +03:00
|
|
|
|
|
|
|
<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"
|
2020-04-09 00:29:13 +03:00
|
|
|
value={this.state.amount}
|
|
|
|
onChange={this._handleChange}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div css={STYLES_ITEM}>
|
2020-06-08 09:45:53 +03:00
|
|
|
<div css={STYLES_FOCUS}>0 FIL</div>
|
2020-04-09 00:29:13 +03:00
|
|
|
<div css={STYLES_SUBTEXT}>Transaction Fee</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={STYLES_ITEM}>
|
2020-11-04 20:55:48 +03:00
|
|
|
<div css={STYLES_FOCUS}>{Strings.formatNumber(this.state.amount)}</div>
|
2020-04-09 00:29:13 +03:00
|
|
|
<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}
|
2020-07-27 06:20:34 +03:00
|
|
|
loading={this.state.loading}
|
2020-06-17 21:05:13 +03:00
|
|
|
>
|
2020-04-09 00:29:13 +03:00
|
|
|
Send
|
2020-08-02 22:17:13 +03:00
|
|
|
</System.ButtonPrimary>
|
2020-07-27 06:20:34 +03:00
|
|
|
|
2020-11-04 20:55:48 +03:00
|
|
|
<System.ButtonSecondary full style={{ marginTop: 16 }} onClick={this._handleCancel}>
|
2020-07-27 06:20:34 +03:00
|
|
|
Cancel
|
2020-08-02 22:17:13 +03:00
|
|
|
</System.ButtonSecondary>
|
2020-04-09 00:29:13 +03:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|