Commit 5e7ae40c authored by Hayden Adams's avatar Hayden Adams

small improvements

parent 0a5042e0
...@@ -14,18 +14,23 @@ import Purchase from './components/Purchase'; ...@@ -14,18 +14,23 @@ import Purchase from './components/Purchase';
import About from './components/About'; import About from './components/About';
import Links from './components/Links'; 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
// import Visualization from './components/Visualization'; // import Visualization from './components/Visualization';
// 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 { exchangeContractReady } from './actions/exchangeContract-actions';
import { exchangeContractReady } from './actions/exchangeContract-actions'; import { tokenContractReady } from './actions/tokenContract-actions';
import { tokenContractReady } from './actions/tokenContract-actions'; import { initializeGlobalWeb3,
import { initializeGlobalWeb3, setWeb3ConnectionStatus, setCurrentMaskAddress, metamaskLocked, metamaskUnlocked, setInteractionState, factoryContractReady, toggleAbout, toggleInvest } from './actions/web3-actions'; setWeb3ConnectionStatus,
setCurrentMaskAddress,
metamaskLocked,
metamaskUnlocked,
setInteractionState,
factoryContractReady,
toggleAbout,
toggleInvest } from './actions/web3-actions';
import { setInputBalance, import { setInputBalance,
setOutputBalance, setOutputBalance,
setInvariant1, setInvariant1,
...@@ -44,34 +49,30 @@ import { setInputBalance, ...@@ -44,34 +49,30 @@ import { setInputBalance,
setUserShares, setUserShares,
setInvestTokenBalance, setInvestTokenBalance,
setInvestEthBalance } from './actions/exchange-actions'; setInvestEthBalance } from './actions/exchange-actions';
// enter d3 & misc. tools
import './App.css'; import './App.css';
import cookie from 'react-cookies' import cookie from 'react-cookies'
import scrollToComponent from 'react-scroll-to-component'; import scrollToComponent from 'react-scroll-to-component';
var localweb3; // this isn't even in state var web3;
class App extends Component { class App extends Component {
constructor (props) { constructor (props) {
super(props) super(props)
if (typeof props.metamask !== 'undefined'){ if (typeof props.metamask !== 'undefined'){
localweb3 = new Web3(window.web3.currentProvider) web3 = new Web3(window.web3.currentProvider)
} else { } else {
localweb3 = 'undefined' web3 = 'undefined'
} }
this.state = { this.state = {
uniAdded: false, // cookie stuff, transactions: []
swapAdded: false, // cookie stuff
firstRun: true, // cookie stuff
transactions: [], // cookie stuff
} }
} }
// TODO: get rid of redundant localweb3 === 'undefined' checks in componentWill/DidMount // TODO: get rid of redundant web3 === 'undefined' checks in componentWill/DidMount
// STATUS: kind of done // STATUS: kind of done
componentWillMount() { componentWillMount() {
//console.log('props', this.props); //console.log('props', this.props);
if(localweb3 === 'undefined') { if(web3 === 'undefined') {
this.props.setWeb3ConnectionStatus(false); this.props.setWeb3ConnectionStatus(false);
} else { } else {
this.setState({ this.setState({
...@@ -81,7 +82,7 @@ class App extends Component { ...@@ -81,7 +82,7 @@ class App extends Component {
transactions: cookie.load('transactions') || [], transactions: cookie.load('transactions') || [],
}) })
// we're working with asynchronous redux // we're working with asynchronous redux
this.props.initializeGlobalWeb3(localweb3) this.props.initializeGlobalWeb3(web3)
this.getInfoFirstTime(); this.getInfoFirstTime();
} }
} }
...@@ -109,7 +110,7 @@ class App extends Component { ...@@ -109,7 +110,7 @@ class App extends Component {
// TODO: getInfoFirstTime and getUserAddress are WET af // TODO: getInfoFirstTime and getUserAddress are WET af
// lets do something about it // lets do something about it
getInfoFirstTime = () => { getInfoFirstTime = () => {
localweb3.eth.getAccounts(async (error, result) => { web3.eth.getAccounts(async (error, result) => {
if(result.length > 0){ if(result.length > 0){
this.props.setCurrentMaskAddress(result[0]); this.props.setCurrentMaskAddress(result[0]);
this.props.metamaskUnlocked(); this.props.metamaskUnlocked();
...@@ -124,9 +125,9 @@ class App extends Component { ...@@ -124,9 +125,9 @@ class App extends Component {
} }
}) })
} }
// fun fact, localweb3.eth.getAccounts will return something even without anything inside
getUserAddress = () => { getUserAddress = () => {
localweb3.eth.getAccounts((error, result) => { this.props.web3Store.web3.eth.getAccounts((error, result) => {
if (result.length > 0) { if (result.length > 0) {
this.props.setCurrentMaskAddress(result[0]); this.props.setCurrentMaskAddress(result[0]);
this.props.metamaskUnlocked(); this.props.metamaskUnlocked();
...@@ -147,19 +148,19 @@ class App extends Component { ...@@ -147,19 +148,19 @@ class App extends Component {
// could possibly use refactoring // could possibly use refactoring
getContracts = () => { getContracts = () => {
const factoryAddress = this.props.web3Store.factoryAddress; const factoryAddress = this.props.web3Store.factoryAddress;
const factoryContract = new localweb3.eth.Contract(factoryABI, factoryAddress); const factoryContract = new this.props.web3Store.web3.eth.Contract(factoryABI, factoryAddress);
this.props.factoryContractReady(factoryContract); this.props.factoryContractReady(factoryContract);
this.props.web3Store.exchangeAddresses.addresses.map(async exchangeAddress => { this.props.web3Store.exchangeAddresses.addresses.map(async exchangeAddress => {
// receive the exchange address, create the exchange contract // receive the exchange address, create the exchange contract
let exchangeContract = await new localweb3.eth.Contract(exchangeABI, exchangeAddress[1]); let exchangeContract = await new this.props.web3Store.web3.eth.Contract(exchangeABI, exchangeAddress[1]);
// send the exchange contract to redux store // send the exchange contract to redux store
await this.props.exchangeContractReady(exchangeAddress[0], exchangeContract); await this.props.exchangeContractReady(exchangeAddress[0], exchangeContract);
}) })
this.props.web3Store.tokenAddresses.addresses.map(async tokenAddress => { this.props.web3Store.tokenAddresses.addresses.map(async tokenAddress => {
// receive the token address, create the token contract // receive the token address, create the token contract
let tokenContract = await new localweb3.eth.Contract(tokenABI, tokenAddress[1]); let tokenContract = await new this.props.web3Store.web3.eth.Contract(tokenABI, tokenAddress[1]);
// send the token contract to redux store // send the token contract to redux store
await this.props.tokenContractReady(tokenAddress[0], tokenContract); await this.props.tokenContractReady(tokenAddress[0], tokenContract);
}) })
...@@ -194,7 +195,6 @@ class App extends Component { ...@@ -194,7 +195,6 @@ class App extends Component {
return this.props.exchangeContracts[symbol] return this.props.exchangeContracts[symbol]
} }
getMarketInfo = () => { getMarketInfo = () => {
switch (this.props.web3Store.exchangeType) { switch (this.props.web3Store.exchangeType) {
case 'ETH to Token': case 'ETH to Token':
...@@ -240,7 +240,6 @@ class App extends Component { ...@@ -240,7 +240,6 @@ class App extends Component {
break; break;
default: default:
} }
// console.log("Getting account info");
} }
getInvestInfo = () => { getInvestInfo = () => {
...@@ -321,12 +320,12 @@ class App extends Component { ...@@ -321,12 +320,12 @@ class App extends Component {
getEthBalance = (type) => { getEthBalance = (type) => {
if (type === 'input') { if (type === 'input') {
localweb3.eth.getBalance(this.props.web3Store.currentMaskAddress, (error, balance) => { this.props.web3Store.web3.eth.getBalance(this.props.web3Store.currentMaskAddress, (error, balance) => {
this.props.setInputBalance(balance); this.props.setInputBalance(balance);
// console.log('ETH Balance: ' + balance); // console.log('ETH Balance: ' + balance);
}); });
} else if (type === 'output') { } else if (type === 'output') {
localweb3.eth.getBalance(this.props.web3Store.currentMaskAddress, (error, balance) => { this.props.web3Store.web3.eth.getBalance(this.props.web3Store.currentMaskAddress, (error, balance) => {
this.props.setOutputBalance(balance); this.props.setOutputBalance(balance);
// console.log('ETH Balance: ' + balance); // console.log('ETH Balance: ' + balance);
}); });
...@@ -357,10 +356,8 @@ class App extends Component { ...@@ -357,10 +356,8 @@ class App extends Component {
var exchangeAddress = this.symbolToExchangeAddress(this.props.exchange.inputToken.value); var exchangeAddress = this.symbolToExchangeAddress(this.props.exchange.inputToken.value);
token.methods.allowance(this.props.web3Store.currentMaskAddress, exchangeAddress).call().then((result, error) => { token.methods.allowance(this.props.web3Store.currentMaskAddress, exchangeAddress).call().then((result, error) => {
console.log(this.props.exchange.inputToken.value + ' allowance: ' + result);
if(result === '0'){ if(result === '0'){
this.props.setAllowanceApprovalState(false) this.props.setAllowanceApprovalState(false)
console.log(this.props.exchange.allowanceApproved)
} }
}) })
} }
...@@ -371,7 +368,7 @@ class App extends Component { ...@@ -371,7 +368,7 @@ class App extends Component {
if(type === 'Token to ETH' || type === 'Token to Token') { if(type === 'Token to ETH' || type === 'Token to Token') {
var token = this.symbolToTokenContract(this.props.exchange.inputToken.value); var token = this.symbolToTokenContract(this.props.exchange.inputToken.value);
var exchangeAddress = this.symbolToExchangeAddress(this.props.exchange.inputToken.value); var exchangeAddress = this.symbolToExchangeAddress(this.props.exchange.inputToken.value);
var amount = localweb3.utils.toWei('100000'); var amount = this.props.web3Store.web3.utils.toWei('100000');
token.methods.approve(exchangeAddress, amount).send({from: this.props.web3Store.currentMaskAddress}) token.methods.approve(exchangeAddress, amount).send({from: this.props.web3Store.currentMaskAddress})
.on('transactionHash', console.log('Transaction Hash created')) .on('transactionHash', console.log('Transaction Hash created'))
...@@ -405,19 +402,6 @@ class App extends Component { ...@@ -405,19 +402,6 @@ class App extends Component {
.on('error', console.error); .on('error', console.error);
} }
onCloseHelper = () => {
if(this.props.exchange.outputToken.value === 'UNI'){
this.setState({ uniAdded: true }) // cookie stuff
cookie.save('uniAdded', true, { path: '/' })
} else if(this.props.exchange.outputToken.value === 'SWAP'){
this.setState({ swapAdded: true }) // more cookie stuff
cookie.save('swapAdded', true, { path: '/' })
} else {
this.setState({ firstRun: !this.state.firstRun }) // also cookie stuff
cookie.save('firstRun', !this.state.firstRun, { path: '/' })
}
}
toggleAbout = () => { toggleAbout = () => {
let current = this.props.web3Store.aboutToggle; let current = this.props.web3Store.aboutToggle;
this.props.toggleAbout(!current); this.props.toggleAbout(!current);
...@@ -447,10 +431,6 @@ class App extends Component { ...@@ -447,10 +431,6 @@ class App extends Component {
<ConnectionHelper <ConnectionHelper
metamask={this.props.metamask} metamask={this.props.metamask}
approveAllowance={this.approveAllowance} approveAllowance={this.approveAllowance}
firstRun={this.state.firstRun}
uniAdded={this.state.uniAdded}
swapAdded={this.state.swapAdded}
onCloseHelper={this.onCloseHelper}
toggleAbout={this.toggleAbout} toggleAbout={this.toggleAbout}
/> />
<Exchange <Exchange
......
...@@ -25,7 +25,7 @@ function ConnectionHelper(props) { ...@@ -25,7 +25,7 @@ function ConnectionHelper(props) {
It 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.exchangeType === "Token to itself" || props.web3Store.exchangeType === "ETH to ETH") {
return ( return (
<div className="grey-bg connection border pa2"> <div className="grey-bg connection border pa2">
<p>You can't swap a token for itself! <span role="img" aria-label="Crying">😂</span></p> <p>You can't swap a token for itself! <span role="img" aria-label="Crying">😂</span></p>
......
...@@ -8,7 +8,6 @@ import { setExchangeInputValue, setExchangeOutputValue, setExchangeRate, setExch ...@@ -8,7 +8,6 @@ import { setExchangeInputValue, setExchangeOutputValue, setExchangeRate, setExch
class Exchange extends Component { class Exchange extends Component {
onInputChange = async (event) => { onInputChange = async (event) => {
var inputValue = event.target.value; var inputValue = event.target.value;
console.log(inputValue, 'onInputChange value')
await this.props.setExchangeInputValue(inputValue); await this.props.setExchangeInputValue(inputValue);
this.setExchangeOutput(); this.setExchangeOutput();
} }
...@@ -19,8 +18,6 @@ class Exchange extends Component { ...@@ -19,8 +18,6 @@ class Exchange extends Component {
this.props.setExchangeRate(0); this.props.setExchangeRate(0);
this.props.setExchangeFee(0); this.props.setExchangeFee(0);
this.props.setInteractionState('connected'); this.props.setInteractionState('connected');
// what the flip does this do
// this.setState({ firstRun: true })
if (type === 'input') { if (type === 'input') {
await this.props.setInputToken(selected); await this.props.setInputToken(selected);
...@@ -29,7 +26,6 @@ class Exchange extends Component { ...@@ -29,7 +26,6 @@ class Exchange extends Component {
} }
await this.getMarketType(); await this.getMarketType();
// these two functions are actually being passed from the parent component, because they're used in multiple places
// eventually pull these out into HOC // eventually pull these out into HOC
this.props.getAccountInfo(); this.props.getAccountInfo();
this.props.getMarketInfo(); this.props.getMarketInfo();
...@@ -37,8 +33,6 @@ class Exchange extends Component { ...@@ -37,8 +33,6 @@ class Exchange extends Component {
setExchangeOutput = () => { setExchangeOutput = () => {
var inputValue = this.props.exchange.inputValue; var inputValue = this.props.exchange.inputValue;
console.log(inputValue, 'from setExchangeOutput')
console.log('outputToken', this.props.exchange.outputToken);
if (this.props.web3Store.exchangeType === 'ETH to ETH' || this.props.web3Store.exchangeType === 'Token to itself'){ if (this.props.web3Store.exchangeType === 'ETH to ETH' || this.props.web3Store.exchangeType === 'Token to itself'){
this.props.setExchangeOutputValue(0); this.props.setExchangeOutputValue(0);
this.props.setInteractionState('error1'); this.props.setInteractionState('error1');
...@@ -75,13 +69,13 @@ class Exchange extends Component { ...@@ -75,13 +69,13 @@ class Exchange extends Component {
getExchangeRate = (input) => { getExchangeRate = (input) => {
if (this.props.web3Store.exchangeType === 'ETH to Token') { if (this.props.web3Store.exchangeType === 'ETH to Token') {
console.log('Getting Rate: ETH to ' + this.props.exchange.outputToken.value); // console.log('Getting Rate: ETH to ' + this.props.exchange.outputToken.value);
this.ethToTokenRate(input); this.ethToTokenRate(input);
} else if (this.props.web3Store.exchangeType === 'Token to ETH') { } else if (this.props.web3Store.exchangeType === 'Token to ETH') {
console.log('Getting Rate: ' + this.props.exchange.inputToken.value + ' to ETH'); // console.log('Getting Rate: ' + this.props.exchange.inputToken.value + ' to ETH');
this.tokenToEthRate(input); this.tokenToEthRate(input);
} else if (this.props.web3Store.exchangeType === 'Token to Token') { } else if (this.props.web3Store.exchangeType === 'Token to Token') {
console.log('Getting Rate: ' + this.props.exchange.inputToken.value + ' to ' + this.props.exchange.outputToken.value); // console.log('Getting Rate: ' + this.props.exchange.inputToken.value + ' to ' + this.props.exchange.outputToken.value);
this.tokenToTokenRate(input); this.tokenToTokenRate(input);
} }
} }
......
...@@ -11,7 +11,7 @@ class NetworkStatus extends Component { ...@@ -11,7 +11,7 @@ class NetworkStatus extends Component {
if (state.web3Store.currentMaskAddress !== undefined) { if (state.web3Store.currentMaskAddress !== undefined) {
// console.log('METAMASK UNLOCKED FROM NETWORK STATUS') // console.log('METAMASK UNLOCKED FROM NETWORK STATUS')
this.checkNetwork(); this.checkNetwork();
} else { console.log('METAMASK LOCKED FROM NETWORK STATUS') } } else { console.log('METAMASK LOCKED') }
}) })
} }
......
...@@ -112,6 +112,7 @@ class Purchase extends Component { ...@@ -112,6 +112,7 @@ class Purchase extends Component {
</a> </a>
) )
} else { } else {
// eslint-disable-next-line
return (<a className="swap grey-bg hidden border pa2"></a>) return (<a className="swap grey-bg hidden border pa2"></a>)
} }
} }
......
// here is where we put the string literals for the actions // here is where we put the string literals for the actions
// maybe there's an action to see if you've been connected to web3
// web3 actions, all set from action creator to reducer to app // web3 actions, all set from action creator to reducer to app
export const SET_WEB3_CONNECTION_STATUS = 'WEB3_CONNECTION_STATUS'; export const SET_WEB3_CONNECTION_STATUS = 'WEB3_CONNECTION_STATUS';
......
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