Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: MIT
import React, { Component } from 'react';
import { defaultAccount$ } from '@parity/light.js';
import { fromWei, toWei } from '@parity/api/lib/util/wei';
import { inject, observer } from 'mobx-react';
import light from 'light-hoc';
import { Link } from 'react-router-dom';
import TokenBalance from '../TokenBalance';
const MAX_GAS_PRICE = 40; // In Gwei
const MIN_GAS_PRICE = 3; // Safelow gas price from GasStation, in Gwei
@light({
defaultAccount: defaultAccount$
})
@inject('sendStore')
@observer
class Send extends Component {
state = {
amount: 0.01, // In Ether or in token
to: '0x00Ae02834e91810B223E54ce3f9B7875258a1747'
};
handleChangeAmount = ({ target: { value } }) =>
this.setState({ amount: value });
handleChangeGasPrice = ({ target: { value } }) =>
this.setState({ gasPrice: value });
handleChangeTo = ({ target: { value } }) => {
this.setState({ to: value }, () => {
// Estimate the gas to this address.
this.props.sendStore.estimateGas(this.state);
});
};
handleSubmit = e => {
e.preventDefault();
const { defaultAccount, history, sendStore } = this.props;
// Post a request to the transaction. There is a next step to sign this
// request.
sendStore.postTx({
from: defaultAccount,
gasPrice: toWei(gasPrice, 'shannon'), // shannon == gwei
to,
value: toWei(amount)
});
history.push('/send/signer');
};
render () {
const {
<Link to='/tokens' className='icon -close'>
Close
</Link>
}
title={<h1>Send {token.name}</h1>}
/>
<div className='window_content'>
<div className='box -padded'>
<div className='box -card'>
<TokenBalance token={token} />
<div className='box -card-drawer'>
<form className='send-form' onSubmit={this.handleSubmit}>
<fieldset className='form_fields'>
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<FormField
input={
<div>
<input
className='form_field_amount'
onChange={this.handleChangeAmount}
required
type='number'
value={amount}
/>
<nav className='form-field_nav'>
<button className='button -utility' type='button'>
Max
</button>
</nav>
</div>
}
label='Amount'
/>
<FormField
input={
<textarea
className='-sm'
onChange={this.handleChangeTo}
required
type='text'
placeholder='Recipient address'
value={to}
/>
}
label='To'
/>
<FormField
className='-range'
input={
<div>
<input
max={MAX_GAS_PRICE}
min={MIN_GAS_PRICE}
onChange={this.handleChangeGasPrice}
required
step={0.1}
type='range'
value={gasPrice}
/>
<nav className='range-nav'>
<span className='range-nav_label'>Cheap</span>
<span className='range-nav_value'>
{fromWei(
toWei(gasPrice, 'shannon').mul(estimated)
).toFixed(6)}{' '}
ETH
</span>
<span className='range-nav_label'>Fast</span>
</nav>
</div>
}
label='Gas'
/>
</fieldset>
<nav className='form-nav'>
<button className='button'>Send</button>
</nav>
</form>
</div>
</div>
);
}
}
export default Send;