feature: add handleChangeFeeType in Send view

This commit is contained in:
George Lima 2018-12-20 14:18:45 -03:00
parent 87a86277d3
commit 150f578a86
1 changed files with 35 additions and 12 deletions

View File

@ -2,6 +2,8 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import FEES from '../constants/fees';
import { InputLabelComponent } from '../components/input-label'; import { InputLabelComponent } from '../components/input-label';
import { InputComponent } from '../components/input'; import { InputComponent } from '../components/input';
import { TextComponent } from '../components/text'; import { TextComponent } from '../components/text';
@ -76,7 +78,8 @@ type State = {
from: string, from: string,
amount: number, amount: number,
to: string, to: string,
fee: number, feeType: string | number,
fee: number | null,
memo: string, memo: string,
}; };
@ -86,7 +89,8 @@ export class SendView extends PureComponent<Props, State> {
from: '', from: '',
amount: 0, amount: 0,
to: '', to: '',
fee: 0, feeType: FEES.LOW,
fee: FEES.LOW,
memo: '', memo: '',
}; };
@ -96,9 +100,29 @@ export class SendView extends PureComponent<Props, State> {
})); }));
}; };
handleChangeFeeType = (value: string) => {
this.setState(
{
feeType: value,
fee: null,
},
() => {
if (
value === String(FEES.LOW)
|| value === String(FEES.MEDIUM)
|| value === String(FEES.HIGH)
) {
this.setState(() => ({
fee: Number(value),
}));
}
},
);
};
render() { render() {
const { const {
showFee, from, amount, to, memo, fee, showFee, from, amount, to, memo, fee, feeType,
} = this.state; } = this.state;
return ( return (
@ -157,19 +181,18 @@ export class SendView extends PureComponent<Props, State> {
type='number' type='number'
onChange={this.handleChange('fee')} onChange={this.handleChange('fee')}
value={String(fee)} value={String(fee)}
placeholder='kjnasG86431nvtsa…ks345jbhbdsDGvds' disabled={feeType !== FEES.CUSTOM}
/> />
</ColumnComponent> </ColumnComponent>
<ColumnComponent width='25%'> <ColumnComponent width='25%'>
<SelectComponent <SelectComponent
onChange={this.handleChange('from')} onChange={this.handleChangeFeeType}
value={from} value={String(feeType)}
options={[ options={Object.keys(FEES).map(cur => ({
{ label: cur.toLowerCase(),
label: 'Medium', value: String(FEES[cur]),
value: 'medium', }))}
}, placement='top'
]}
/> />
</ColumnComponent> </ColumnComponent>
</RowComponent> </RowComponent>