Commit ae9fa925 authored by Kenny Tran's avatar Kenny Tran

Do approvals correctly

parent d15a3cec
...@@ -210,15 +210,16 @@ class CurrencyInputPanel extends Component { ...@@ -210,15 +210,16 @@ class CurrencyInputPanel extends Component {
exchangeAddresses: { fromToken }, exchangeAddresses: { fromToken },
web3, web3,
disableUnlock, disableUnlock,
value,
} = this.props; } = this.props;
if (disableUnlock || !selectedTokenAddress || selectedTokenAddress === 'ETH') { if (disableUnlock || !selectedTokenAddress || selectedTokenAddress === 'ETH') {
return; return;
} }
const { value, decimals, label } = selectors().getApprovals(selectedTokenAddress, account, fromToken[selectedTokenAddress]); const { value: allowance, decimals, label } = selectors().getApprovals(selectedTokenAddress, account, fromToken[selectedTokenAddress]);
if (!label || value.isGreaterThan(BN(10 ** 22))) { if (!label || allowance.isGreaterThanOrEqualTo(BN(value * 10 ** decimals || 0))) {
return; return;
} }
......
...@@ -70,19 +70,19 @@ class AddLiquidity extends Component { ...@@ -70,19 +70,19 @@ class AddLiquidity extends Component {
isUnapproved() { isUnapproved() {
const { account, exchangeAddresses, selectors } = this.props; const { account, exchangeAddresses, selectors } = this.props;
const { outputCurrency } = this.state; const { outputCurrency, outputValue } = this.state;
if (!outputCurrency) { if (!outputCurrency) {
return false; return false;
} }
const { value, label } = selectors().getApprovals( const { value: allowance, label, decimals } = selectors().getApprovals(
outputCurrency, outputCurrency,
account, account,
exchangeAddresses.fromToken[outputCurrency] exchangeAddresses.fromToken[outputCurrency]
); );
if (!label || value.isLessThan(BN(10 ** 22))) { if (label && allowance.isLessThan(BN(outputValue * 10 ** decimals || 0))) {
return true; return true;
} }
...@@ -183,8 +183,8 @@ class AddLiquidity extends Component { ...@@ -183,8 +183,8 @@ class AddLiquidity extends Component {
let inputError; let inputError;
let outputError; let outputError;
let isValid = true; let isValid = true;
const inputIsZero = BN(inputValue).isEqualTo(BN(0)); const inputIsZero = BN(inputValue).isZero();
const outputIsZero = BN(outputValue).isEqualTo(BN(0)); const outputIsZero = BN(outputValue).isZero();
if (!inputValue || inputIsZero || !outputValue || outputIsZero || !inputCurrency || !outputCurrency || this.isUnapproved()) { if (!inputValue || inputIsZero || !outputValue || outputIsZero || !inputCurrency || !outputCurrency || this.isUnapproved()) {
isValid = false; isValid = false;
...@@ -259,8 +259,8 @@ class AddLiquidity extends Component { ...@@ -259,8 +259,8 @@ class AddLiquidity extends Component {
inputCurrency, inputCurrency,
outputCurrency, outputCurrency,
} = this.state; } = this.state;
const inputIsZero = BN(inputValue).isEqualTo(BN(0)); const inputIsZero = BN(inputValue).isZero();
const outputIsZero = BN(outputValue).isEqualTo(BN(0)); const outputIsZero = BN(outputValue).isZero();
if (!inputCurrency || !outputCurrency) { if (!inputCurrency || !outputCurrency) {
return ( return (
......
...@@ -74,8 +74,8 @@ class Send extends Component { ...@@ -74,8 +74,8 @@ class Send extends Component {
let outputError = ''; let outputError = '';
let isValid = true; let isValid = true;
const validRecipientAddress = web3 && web3.utils.isAddress(recipient); const validRecipientAddress = web3 && web3.utils.isAddress(recipient);
const inputIsZero = BN(inputValue).isEqualTo(BN(0)); const inputIsZero = BN(inputValue).isZero();
const outputIsZero = BN(outputValue).isEqualTo(BN(0)); const outputIsZero = BN(outputValue).isZero();
if (!inputValue || inputIsZero || !outputValue || outputIsZero || !inputCurrency || !outputCurrency || !recipient || this.isUnapproved() || !validRecipientAddress) { if (!inputValue || inputIsZero || !outputValue || outputIsZero || !inputCurrency || !outputCurrency || !recipient || this.isUnapproved() || !validRecipientAddress) {
isValid = false; isValid = false;
...@@ -100,19 +100,19 @@ class Send extends Component { ...@@ -100,19 +100,19 @@ class Send extends Component {
isUnapproved() { isUnapproved() {
const { account, exchangeAddresses, selectors } = this.props; const { account, exchangeAddresses, selectors } = this.props;
const { inputCurrency } = this.state; const { inputCurrency, inputValue } = this.state;
if (!inputCurrency || inputCurrency === 'ETH') { if (!inputCurrency || inputCurrency === 'ETH') {
return false; return false;
} }
const { value, label } = selectors().getApprovals( const { value: allowance, label, decimals } = selectors().getApprovals(
inputCurrency, inputCurrency,
account, account,
exchangeAddresses.fromToken[inputCurrency] exchangeAddresses.fromToken[inputCurrency]
); );
if (!label || value.isLessThan(BN(10 ** 22))) { if (label && allowance.isLessThan(BN(inputValue * 10 ** decimals || 0))) {
return true; return true;
} }
...@@ -128,7 +128,7 @@ class Send extends Component { ...@@ -128,7 +128,7 @@ class Send extends Component {
const editedValue = lastEditedField === INPUT ? this.state.inputValue : this.state.outputValue; const editedValue = lastEditedField === INPUT ? this.state.inputValue : this.state.outputValue;
if (BN(editedValue).isEqualTo(BN(0))) { if (BN(editedValue).isZero()) {
return; return;
} }
...@@ -500,8 +500,8 @@ class Send extends Component { ...@@ -500,8 +500,8 @@ class Send extends Component {
const { label: inputLabel } = selectors().getBalance(account, inputCurrency); const { label: inputLabel } = selectors().getBalance(account, inputCurrency);
const { label: outputLabel } = selectors().getBalance(account, outputCurrency); const { label: outputLabel } = selectors().getBalance(account, outputCurrency);
const validRecipientAddress = web3 && web3.utils.isAddress(recipient); const validRecipientAddress = web3 && web3.utils.isAddress(recipient);
const inputIsZero = BN(inputValue).isEqualTo(BN(0)); const inputIsZero = BN(inputValue).isZero();
const outputIsZero = BN(outputValue).isEqualTo(BN(0)); const outputIsZero = BN(outputValue).isZero();
let nextStepMessage; let nextStepMessage;
if (inputError || outputError) { if (inputError || outputError) {
......
...@@ -71,8 +71,8 @@ class Swap extends Component { ...@@ -71,8 +71,8 @@ class Swap extends Component {
let outputError = ''; let outputError = '';
let isValid = true; let isValid = true;
let isUnapproved = this.isUnapproved(); let isUnapproved = this.isUnapproved();
const inputIsZero = BN(inputValue).isEqualTo(BN(0)); const inputIsZero = BN(inputValue).isZero();
const outputIsZero = BN(outputValue).isEqualTo(BN(0)); const outputIsZero = BN(outputValue).isZero();
if (!inputValue || inputIsZero || !outputValue || outputIsZero || !inputCurrency || !outputCurrency || isUnapproved) { if (!inputValue || inputIsZero || !outputValue || outputIsZero || !inputCurrency || !outputCurrency || isUnapproved) {
isValid = false; isValid = false;
...@@ -97,19 +97,19 @@ class Swap extends Component { ...@@ -97,19 +97,19 @@ class Swap extends Component {
isUnapproved() { isUnapproved() {
const { account, exchangeAddresses, selectors } = this.props; const { account, exchangeAddresses, selectors } = this.props;
const { inputCurrency } = this.state; const { inputCurrency, inputValue } = this.state;
if (!inputCurrency || inputCurrency === 'ETH') { if (!inputCurrency || inputCurrency === 'ETH') {
return false; return false;
} }
const { value, label } = selectors().getApprovals( const { value: allowance, label, decmals } = selectors().getApprovals(
inputCurrency, inputCurrency,
account, account,
exchangeAddresses.fromToken[inputCurrency] exchangeAddresses.fromToken[inputCurrency]
); );
if (!label || value.isLessThan(BN(10 ** 22))) { if (label && allowance.isLessThan(BN(inputValue * 10 ** decimals || 0))) {
return true; return true;
} }
...@@ -125,7 +125,7 @@ class Swap extends Component { ...@@ -125,7 +125,7 @@ class Swap extends Component {
const editedValue = lastEditedField === INPUT ? this.state.inputValue : this.state.outputValue; const editedValue = lastEditedField === INPUT ? this.state.inputValue : this.state.outputValue;
if (BN(editedValue).isEqualTo(BN(0))) { if (BN(editedValue).isZero()) {
return; return;
} }
...@@ -483,8 +483,8 @@ class Swap extends Component { ...@@ -483,8 +483,8 @@ class Swap extends Component {
outputCurrency, outputCurrency,
} = this.state; } = this.state;
const inputIsZero = BN(inputValue).isEqualTo(BN(0)); const inputIsZero = BN(inputValue).isZero();
const outputIsZero = BN(outputValue).isEqualTo(BN(0)); const outputIsZero = BN(outputValue).isZero();
if (!inputCurrency || !outputCurrency) { if (!inputCurrency || !outputCurrency) {
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment