Commit 0a5042e0 authored by Hayden Adams's avatar Hayden Adams

random fixes and temporarily remove price graph

parent 4389c232
# Uniswap - a trustless, decentralized exchange for Ether and ERC20 tokens # Uniswap - a decentralized exchange for ERC20 tokens
Uniswap exchange uses a "Market Maker" mechanism, where liquidity providers store a reserve of ETH and ERC20 tokens within an Ethereum smart contract. An exchange rate is set between the tokens and ETH based on the relative availibility of each token. Arbitrage ensures that the rate will be the same as on other exchanges. Buyers who send Token 1 to the smart contract will receive back Token 2 at the current rate. A small fee is paid from the buyer to the liquidity providers to incentive participation. Read the Whitepaper: https://hackmd.io/C-DvwDSfSxuh-Gd4WKE_ig
A full writeup with math and whatnot will be written soon. Until then, here is some more info on Market Makers: Visit the website: https://uniswap.io/
https://www.reddit.com/r/ethereum/comments/55m04x/lets_run_onchain_decentralized_exchanges_the_way/ Read the smart contracts: https://github.com/uniswap
http://vitalik.ca/general/2017/06/22/marketmakers.html
Please reach out if you would like to get involved or support the project. Send me an email: hayden@uniswap.io
<!-- ETH Address: 0x4779721CaC18A46DbCF148f2Dd7A8E6cc1F90078 -->
Demo: https://uniswap.io/
Email: hayden@uniswap.io
ETH Address: 0x4779721CaC18A46DbCF148f2Dd7A8E6cc1F90078
This diff is collapsed.
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"dependencies": { "dependencies": {
"axios": "^0.18.0", "axios": "^0.18.0",
"d3": "^4.13.0", "d3": "^4.13.0",
"npm": "^6.0.0",
"react": "^16.2.0", "react": "^16.2.0",
"react-cookies": "^0.1.0", "react-cookies": "^0.1.0",
"react-dom": "^16.2.0", "react-dom": "^16.2.0",
......
...@@ -8,6 +8,7 @@ body{ ...@@ -8,6 +8,7 @@ body{
line-height: 1.6; line-height: 1.6;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
overflow-x: hidden;
} }
.dim input{ .dim input{
...@@ -61,12 +62,22 @@ a:hover{ ...@@ -61,12 +62,22 @@ a:hover{
align-items: center; align-items: center;
/* color: #27AE60; */ /* color: #27AE60; */
flex: 1; flex: 1;
z-index: 2;
font-family: "Inter UI", sans-serif; font-family: "Inter UI", sans-serif;
} }
.connection a{ .connection a{
/* text-decoration: none; */ /* text-decoration: none; */
/* color: #27AE60; */ /* color: #27AE60; */
padding-right: 2em;
}
.userBalance{
overflow-y: hidden;
overflow-x: scroll;
white-space: nowrap;
z-index: 10;
padding-right: 2em;
} }
.order { .order {
......
...@@ -16,15 +16,15 @@ import Links from './components/Links'; ...@@ -16,15 +16,15 @@ import Links from './components/Links';
import SharePurchase from './components/SharePurchase'; import SharePurchase from './components/SharePurchase';
//import Transactions from './components/Transactions'; //import Transactions from './components/Transactions';
// d3 // d3
import Visualization from './components/Visualization'; // import Visualization from './components/Visualization';
// enter redux // enter redux
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { subscribe } from 'redux-subscriber'; import { subscribe } from 'redux-subscriber';
// redux actions // redux actions
// import { initializeGlobalWeb3 } from './actions/global-actions'; // import { initializeGlobalWeb3 } from './actions/global-actions';
import { uniExchangeContractReady, swtExchangeContractReady, exchangeContractReady } from './actions/exchangeContract-actions'; import { exchangeContractReady } from './actions/exchangeContract-actions';
import { uniTokenContractReady, swtTokenContractReady, tokenContractReady } from './actions/tokenContract-actions'; import { tokenContractReady } from './actions/tokenContract-actions';
import { initializeGlobalWeb3, setWeb3ConnectionStatus, setCurrentMaskAddress, metamaskLocked, metamaskUnlocked, setInteractionState, factoryContractReady, toggleAbout, toggleInvest } from './actions/web3-actions'; import { initializeGlobalWeb3, setWeb3ConnectionStatus, setCurrentMaskAddress, metamaskLocked, metamaskUnlocked, setInteractionState, factoryContractReady, toggleAbout, toggleInvest } from './actions/web3-actions';
import { setInputBalance, import { setInputBalance,
setOutputBalance, setOutputBalance,
...@@ -39,6 +39,7 @@ import { setInputBalance, ...@@ -39,6 +39,7 @@ import { setInputBalance,
setInvestInvariant, setInvestInvariant,
setInvestEthPool, setInvestEthPool,
setInvestTokenPool, setInvestTokenPool,
setInvestTokenAllowance,
setInvestShares, setInvestShares,
setUserShares, setUserShares,
setInvestTokenBalance, setInvestTokenBalance,
...@@ -245,6 +246,7 @@ class App extends Component { ...@@ -245,6 +246,7 @@ class App extends Component {
getInvestInfo = () => { getInvestInfo = () => {
var exchange = this.symbolToExchangeContract(this.props.exchange.investToken.value); var exchange = this.symbolToExchangeContract(this.props.exchange.investToken.value);
var token = this.symbolToTokenContract(this.props.exchange.investToken.value); var token = this.symbolToTokenContract(this.props.exchange.investToken.value);
var exchangeAddress = this.symbolToExchangeAddress(this.props.exchange.investToken.value)
exchange.methods.invariant().call().then((result, error) => { exchange.methods.invariant().call().then((result, error) => {
this.props.setInvestInvariant(result); this.props.setInvestInvariant(result);
...@@ -270,6 +272,10 @@ class App extends Component { ...@@ -270,6 +272,10 @@ class App extends Component {
this.props.setInvestTokenBalance(balance); this.props.setInvestTokenBalance(balance);
}); });
token.methods.allowance(this.props.web3Store.currentMaskAddress, exchangeAddress).call((error, balance) => {
this.props.setInvestTokenAllowance(balance);
});
this.props.web3Store.web3.eth.getBalance(this.props.web3Store.currentMaskAddress, (error, balance) => { this.props.web3Store.web3.eth.getBalance(this.props.web3Store.currentMaskAddress, (error, balance) => {
this.props.setInvestEthBalance(balance); this.props.setInvestEthBalance(balance);
}); });
...@@ -463,12 +469,13 @@ class App extends Component { ...@@ -463,12 +469,13 @@ class App extends Component {
symbolToExchangeContract={this.symbolToExchangeContract} symbolToExchangeContract={this.symbolToExchangeContract}
symbolToTokenAddress={this.symbolToTokenAddress} symbolToTokenAddress={this.symbolToTokenAddress}
/> />
<Visualization /> {/* <Visualization /> */}
<Links <Links
toggleInvest={this.toggleInvest} toggleInvest={this.toggleInvest}
location={this} location={this}
symbolToTokenContract={this.symbolToTokenContract} symbolToTokenContract={this.symbolToTokenContract}
symbolToExchangeContract={this.symbolToExchangeContract} symbolToExchangeContract={this.symbolToExchangeContract}
symbolToExchangeAddress={this.symbolToExchangeAddress}
/> />
<SharePurchase <SharePurchase
symbolToExchangeContract={this.symbolToExchangeContract} symbolToExchangeContract={this.symbolToExchangeContract}
...@@ -497,10 +504,6 @@ const mapDispatchToProps = (dispatch) => { ...@@ -497,10 +504,6 @@ const mapDispatchToProps = (dispatch) => {
metamaskUnlocked, metamaskUnlocked,
setInteractionState, setInteractionState,
factoryContractReady, factoryContractReady,
uniExchangeContractReady,
swtExchangeContractReady,
uniTokenContractReady,
swtTokenContractReady,
setInputBalance, setInputBalance,
setOutputBalance, setOutputBalance,
setInvariant1, setInvariant1,
...@@ -518,6 +521,7 @@ const mapDispatchToProps = (dispatch) => { ...@@ -518,6 +521,7 @@ const mapDispatchToProps = (dispatch) => {
setInvestToken, setInvestToken,
setInvestEthPool, setInvestEthPool,
setInvestTokenPool, setInvestTokenPool,
setInvestTokenAllowance,
setInvestInvariant, setInvestInvariant,
setInvestShares, setInvestShares,
setUserShares, setUserShares,
......
...@@ -22,6 +22,7 @@ import { ...@@ -22,6 +22,7 @@ import {
SET_USER_SHARES, SET_USER_SHARES,
SET_INVEST_TOKEN_BALANCE, SET_INVEST_TOKEN_BALANCE,
SET_INVEST_ETH_BALANCE, SET_INVEST_ETH_BALANCE,
SET_INVEST_TOKEN_ALLOWANCE,
SET_INVEST_SHARES_INPUT, SET_INVEST_SHARES_INPUT,
SET_INVEST_ETH_REQUIRED, SET_INVEST_ETH_REQUIRED,
SET_INVEST_TOKENS_REQUIRED, SET_INVEST_TOKENS_REQUIRED,
...@@ -143,6 +144,11 @@ export const setInvestEthBalance = (investEthBalance) => ({ ...@@ -143,6 +144,11 @@ export const setInvestEthBalance = (investEthBalance) => ({
investEthBalance investEthBalance
}); });
export const setInvestTokenAllowance = (investTokenAllowance) => ({
type: SET_INVEST_TOKEN_ALLOWANCE,
investTokenAllowance
});
export const setInvestSharesInput = (investSharesInput) => ({ export const setInvestSharesInput = (investSharesInput) => ({
type: SET_INVEST_SHARES_INPUT, type: SET_INVEST_SHARES_INPUT,
investSharesInput investSharesInput
......
import { import {
UNI_EXCHANGE_CONTRACT_READY,
SWT_EXCHANGE_CONTRACT_READY,
EXCHANGE_CONTRACT_READY EXCHANGE_CONTRACT_READY
} from '../constants'; } from '../constants';
export const uniExchangeContractReady = (contract) => ({ // definitely needs to be redux thunk
type: UNI_EXCHANGE_CONTRACT_READY,
contract
});
export const swtExchangeContractReady = (contract) => ({
type: SWT_EXCHANGE_CONTRACT_READY,
contract
});
// definitely needs to be redux thunk
export const exchangeContractReady = (symbol, exchangeContract) => ({ export const exchangeContractReady = (symbol, exchangeContract) => ({
type: EXCHANGE_CONTRACT_READY, type: EXCHANGE_CONTRACT_READY,
payload: { [symbol]: exchangeContract } payload: { [symbol]: exchangeContract }
}); });
import { import {
UNI_TOKEN_CONTRACT_READY,
SWT_TOKEN_CONTRACT_READY,
TOKEN_CONTRACT_READY TOKEN_CONTRACT_READY
} from '../constants'; } from '../constants';
export const uniTokenContractReady = (contract) => ({ // again, needs to be redux thunk
type: UNI_TOKEN_CONTRACT_READY,
contract
});
export const swtTokenContractReady = (contract) => ({
type: SWT_TOKEN_CONTRACT_READY,
contract
});
// again, needs to be redux thunk
export const tokenContractReady = (symbol, tokenContract) => ({ export const tokenContractReady = (symbol, tokenContract) => ({
type: TOKEN_CONTRACT_READY, type: TOKEN_CONTRACT_READY,
payload: { [symbol]: tokenContract } payload: { [symbol]: tokenContract }
}); });
\ No newline at end of file
...@@ -4,8 +4,8 @@ function AboutMessage ({ toggled }) { ...@@ -4,8 +4,8 @@ function AboutMessage ({ toggled }) {
if (toggled === true) { if (toggled === true) {
return ( return (
<section className="expand grey-bg border pa2"> <section className="expand grey-bg border pa2">
<p>Uniswap is an automated market maker exchange capable of both ETH-to-ERC20 and ERC20-to-ERC20 trades. Anyone can become a liquidity provider, and invest in the liquidity pool of an ERC20 token. This allows other users to trade that token for other tokens at an exchange rate based on their relative availibility. When a token trade is executed, a small fee is payed to the liquidity providers that enabled the transaction, proportional to their investment.</p> <p>Read the: <a href="https://hackmd.io/C-DvwDSfSxuh-Gd4WKE_ig#Uniswap-Whitepaper-%F0%9F%A6%84">Uniswap Whitepaper</a></p>
<p>A full writeup can be found here: <a href="https://hackmd.io/Tlf08KuPTbqsHLKk5hzAvA">Uniswap Project Overview</a></p> <p>Uniswap is an automated market maker for exchanging ERC20 tokens. Anyone can become a liquidity provider, and invest in the liquidity pool of an ERC20 token. This allows other users to trade that token for other tokens at an exchange rate based on their relative availibility. When a token trade is executed, a small fee is payed to the liquidity providers that enabled the transaction.</p>
<p>Please reach out if you would like to get involved or support the project.</p> <p>Please reach out if you would like to get involved or support the project.</p>
<p><span role="img" aria-label="GitHub">⟪⟫</span> <a href="https://github.com/uniswap">github.com/uniswap</a></p> <p><span role="img" aria-label="GitHub">⟪⟫</span> <a href="https://github.com/uniswap">github.com/uniswap</a></p>
<p><span role="img" aria-label="Email">📧 </span><a href="mailto:hayden@uniswap.io">hayden@uniswap.io</a></p> <p><span role="img" aria-label="Email">📧 </span><a href="mailto:hayden@uniswap.io">hayden@uniswap.io</a></p>
......
...@@ -5,22 +5,24 @@ function ConnectionHelper(props) { ...@@ -5,22 +5,24 @@ function ConnectionHelper(props) {
if (!props.metamask) { if (!props.metamask) {
return ( return (
<div className="grey-bg connection border pa2"> <div className="grey-bg connection border pa2">
<p>Welcome! Uniswap is a decentralized exhange for ETH and ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a">How it works </a><br /><br /> <p>Welcome! Uniswap is a decentralized exhange for ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a">How it works </a><br /><br />
<b>To get started, please install <a href="https://metamask.io/">Metamask</a>.</b></p> <b>To get started, please install <a href="https://metamask.io/">Metamask</a>.</b></p>
</div> </div>
) )
} else if (props.web3Store.connected && props.web3Store.interaction === 'disconnected') { } else if (props.web3Store.connected && props.web3Store.interaction === 'disconnected') {
return ( return (
<div className="grey-bg connection border pa2"> <div className="grey-bg connection border pa2">
<p>Welcome! Uniswap is a decentralized exchange for ETH and ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a" >How it works </a><br /><br /> <p>
Looks like you aren't connected. <b>Please switch to the correct network.</b></p> Welcome! Uniswap is a decentralized exchange for ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a" >How it works </a><br /><br />
It looks like you aren't connected. <b>Please switch to the Rinkeby testnet.</b>
</p>
</div> </div>
) )
} else if (props.web3Store.metamaskLocked) { } else if (props.web3Store.metamaskLocked) {
return ( return (
<div className="grey-bg connection border pa2"> <div className="grey-bg connection border pa2">
<p>Welcome! Uniswap is a decentralized exhange platform for ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a" >How it works ↘</a><br /><br /> <p>Welcome! Uniswap is a decentralized exhange platform for ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a" >How it works ↘</a><br /><br />
Looks like you aren't connected. <b>Please unlock Metamask to continue.</b></p> It looks like you aren't connected. <b>Please unlock Metamask to continue.</b></p>
</div> </div>
) )
} else if (props.web3Store.interaction === "error1") { } else if (props.web3Store.interaction === "error1") {
...@@ -38,51 +40,35 @@ function ConnectionHelper(props) { ...@@ -38,51 +40,35 @@ function ConnectionHelper(props) {
} else if (props.exchange.inputValue > props.exchange.inputBalance/10**18 && props.exchange.inputToken.value === 'ETH') { } else if (props.exchange.inputValue > props.exchange.inputBalance/10**18 && props.exchange.inputToken.value === 'ETH') {
return ( return (
<div className="grey-bg red connection border pa2"> <div className="grey-bg red connection border pa2">
<p>This account doesn't have enough balance to make this transaction! Get more {props.exchange.inputToken.value} with the <a target="_blank" rel="noopener noreferrer" href="https://faucet.rinkeby.io/">Rinkeby Faucet.</a></p> <p>You don't have enough ETH to make this transaction! Get more at the <a target="_blank" rel="noopener noreferrer" href="https://faucet.rinkeby.io/">Rinkeby Faucet.</a></p>
</div> </div>
) )
} else if (!props.exchange.allowanceApproved && props.web3Store.exchangeType === "Token to Token") { } else if (!props.exchange.allowanceApproved && props.web3Store.exchangeType === "Token to Token") {
return ( return (
<div className="grey-bg connection border pa2"> <div className="grey-bg red connection border pa2">
<p>Our smart contract has to be approved by your address to be able to swap this token for other tokens.<br /> We set a high transfer limit for the demo (<a onClick={() => {props.toggleAbout()}} className="f-a">Why?</a>).</p> <p>Uniswap has to be approved by your address to trade {props.exchange.inputToken.value}.</p>
<p></p>
<a className="f-a" onClick={() => props.approveAllowance()}>Approve </a> <a className="f-a" onClick={() => props.approveAllowance()}>Approve </a>
</div> </div>
) )
} else if (!props.exchange.allowanceApproved && props.web3Store.exchangeType === "Token to ETH") { } else if (!props.exchange.allowanceApproved && props.web3Store.exchangeType === "Token to ETH") {
return ( return (
<div className="grey-bg connection border pa2"> <div className="grey-bg red connection border pa2">
<p>Our smart contract has to be approved by your address to be able to swap this token for ETH.<br /> We set a high transfer limit for the demo (<a onClick={() => {props.toggleAbout()}} className="f-a">Why?</a>).</p> <p>Uniswap has to be approved by your address to trade {props.exchange.inputToken.value}.</p>
<p></p>
<a className="f-a" onClick={() => props.approveAllowance()}>Approve </a> <a className="f-a" onClick={() => props.approveAllowance()}>Approve </a>
</div> </div>
) )
} else if (!props.uniAdded && props.exchange.outputToken.value === "UNI") {
return (
<div className="grey-bg connection border pa2">
<p>Welcome! Uniswap is a decentralized exhange platform for ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a" >How it works </a><br /><br />
Youll need to add the UNI tokens to Metamask. <a target="_blank" rel="noopener noreferrer" href="http://metamask.consensyssupport.happyfox.com/kb/article/4-managing-tokens">Heres a step by step guide.</a><br />
Add UNI with <a href="">0x350E5DD084ecF271e8d3531D4324443952F47756</a>.</p>
<a className="f-a" onClick={() => props.onCloseHelper()}>I've added the token</a>
</div>
)
} else if (!props.swapAdded && props.exchange.outputToken.value === "SWAP") {
return (
<div className="grey-bg connection border pa2">
<p>Welcome! Uniswap is a decentralized exhange platform for ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a" >How it works</a>.<br /><br />
You’ll need to add the SWAP tokens to Metamask. <a target="_blank" rel="noopener noreferrer" href="http://metamask.consensyssupport.happyfox.com/kb/article/4-managing-tokens">Here’s a step by step guide.</a><br />
Add UNI with <a href="">0x8B2A87F8243f23C33fb97E23a21Ae8EDB3b71AcA</a>.</p>
<a className="f-a" onClick={() => props.onCloseHelper()}>I've added the token</a>
</div>
)
} else if (props.exchange.inputValue > props.exchange.inputBalance/10**18) { } else if (props.exchange.inputValue > props.exchange.inputBalance/10**18) {
return ( return (
<div className="grey-bg red connection border pa2"> <div className="grey-bg red connection border pa2">
<p>{"This account doesn't have enough balance to make this transaction! You'll need to swap some ETH for " + props.exchange.inputToken.value + "."}</p> <p>{"You don't have enough " + props.exchange.inputToken.value + " to make this transaction. 😢 "}</p>
</div> </div>
) )
} else { } else {
return ( return (
<div className="grey-bg connection border pa2"> <div className="grey-bg connection border pa2">
<p>Welcome! Uniswap is a decentralized exhange for ETH and ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a">How it works </a><br /><br /> <p>Welcome! Uniswap is a decentralized exhange for ERC20 Tokens. <a onClick={() => {props.toggleAbout()}} className="f-a">How it works </a><br /><br />
You're connected. Enter a value below to get started.</p> You're connected. Enter a value below to get started.</p>
<p>↓</p> <p>↓</p>
</div> </div>
......
...@@ -10,6 +10,7 @@ import { setInvestToken, ...@@ -10,6 +10,7 @@ import { setInvestToken,
setInvestShares, setInvestShares,
setInvestTokenBalance, setInvestTokenBalance,
setInvestEthBalance, setInvestEthBalance,
setInvestTokenAllowance,
setInvestSharesInput, setInvestSharesInput,
setUserShares, setUserShares,
setInvestEthRequired, setInvestEthRequired,
...@@ -29,6 +30,7 @@ class Invest extends Component { ...@@ -29,6 +30,7 @@ class Invest extends Component {
this.props.setInvestEthPool(0); this.props.setInvestEthPool(0);
this.props.setInvestTokenBalance(0); this.props.setInvestTokenBalance(0);
this.props.setInvestEthBalance(0); this.props.setInvestEthBalance(0);
this.props.setInvestTokenAllowance(0);
this.props.setInvestShares(0); this.props.setInvestShares(0);
this.props.setUserShares(0); this.props.setUserShares(0);
} }
...@@ -65,20 +67,27 @@ class Invest extends Component { ...@@ -65,20 +67,27 @@ class Invest extends Component {
} }
getInvestBalance = () => { getInvestBalance = () => {
var token = this.props.symbolToTokenContract(this.props.exchange.investToken.value); var symbol = this.props.exchange.investToken.value;
var exchange = this.props.symbolToExchangeContract(this.props.exchange.investToken.value); var investor = this.props.web3Store.currentMaskAddress;
var token = this.props.symbolToTokenContract(symbol);
var exchange = this.props.symbolToExchangeContract(symbol);
var exchangeAddr = this.props.symbolToExchangeAddress(symbol);
this.props.web3Store.web3.eth.getBalance(this.props.web3Store.currentMaskAddress, (error, balance) => { this.props.web3Store.web3.eth.getBalance(investor, (error, balance) => {
this.props.setInvestEthBalance(balance); this.props.setInvestEthBalance(balance);
}); });
token.methods.balanceOf(this.props.web3Store.currentMaskAddress).call((error, balance) => { token.methods.balanceOf(investor).call((error, balance) => {
this.props.setInvestTokenBalance(balance); this.props.setInvestTokenBalance(balance);
}); });
exchange.methods.getShares(this.props.web3Store.currentMaskAddress).call().then((result, error) => { token.methods.allowance(investor, exchangeAddr).call((error, balance) => {
this.props.setInvestTokenAllowance(balance);
console.log('invest allowance: ', balance)
});
exchange.methods.getShares(investor).call().then((result, error) => {
this.props.setUserShares(result); this.props.setUserShares(result);
console.log(result);
}); });
} }
...@@ -96,6 +105,23 @@ class Invest extends Component { ...@@ -96,6 +105,23 @@ class Invest extends Component {
} }
} }
approveInvestAllowance = () => {
var symbol = this.props.exchange.investToken.value;
var token = this.props.symbolToTokenContract(symbol);
var exchangeAddress = this.props.symbolToExchangeAddress(symbol);
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.web3Store.investToggle === true) { if (this.props.web3Store.investToggle === true) {
return ( return (
...@@ -106,6 +132,7 @@ class Invest extends Component { ...@@ -106,6 +132,7 @@ class Invest extends Component {
</div> </div>
<div className="invest investValue border pa2"> <div className="invest investValue border pa2">
<p> Select token and input number of shares: &nbsp;&nbsp;&nbsp;</p> <p> Select token and input number of shares: &nbsp;&nbsp;&nbsp;</p>
<div className="investSelectToken"> <div className="investSelectToken">
<SelectToken token={this.props.exchange.investToken} onSelectToken={this.onSelectToken} /> <SelectToken token={this.props.exchange.investToken} onSelectToken={this.onSelectToken} />
<p className="investDropdown">{'<'}</p> <p className="investDropdown">{'<'}</p>
...@@ -114,8 +141,8 @@ class Invest extends Component { ...@@ -114,8 +141,8 @@ class Invest extends Component {
</div> </div>
<div className="investValue border pa2"> <div className="investValue border pa2">
<p> Total Shares: {this.props.exchange.investShares} </p> <p> Total Shares: {this.props.exchange.investShares} </p>
<p> You own: {this.props.exchange.userShares} shares </p> <p> Your shares: {this.props.exchange.userShares} </p>
<p> You get {((this.props.exchange.userShares*100)/this.props.exchange.investShares).toFixed(2)}% of fees </p> <p> Your fees {((this.props.exchange.userShares*100)/this.props.exchange.investShares).toFixed(2)}% </p>
</div> </div>
<div className="investValue border pa2"> <div className="investValue border pa2">
<p> Total Liquidity </p> <p> Total Liquidity </p>
...@@ -132,7 +159,13 @@ class Invest extends Component { ...@@ -132,7 +159,13 @@ 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>
) )
} else { } else {
return (<section className="expand grey-bg border pa2 hidden"></section>) return (<section className="expand grey-bg border pa2 hidden"></section>)
...@@ -154,6 +187,7 @@ const mapDispatchToProps = (dispatch) => { ...@@ -154,6 +187,7 @@ const mapDispatchToProps = (dispatch) => {
setInvestShares, setInvestShares,
setInvestTokenBalance, setInvestTokenBalance,
setInvestEthBalance, setInvestEthBalance,
setInvestTokenAllowance,
setInvestSharesInput, setInvestSharesInput,
setInvestEthRequired, setInvestEthRequired,
setInvestTokensRequired, setInvestTokensRequired,
......
...@@ -18,6 +18,7 @@ class Links extends Component { ...@@ -18,6 +18,7 @@ class Links extends Component {
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}
symbolToExchangeAddress={this.props.symbolToExchangeAddress}
/> />
</div> </div>
) )
......
...@@ -30,9 +30,9 @@ class NetworkStatus extends Component { ...@@ -30,9 +30,9 @@ class NetworkStatus extends Component {
if (this.props.web3Store.connected && this.props.web3Store.interaction !== 'disconnected'){ if (this.props.web3Store.connected && this.props.web3Store.interaction !== 'disconnected'){
return ( return (
<div className="connection border pa2 green"> <div className="connection border pa2 green">
<p className="userBalance">{this.props.exchange.inputToken.value + ": " + (this.props.exchange.inputBalance/10**18).toFixed(2)}</p>
<p className="userBalance">{this.props.exchange.outputToken.value + ": " + (this.props.exchange.outputBalance/10**18).toFixed(2)}</p>
<a target="_blank" rel="noopener noreferrer" href={'https://rinkeby.etherscan.io/search?q=' + this.props.web3Store.currentMaskAddress}>{this.props.web3Store.currentMaskAddress}</a> <a target="_blank" rel="noopener noreferrer" href={'https://rinkeby.etherscan.io/search?q=' + this.props.web3Store.currentMaskAddress}>{this.props.web3Store.currentMaskAddress}</a>
<p>{this.props.exchange.inputToken.value + ": " + (this.props.exchange.inputBalance/10**18).toFixed(2)}</p>
<p>{this.props.exchange.outputToken.value + ": " + (this.props.exchange.outputBalance/10**18).toFixed(2)}</p>
<p></p> <p></p>
</div> </div>
) )
...@@ -53,7 +53,7 @@ class NetworkStatus extends Component { ...@@ -53,7 +53,7 @@ class NetworkStatus extends Component {
} else { } else {
return ( return (
<div className="connection yellow border pa2"> <div className="connection yellow border pa2">
<p>{'MetaMask connected to ' + this.props.web3Store.networkMessage + ' Switch to Rinkeby and refresh!'}</p> <p>{'MetaMask connected to ' + this.props.web3Store.networkMessage + '. Please switch to Rinkeby!'}</p>
<p></p> <p></p>
</div> </div>
) )
......
...@@ -16,7 +16,6 @@ class Purchase extends Component { ...@@ -16,7 +16,6 @@ class Purchase extends Component {
buyShares = () => { buyShares = () => {
console.log(this.props.exchange.inputToken.value, 'ahh')
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;
var ethRequiredInt = parseInt(this.props.exchange.investEthRequired, 10).toString(); var ethRequiredInt = parseInt(this.props.exchange.investEthRequired, 10).toString();
...@@ -56,7 +55,6 @@ class Purchase extends Component { ...@@ -56,7 +55,6 @@ class Purchase extends Component {
// this.props.setExchangeOutputValue(0); // this.props.setExchangeOutputValue(0);
// this.props.setInteractionState('submitted'); // this.props.setInteractionState('submitted');
console.log(result); console.log(result);
// cookie.save('transactions', transactions, { path: '/' })
}) })
.on('receipt', (receipt) => {console.log(receipt)}) //Transaction Submitted to blockchain .on('receipt', (receipt) => {console.log(receipt)}) //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
...@@ -81,11 +79,11 @@ class Purchase extends Component { ...@@ -81,11 +79,11 @@ class Purchase extends Component {
</p> </p>
) )
} else { } else {
return ( return (
<a className="swap border pa2" role="button" onClick={() => {this.buyOrSellShares()}}> <a className="swap border pa2" role="button" onClick={() => {this.buyOrSellShares()}}>
<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>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>
</a> </a>
) )
} }
} else { } else {
......
...@@ -29,7 +29,7 @@ class Visualization extends Component { ...@@ -29,7 +29,7 @@ class Visualization extends Component {
//console.log(query, 'query') //console.log(query, 'query')
axios.get('http://ec2-34-205-17-195.compute-1.amazonaws.com:3000/graphql', { params: {query: query } }) axios.get('http://ec2-34-197-169-170.compute-1.amazonaws.com:3000/graphql', { params: {query: query } })
.then(data => this.setState({data: data.data.data.Event })) .then(data => this.setState({data: data.data.data.Event }))
.then(() => this.createLineGraph()) .then(() => this.createLineGraph())
.catch(err => console.error(err)); .catch(err => console.error(err));
...@@ -49,7 +49,7 @@ class Visualization extends Component { ...@@ -49,7 +49,7 @@ class Visualization extends Component {
} }
}`; }`;
axios.get('http://ec2-34-205-17-195.compute-1.amazonaws.com:3000/graphql', { params: { query: query }}) axios.get('http://ec2-34-197-169-170.compute-1.amazonaws.com:3000/graphql', { params: { query: query }})
.then(data => this.setState({data: data.data.data.Event})) .then(data => this.setState({data: data.data.data.Event}))
.then(() => { .then(() => {
this.createNewLineGraph() this.createNewLineGraph()
......
...@@ -53,6 +53,7 @@ export const SET_INVEST_TOKEN = 'SET_INVEST_TOKEN'; ...@@ -53,6 +53,7 @@ export const SET_INVEST_TOKEN = 'SET_INVEST_TOKEN';
export const SET_INVEST_INVARIANT = 'SET_INVEST_INVARIANT'; export const SET_INVEST_INVARIANT = 'SET_INVEST_INVARIANT';
export const SET_INVEST_ETH_POOL = 'SET_INVEST_ETH'; export const SET_INVEST_ETH_POOL = 'SET_INVEST_ETH';
export const SET_INVEST_TOKEN_POOL = 'SET_INVEST_TOKENS'; export const SET_INVEST_TOKEN_POOL = 'SET_INVEST_TOKENS';
export const SET_INVEST_TOKEN_ALLOWANCE = 'SET_INVEST_TOKEN_ALLOWANCE';
export const SET_INVEST_SHARES = 'SET_INVEST_SHARES'; export const SET_INVEST_SHARES = 'SET_INVEST_SHARES';
export const SET_USER_SHARES = 'SET_USER_SHARES'; export const SET_USER_SHARES = 'SET_USER_SHARES';
export const SET_INVEST_TOKEN_BALANCE = 'SET_INVEST_TOKEN_BALANCE'; export const SET_INVEST_TOKEN_BALANCE = 'SET_INVEST_TOKEN_BALANCE';
...@@ -62,5 +63,6 @@ export const SET_INVEST_ETH_REQUIRED = 'SET_INVEST_ETH_REQUIRED'; ...@@ -62,5 +63,6 @@ export const SET_INVEST_ETH_REQUIRED = 'SET_INVEST_ETH_REQUIRED';
export const SET_INVEST_TOKENS_REQUIRED = 'SET_INVEST_TOKENS_REQUIRED'; export const SET_INVEST_TOKENS_REQUIRED = 'SET_INVEST_TOKENS_REQUIRED';
export const SET_INVEST_CHECKED = 'SET_INVEST_CHECKED'; export const SET_INVEST_CHECKED = 'SET_INVEST_CHECKED';
// test setInteractionState // test setInteractionState
export const INITIALIZE_GLOBAL_WEB3 = 'INITIALIZE_GLOBAL_WEB3'; export const INITIALIZE_GLOBAL_WEB3 = 'INITIALIZE_GLOBAL_WEB3';
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
SET_INVEST_INVARIANT, SET_INVEST_INVARIANT,
SET_INVEST_ETH_POOL, SET_INVEST_ETH_POOL,
SET_INVEST_TOKEN_POOL, SET_INVEST_TOKEN_POOL,
SET_INVEST_TOKEN_ALLOWANCE,
SET_INVEST_SHARES, SET_INVEST_SHARES,
SET_USER_SHARES, SET_USER_SHARES,
SET_INVEST_ETH_BALANCE, SET_INVEST_ETH_BALANCE,
...@@ -53,6 +54,7 @@ export default (state = {}, action) => { ...@@ -53,6 +54,7 @@ export default (state = {}, action) => {
userShares, userShares,
investEthBalance, investEthBalance,
investTokenBalance, investTokenBalance,
investTokenAllowance,
investSharesInput, investSharesInput,
investEthRequired, investEthRequired,
investTokensRequired, investTokensRequired,
...@@ -106,6 +108,8 @@ export default (state = {}, action) => { ...@@ -106,6 +108,8 @@ export default (state = {}, action) => {
return Object.assign({}, state, { investEthBalance: investEthBalance }); return Object.assign({}, state, { investEthBalance: investEthBalance });
case SET_INVEST_TOKEN_BALANCE: case SET_INVEST_TOKEN_BALANCE:
return Object.assign({}, state, { investTokenBalance: investTokenBalance }); return Object.assign({}, state, { investTokenBalance: investTokenBalance });
case SET_INVEST_TOKEN_ALLOWANCE:
return Object.assign({}, state, { investTokenAllowance: investTokenAllowance });
case SET_INVEST_SHARES_INPUT: case SET_INVEST_SHARES_INPUT:
return Object.assign({}, state, { investSharesInput: investSharesInput }); return Object.assign({}, state, { investSharesInput: investSharesInput });
case SET_INVEST_ETH_REQUIRED: case SET_INVEST_ETH_REQUIRED:
......
// import { INITIALIZE_GLOBAL_WEB3 } from '../constants';
// export default (state = {}, action) => {
// const { globalWeb3 } = action;
// switch(action.type) {
// case INITIALIZE_GLOBAL_WEB3:
// return Object.assign({}, state, { web3: globalWeb3 });
// default: return state
// }
// }
\ No newline at end of file
...@@ -57,6 +57,7 @@ export default { ...@@ -57,6 +57,7 @@ export default {
userShares: 0, userShares: 0,
investTokenBalance: 0, investTokenBalance: 0,
investEthBalance: 0, investEthBalance: 0,
investTokenAllowance: 0,
investSharesInput: 0, investSharesInput: 0,
investEthRequired: 0, investEthRequired: 0,
investTokensRequired: 0, investTokensRequired: 0,
......
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