Commit 005538b6 authored by Hayden Adams's avatar Hayden Adams

improvements

parent 309bd109
...@@ -194,8 +194,6 @@ input[type=number]::-webkit-outer-spin-button { ...@@ -194,8 +194,6 @@ input[type=number]::-webkit-outer-spin-button {
color: white; color: white;
height: 48px; height: 48px;
transition: height .3s ease; transition: height .3s ease;
background-color: #27AE60;
background-color: #2F80ED;
cursor: pointer; cursor: pointer;
font-family: "Inter UI", sans-serif; font-family: "Inter UI", sans-serif;
} }
...@@ -228,6 +226,14 @@ input[type=number]::-webkit-outer-spin-button { ...@@ -228,6 +226,14 @@ input[type=number]::-webkit-outer-spin-button {
background-color: #ffffff; background-color: #ffffff;
} }
.red-bg{
background-color: red;
}
.blue-bg{
background-color: #2F80ED;
}
.red{ .red{
color: red; color: red;
} }
......
...@@ -47,7 +47,6 @@ import { setInputBalance, ...@@ -47,7 +47,6 @@ import { setInputBalance,
setInvestTokenBalance, setInvestTokenBalance,
setInvestEthBalance } from './actions/exchange-actions'; setInvestEthBalance } from './actions/exchange-actions';
import './App.css'; import './App.css';
import cookie from 'react-cookies'
import scrollToComponent from 'react-scroll-to-component'; import scrollToComponent from 'react-scroll-to-component';
var web3; var web3;
...@@ -432,8 +431,10 @@ class App extends Component { ...@@ -432,8 +431,10 @@ class App extends Component {
symbolToExchangeAddress={this.symbolToExchangeAddress} symbolToExchangeAddress={this.symbolToExchangeAddress}
/> />
<SharePurchase <SharePurchase
symbolToTokenContract={this.symbolToTokenContract}
symbolToExchangeContract={this.symbolToExchangeContract} symbolToExchangeContract={this.symbolToExchangeContract}
symbolToTokenAddress={this.symbolToTokenAddress} symbolToTokenAddress={this.symbolToTokenAddress}
symbolToExchangeAddress={this.symbolToExchangeAddress}
/> />
<About toggleAbout={this.toggleAbout} location={this}/> <About toggleAbout={this.toggleAbout} location={this}/>
{//<Transactions transactions={this.state.transactions} interaction={this.props.web3Store.interaction} /> {//<Transactions transactions={this.state.transactions} interaction={this.props.web3Store.interaction} />
......
...@@ -57,7 +57,7 @@ export const setEthPool2 = (ethPool2) => ({ ...@@ -57,7 +57,7 @@ export const setEthPool2 = (ethPool2) => ({
}); });
export const setTokenPool1 = (tokenPool1) => ({ export const setTokenPool1 = (tokenPool1) => ({
type: SET_TOKEN_POOL_2, type: SET_TOKEN_POOL_1,
tokenPool1 tokenPool1
}); });
......
...@@ -79,7 +79,6 @@ export const setBlockTimestamp = () => { ...@@ -79,7 +79,6 @@ export const setBlockTimestamp = () => {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const { web3 } = getState().web3Store; const { web3 } = getState().web3Store;
await web3.eth.getBlock('latest', (error, blockInfo) => { await web3.eth.getBlock('latest', (error, blockInfo) => {
console.log(blockInfo.timestamp, 'BLOCKTIMESTAMP');
dispatch({ dispatch({
type: SET_BLOCK_TIMESTAMP, type: SET_BLOCK_TIMESTAMP,
timestamp: blockInfo.timestamp timestamp: blockInfo.timestamp
......
...@@ -113,7 +113,6 @@ class Invest extends Component { ...@@ -113,7 +113,6 @@ class Invest extends Component {
}) //Transaction Submitted to blockchain }) //Transaction Submitted to blockchain
.on('confirmation', (confirmationNumber, receipt) => {console.log("Block Confirmations: " + confirmationNumber)}) //Transaction Mined .on('confirmation', (confirmationNumber, receipt) => {console.log("Block Confirmations: " + confirmationNumber)}) //Transaction Mined
.on('error', console.error); .on('error', console.error);
} }
render () { render () {
...@@ -153,11 +152,6 @@ class Invest extends Component { ...@@ -153,11 +152,6 @@ class Invest extends Component {
<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{(this.props.exchange.investEthBalance/10**18).toFixed(5)} ETH </p> <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{(this.props.exchange.investEthBalance/10**18).toFixed(5)} ETH </p>
<p> {(this.props.exchange.investTokenBalance/10**18).toFixed(5)} {this.props.exchange.investToken.value} </p> <p> {(this.props.exchange.investTokenBalance/10**18).toFixed(5)} {this.props.exchange.investToken.value} </p>
</div> </div>
<div className="investValue border pa2 grey-bg connection">
<p> Allowance: </p>
<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{(this.props.exchange.investTokenAllowance/10**18).toFixed(5)} {this.props.exchange.investToken.value} </p>
<a className="f-a" onClick={() => this.approveInvestAllowance()}>Approve </a>
</div>
</section> </section>
) )
......
...@@ -14,7 +14,6 @@ class Links extends Component { ...@@ -14,7 +14,6 @@ class Links extends Component {
</a> </a>
</section> </section>
<Invest <Invest
toggled={this.props.web3Store.investToggle}
token={this.props.exchange.investToken} token={this.props.exchange.investToken}
symbolToTokenContract={this.props.symbolToTokenContract} symbolToTokenContract={this.props.symbolToTokenContract}
symbolToExchangeContract={this.props.symbolToExchangeContract} symbolToExchangeContract={this.props.symbolToExchangeContract}
......
...@@ -107,7 +107,7 @@ class Purchase extends Component { ...@@ -107,7 +107,7 @@ class Purchase extends Component {
render() { render() {
if (this.props.web3Store.interaction === 'input') { if (this.props.web3Store.interaction === 'input') {
return ( return (
<a className="swap border pa2" role="button" onClick={() => {this.purchaseTokens()}}> <a className="swap border pa2 blue-bg" role="button" onClick={() => {this.purchaseTokens()}}>
<b>{"I want to swap " + this.props.exchange.inputValue + " " + this.props.exchange.inputToken.value + " for " + (this.props.exchange.outputValue/10**18).toFixed(4) + " " + this.props.exchange.outputToken.value}</b> <b>{"I want to swap " + this.props.exchange.inputValue + " " + this.props.exchange.inputToken.value + " for " + (this.props.exchange.outputValue/10**18).toFixed(4) + " " + this.props.exchange.outputToken.value}</b>
</a> </a>
) )
......
...@@ -14,7 +14,6 @@ class Purchase extends Component { ...@@ -14,7 +14,6 @@ class Purchase extends Component {
} }
} }
buyShares = () => { buyShares = () => {
var exchange = this.props.symbolToExchangeContract(this.props.exchange.investToken.value); var exchange = this.props.symbolToExchangeContract(this.props.exchange.investToken.value);
var minShares = 1; var minShares = 1;
...@@ -61,31 +60,62 @@ class Purchase extends Component { ...@@ -61,31 +60,62 @@ class Purchase extends Component {
.on('error', console.error); .on('error', console.error);
} }
buyOrSell = (input) => { approveInvestAllowance = () => {
if(input) { var symbol = this.props.exchange.investToken.value;
return 'buy' var token = this.props.symbolToTokenContract(symbol);
} else { var exchangeAddress = this.props.symbolToExchangeAddress(symbol);
return 'sell' var amount = this.props.web3Store.web3.utils.toWei('100000');
} var gasCost = this.props.web3Store.web3.utils.toWei('25', 'gwei')
token.methods.approve(exchangeAddress, amount).send({from: this.props.web3Store.currentMaskAddress, gasPrice: gasCost})
.on('transactionHash', console.log('Transaction Hash created'))
.on('receipt', (receipt) => {
console.log(receipt)
this.props.setAllowanceApprovalState(true);
}) //Transaction Submitted to blockchain
.on('confirmation', (confirmationNumber, receipt) => {console.log("Block Confirmations: " + confirmationNumber)}) //Transaction Mined
.on('error', console.error);
} }
render() { render() {
if (this.props.exchange.investEthRequired > 0) { if (this.props.exchange.investToken.value == "ETH") {
// fix later return (<a className="swap grey-bg hidden border pa2"></a>)
if (!this.props.exchange.investChecked && 1 === 0) { } else if(this.props.web3Store.investToggle == true && this.props.exchange.investSharesInput > 0) {
if(this.props.exchange.investTokenAllowance == 0) {
return (
<div className="swap border pa2 blue-bg" role="button" onClick={() => {this.approveInvestAllowance()}}>
<b><p>Click to approve {this.props.exchange.investToken.value} spending</p></b>
</div>
)
} else if(this.props.exchange.investChecked) {
if(this.props.exchange.investEthRequired > this.props.exchange.investEthBalance) {
return (
<div className="swap border pa2 red-bg">
<b><p>You can't afford to invest {(this.props.exchange.investEthRequired/10**18).toFixed(4)} ETH and {(this.props.exchange.investTokensRequired/10**18).toFixed(4)} {this.props.exchange.investToken.value} for {this.props.exchange.investSharesInput} shares</p></b>
</div>
)
} else {
return ( return (
<p className="swap border pa2"> <a className="swap border pa2 blue-bg" role="button" onClick={() => {this.buyOrSellShares()}}>
<b>Not enough shares!</b> <b>I want to invest {(this.props.exchange.investEthRequired/10**18).toFixed(4)} ETH and {(this.props.exchange.investTokensRequired/10**18).toFixed(4)} {this.props.exchange.investToken.value} for {this.props.exchange.investSharesInput} shares</b>
</p> </a>
) )
}
} else { } else {
if(this.props.exchange.investSharesInput > this.props.exchange.userShares) {
return ( return (
<a className="swap border pa2" role="button" onClick={() => {this.buyOrSellShares()}}> <a className="swap border pa2 red-bg">
<b>I want to {this.buyOrSell(this.props.exchange.investChecked)} {this.props.exchange.investSharesInput} shares for {(this.props.exchange.investEthRequired/10**18).toFixed(4)} ETH and {(this.props.exchange.investTokensRequired/10**18).toFixed(4)} {this.props.exchange.investToken.value}</b> <b>You do not have {this.props.exchange.investSharesInput} shares.</b>
</a>
)
} else {
return (
<a className="swap border pa2 blue-bg" role="button" onClick={() => {this.buyOrSellShares()}}>
<b>{this.props.exchange.investSharesInput > this.props.exchange.userShares} I want to divest {(this.props.exchange.investEthRequired/10**18).toFixed(4)} ETH and {(this.props.exchange.investTokensRequired/10**18).toFixed(4)} {this.props.exchange.investToken.value} for {this.props.exchange.investSharesInput} shares</b>
</a> </a>
) )
} }
}
} else { } else {
return (<a className="swap grey-bg hidden border pa2"></a>) return (<a className="swap grey-bg hidden border pa2"></a>)
} }
......
...@@ -32,8 +32,6 @@ export default (state = {}, action) => { ...@@ -32,8 +32,6 @@ export default (state = {}, action) => {
outputBalance, outputBalance,
inputToken, inputToken,
outputToken, outputToken,
invariant1,
invariant2,
ethPool1, ethPool1,
ethPool2, ethPool2,
tokenPool1, tokenPool1,
...@@ -44,7 +42,6 @@ export default (state = {}, action) => { ...@@ -44,7 +42,6 @@ export default (state = {}, action) => {
rate, rate,
fee, fee,
investToken, investToken,
investInvariant,
investEthPool, investEthPool,
investTokenPool, investTokenPool,
investShares, investShares,
......
...@@ -3,7 +3,7 @@ import { ...@@ -3,7 +3,7 @@ import {
} from '../constants' } from '../constants'
export default (state = {}, action) => { export default (state = {}, action) => {
const { contract, payload } = action; const { payload } = action;
switch(action.type) { switch(action.type) {
case EXCHANGE_CONTRACT_READY: case EXCHANGE_CONTRACT_READY:
return Object.assign({}, state, payload ) return Object.assign({}, state, payload )
......
...@@ -3,7 +3,7 @@ import { ...@@ -3,7 +3,7 @@ import {
} from '../constants'; } from '../constants';
export default (state = {}, action) => { export default (state = {}, action) => {
const { contract, payload } = action; const { payload } = action;
switch(action.type) { switch(action.type) {
case TOKEN_CONTRACT_READY: case TOKEN_CONTRACT_READY:
return Object.assign({}, state, payload ) return Object.assign({}, state, payload )
......
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