Commit c41926db authored by Hayden Adams's avatar Hayden Adams

fix min value bug

parent 64710cae
...@@ -94,6 +94,7 @@ class Exchange extends Component { ...@@ -94,6 +94,7 @@ class Exchange extends Component {
this.props.setExchangeRate(buyRate); this.props.setExchangeRate(buyRate);
this.props.setExchangeFee(exchangeFee); this.props.setExchangeFee(exchangeFee);
this.props.setExchangeOutputValue(tokensOut); this.props.setExchangeOutputValue(tokensOut);
console.log('ethToTokenRate', buyRate);
} }
tokenToEthRate = (tokenInput) => { tokenToEthRate = (tokenInput) => {
......
...@@ -17,13 +17,17 @@ class Purchase extends Component { ...@@ -17,13 +17,17 @@ class Purchase extends Component {
} }
ethToTokenPurchase = () => { ethToTokenPurchase = () => {
// console.log('symbol: ', this.props.exchange.outputToken.value);
var exchange = this.props.symbolToExchangeContract(this.props.exchange.outputToken.value); var exchange = this.props.symbolToExchangeContract(this.props.exchange.outputToken.value);
var minTokens = this.props.exchange.outputValue.toString(); // console.log('exchange: ', exchange);
var minTokensInt = parseInt(minTokens, 10).toString(); var estimatedTokens = this.props.exchange.outputValue
var minTokensInt = parseInt((estimatedTokens*0.9), 10).toString();
var ethSold = this.props.exchange.inputValue; var ethSold = this.props.exchange.inputValue;
var weiSold = this.props.web3Store.web3.utils.toWei(ethSold); var weiSold = this.props.web3Store.web3.utils.toWei(ethSold);
var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins
// console.log(minTokensInt, weiSold, timeout); // console.log('minTokensInt: ', minTokensInt);
// console.log('weiSold: ', weiSold);
// console.log('timeout: ', timeout);
exchange.methods.ethToTokenSwap(minTokensInt, timeout).send({from: this.props.web3Store.currentMaskAddress, value: weiSold}) exchange.methods.ethToTokenSwap(minTokensInt, timeout).send({from: this.props.web3Store.currentMaskAddress, value: weiSold})
.on('transactionHash', (result) => { .on('transactionHash', (result) => {
...@@ -52,8 +56,8 @@ class Purchase extends Component { ...@@ -52,8 +56,8 @@ class Purchase extends Component {
tokenToEthPurchase = () => { tokenToEthPurchase = () => {
var exchange = this.props.symbolToExchangeContract(this.props.exchange.inputToken.value); var exchange = this.props.symbolToExchangeContract(this.props.exchange.inputToken.value);
var minEth = this.props.exchange.outputValue.toString(); var estimatedEth = this.props.exchange.outputValue
var minEthInt = parseInt(minEth, 10).toString(); var minEthInt = parseInt((estimatedEth*0.9), 10).toString();
var tokensSold = this.props.exchange.inputValue; var tokensSold = this.props.exchange.inputValue;
// toWei needs to be replaced with *decimals // toWei needs to be replaced with *decimals
var tokensSoldInt = this.props.web3Store.web3.utils.toWei(tokensSold); var tokensSoldInt = this.props.web3Store.web3.utils.toWei(tokensSold);
...@@ -78,8 +82,8 @@ class Purchase extends Component { ...@@ -78,8 +82,8 @@ class Purchase extends Component {
tokenToTokenPurchase = () => { tokenToTokenPurchase = () => {
var exchange = this.props.symbolToExchangeContract(this.props.exchange.inputToken.value); var exchange = this.props.symbolToExchangeContract(this.props.exchange.inputToken.value);
var tokenOutAddress = this.props.symbolToTokenAddress(this.props.exchange.outputToken.value); var tokenOutAddress = this.props.symbolToTokenAddress(this.props.exchange.outputToken.value);
var minTokens = this.props.exchange.outputValue.toString(); var estimatedTokens = this.props.exchange.outputValue;
var minTokensInt = parseInt(minTokens, 10).toString(); var minTokensInt = parseInt((estimatedTokens*0.9), 10).toString();
var tokensSold = this.props.exchange.inputValue; var tokensSold = this.props.exchange.inputValue;
var tokensSoldInt = this.props.web3Store.web3.utils.toWei(tokensSold); var tokensSoldInt = this.props.web3Store.web3.utils.toWei(tokensSold);
var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins
......
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