From b6b0441a6546622062693428c9b2276d91ced5b0 Mon Sep 17 00:00:00 2001
From: ImmanuelSegol <3ditds@gmail.com>
Date: Sat, 2 Feb 2019 18:02:46 +0200
Subject: [PATCH 1/2] feat: more versatile errors on homepage
---
src/components/swaptab/index.js | 53 ++++++++++++++++++++++++++-------
1 file changed, 42 insertions(+), 11 deletions(-)
diff --git a/src/components/swaptab/index.js b/src/components/swaptab/index.js
index 3766d8f..519bb54 100644
--- a/src/components/swaptab/index.js
+++ b/src/components/swaptab/index.js
@@ -87,10 +87,12 @@ class SwapTab extends React.Component {
this.state = {
error: false,
+ inputError: false,
base: 'LTC',
quote: 'BTC ⚡',
baseAmount: MIN,
quoteAmount: 0,
+ errorMessage: '',
};
}
@@ -167,27 +169,48 @@ class SwapTab extends React.Component {
return baseAmount <= MAX && baseAmount >= MIN;
};
+ checkValidPair = (quote, base) => {
+ if (quote === base) {
+ this.setState({
+ error: true,
+ errorMessage: 'Choose different asset',
+ });
+ return;
+ }
+
+ const pair = `${quote}/${base}`;
+ if (pair === 'BTC/LTC' || pair === 'LTC/BTC') {
+ this.setState({
+ error: true,
+ errorMessage: 'Coming soon',
+ });
+ return;
+ }
+
+ this.setState({ base, quote, error: false, errorMessage: '' });
+ };
+
updateBaseAmount = quoteAmount => {
const rate = new BigNumber(this.state.rate.rate);
const newBaseAmount = new BigNumber(quoteAmount).dividedBy(rate).toFixed(8);
- const error = !this.checkBaseAmount(newBaseAmount);
+ const inputError = !this.checkBaseAmount(newBaseAmount);
this.setState({
quoteAmount: Number.parseFloat(quoteAmount),
baseAmount: newBaseAmount,
- error,
+ inputError,
});
};
updateQuoteAmount = baseAmount => {
const rate = new BigNumber(this.state.rate.rate);
const newQuoteAmount = new BigNumber(baseAmount).times(rate).toFixed(8);
- const error = !this.checkBaseAmount(baseAmount);
+ const inputError = !this.checkBaseAmount(baseAmount);
this.setState({
quoteAmount: newQuoteAmount,
baseAmount: Number.parseFloat(baseAmount),
- error,
+ inputError,
});
};
@@ -219,7 +242,15 @@ class SwapTab extends React.Component {
render() {
const { classes, rates, currencies } = this.props;
- const { error, base, quote, baseAmount, quoteAmount } = this.state;
+ const {
+ error,
+ base,
+ quote,
+ baseAmount,
+ quoteAmount,
+ errorMessage,
+ inputError,
+ } = this.state;
return (
@@ -236,14 +267,14 @@ class SwapTab extends React.Component {
min={MIN}
max={MAX}
step={MIN}
- error={error}
+ error={inputError}
value={baseAmount}
onChange={e => this.updateQuoteAmount(e)}
/>
this.setState({ base: e })}
+ onChange={e => this.checkValidPair(quote, e)}
/>
@@ -252,23 +283,23 @@ class SwapTab extends React.Component {
min={0.00000001}
max={MAX}
step={0.00000001}
- error={error}
+ error={inputError}
value={quoteAmount}
onChange={e => this.updateBaseAmount(e)}
/>
this.setState({ quote: e })}
+ onChange={e => this.checkValidPair(e, base)}
/>
{} : () => this.shouldSubmit()}
- errorText={'Invalid amount'}
+ errorText={inputError ? 'Invalid amount' : errorMessage}
errorRender={() => {}}
/>
From 7e53b74bc8e057bc24e496f9a9a1fea7afe4f774 Mon Sep 17 00:00:00 2001
From: ImmanuelSegol <3ditds@gmail.com>
Date: Tue, 5 Feb 2019 21:00:31 +0200
Subject: [PATCH 2/2] refactor: typo
---
src/components/swaptab/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/components/swaptab/index.js b/src/components/swaptab/index.js
index 519bb54..bd8aaa6 100644
--- a/src/components/swaptab/index.js
+++ b/src/components/swaptab/index.js
@@ -173,7 +173,7 @@ class SwapTab extends React.Component {
if (quote === base) {
this.setState({
error: true,
- errorMessage: 'Choose different asset',
+ errorMessage: 'Choose a different asset',
});
return;
}