2017-08-23 02:57:18 -04:00
|
|
|
import React from 'react';
|
2017-08-28 14:05:38 -04:00
|
|
|
import translate, { translateRaw } from 'translations';
|
2017-08-23 02:57:18 -04:00
|
|
|
import UnitDropdown from './UnitDropdown';
|
2017-11-12 14:45:52 -05:00
|
|
|
import { Wei } from 'libs/units';
|
|
|
|
import { UnitConverter } from 'components/renderCbs';
|
2017-09-24 19:06:28 -07:00
|
|
|
interface Props {
|
2017-11-12 14:45:52 -05:00
|
|
|
decimal: number;
|
2017-09-24 19:06:28 -07:00
|
|
|
unit: string;
|
|
|
|
tokens: string[];
|
2017-11-12 14:45:52 -05:00
|
|
|
balance: number | null | Wei;
|
|
|
|
isReadOnly: boolean;
|
|
|
|
onAmountChange(value: string, unit: string): void;
|
|
|
|
onUnitChange(unit: string): void;
|
2017-09-24 19:06:28 -07:00
|
|
|
}
|
2017-06-27 02:27:55 +04:00
|
|
|
|
|
|
|
export default class AmountField extends React.Component {
|
2017-09-24 19:06:28 -07:00
|
|
|
public props: Props;
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-11-12 14:45:52 -05:00
|
|
|
get active() {
|
|
|
|
return !this.props.isReadOnly;
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public render() {
|
2017-11-12 14:45:52 -05:00
|
|
|
const { unit, balance, decimal, isReadOnly } = this.props;
|
2017-07-02 00:49:06 -05:00
|
|
|
return (
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 15:52:01 -04:00
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-xs-11">
|
2017-10-10 22:04:49 -07:00
|
|
|
<label>{translate('SEND_amount')}</label>
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 15:52:01 -04:00
|
|
|
<div className="input-group">
|
2017-11-12 14:45:52 -05:00
|
|
|
<UnitConverter decimal={decimal} onChange={this.callWithBaseUnit}>
|
|
|
|
{({ onUserInput, convertedUnit }) => (
|
|
|
|
<input
|
|
|
|
className={`form-control ${isFinite(Number(convertedUnit)) &&
|
|
|
|
Number(convertedUnit) > 0
|
|
|
|
? 'is-valid'
|
|
|
|
: 'is-invalid'}`}
|
|
|
|
type="text"
|
|
|
|
placeholder={translateRaw('SEND_amount_short')}
|
|
|
|
value={convertedUnit}
|
|
|
|
disabled={isReadOnly}
|
|
|
|
onChange={onUserInput}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</UnitConverter>
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 15:52:01 -04:00
|
|
|
<UnitDropdown
|
|
|
|
value={unit}
|
|
|
|
options={['ether'].concat(this.props.tokens)}
|
2017-11-12 14:45:52 -05:00
|
|
|
onChange={isReadOnly ? void 0 : this.onUnitChange}
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 15:52:01 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2017-11-12 14:45:52 -05:00
|
|
|
{!isReadOnly &&
|
2017-10-10 22:04:49 -07:00
|
|
|
balance && (
|
|
|
|
<span className="help-block">
|
|
|
|
<a onClick={this.onSendEverything}>
|
|
|
|
<span className="strong">
|
|
|
|
{translate('SEND_TransferTotal')}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
)}
|
2017-07-02 00:49:06 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-11-12 14:45:52 -05:00
|
|
|
public onUnitChange = (unit: string) =>
|
|
|
|
this.active && this.props.onUnitChange(unit); // thsi needs to be converted unit
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-11-12 14:45:52 -05:00
|
|
|
public callWithBaseUnit = ({ currentTarget: { value } }) =>
|
|
|
|
this.active && this.props.onAmountChange(value, this.props.unit);
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-11-12 14:45:52 -05:00
|
|
|
public onSendEverything = () =>
|
|
|
|
this.active && this.props.onAmountChange('everything', this.props.unit);
|
2017-06-27 02:27:55 +04:00
|
|
|
}
|