Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
feat: disable inputs when rate is undefined (#156)
Browse files Browse the repository at this point in the history
* feat: disable inputs when rate is undefined
  • Loading branch information
ImmanuelSegol authored Apr 9, 2019
1 parent 974180e commit e81cf66
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/swaptab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class SwapTab extends React.Component {
super(props);

this.state = {
disabled: false,
error: false,
inputError: false,
base: 'LTC',
Expand Down Expand Up @@ -176,6 +177,11 @@ class SwapTab extends React.Component {
componentDidUpdate = (_, prevState) => {
const { base, quote, baseAmount } = this.state;

// If rate if undefined disable input
if (this.state.rate !== prevState.rate) {
this.noRateAvailable();
}

// Update the rate if the request finished or the currencies changed
if (
prevState.base !== this.state.base ||
Expand Down Expand Up @@ -266,6 +272,12 @@ class SwapTab extends React.Component {
this.setState({ base, quote, error: false, errorMessage: '' });
};

noRateAvailable = () => {
this.state.rate
? this.setState({ disabled: false })
: this.setState({ disabled: true });
};

updateBaseAmount = quoteAmount => {
const { rate } = this.state.rate;

Expand Down Expand Up @@ -360,6 +372,7 @@ class SwapTab extends React.Component {
<View className={classes.select}>
<Text text="You send:" className={classes.text} />
<Input
disable={this.state.disabled}
className={classes.inputMobile}
min={minAmount}
max={maxAmount}
Expand Down Expand Up @@ -389,6 +402,7 @@ class SwapTab extends React.Component {
<View className={classes.select}>
<Text text="You receive:" className={classes.text} />
<Input
disable={this.state.disabled}
className={classes.inputMobile}
min={1 / decimals}
max={Number.MAX_SAFE_INTEGER}
Expand Down

0 comments on commit e81cf66

Please sign in to comment.