Commit 20538d34 authored by Uciel's avatar Uciel

renamed web3 reducer

parent fe19f9ea
......@@ -14,16 +14,16 @@ import Purchase from './components/Purchase';
import About from './components/About';
import Links from './components/Links';
import Transactions from './components/Transactions';
import SelectToken from './components/SelectToken'
// import SelectToken from './components/SelectToken'
// enter redux
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux';
import { subscribe } from 'redux-subscriber';
// redux actions
import { initializeGlobalWeb3 } from './actions/global-actions';
// import { initializeGlobalWeb3 } from './actions/global-actions';
import { uniExchangeContractReady, swtExchangeContractReady } from './actions/exchangeContract-actions';
import { uniTokenContractReady, swtTokenContractReady } from './actions/tokenContract-actions';
import { setWeb3ConnectionStatus, setCurrentMaskAddress, metamaskLocked, metamaskUnlocked, setInteractionState, factoryContractReady, toggleAbout } from './actions/web3-actions';
import { initializeGlobalWeb3, setWeb3ConnectionStatus, setCurrentMaskAddress, metamaskLocked, metamaskUnlocked, setInteractionState, factoryContractReady, toggleAbout } from './actions/web3-actions';
import { setInputBalance, setOutputBalance, setInvariant1, setInvariant2, setMarketEth1, setMarketEth2, setMarketTokens1, setMarketTokens2, setAllowanceApprovalState } from './actions/exchange-actions';
// enter d3 & misc. tools
import './App.css';
......@@ -75,11 +75,11 @@ class App extends Component {
if(state.web3Store.connected === true && !state.web3Store.metamaskLocked) {
console.log('successfully connected to metamask', state.web3Store.currentMaskAddress);
setInterval(this.getMarketInfo, 15000);
// setInterval(this.getAccountInfo, 15000);
// setInterval(this.getUserAddress, 10000);
setInterval(this.getAccountInfo, 15000);
setInterval(this.getUserAddress, 10000);
} else {
console.log('web3 not connected, getting user address')
// setInterval(this.getUserAddress, 500);
setInterval(this.getUserAddress, 500);
}
})
}
......@@ -107,11 +107,13 @@ class App extends Component {
getUserAddress = () => {
localweb3.eth.getAccounts((error, result) => {
if (result.length > 0) {
console.log('getUserAddress metamask unlocked')
this.props.setCurrentMaskAddress(result[0]);
this.props.metamaskUnlocked();
this.props.setWeb3ConnectionStatus(true);
}
else {
console.log('getUserAddress metamask Locked ')
this.props.metamaskLocked();
this.props.setWeb3ConnectionStatus(false);
this.props.setInteractionState('locked');
......
import {
INITIALIZE_GLOBAL_WEB3,
SET_WEB3_CONNECTION_STATUS,
SET_CURRENT_MASK_ADDRESS,
METAMASK_LOCKED,
......@@ -94,4 +95,10 @@ export const setExchangeType = (exchangeType) => ({
export const toggleAbout = (toggle) => ({
type: TOGGLE_ABOUT,
aboutToggle: toggle
})
\ No newline at end of file
});
export const initializeGlobalWeb3 = (web3) => ({
type: INITIALIZE_GLOBAL_WEB3,
web3
});
\ No newline at end of file
import React, { Component }from 'react';
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { setWeb3ConnectionStatus, setInteractionState, setNetworkMessage } from '../actions/web3-actions';
import { subscribe } from 'redux-subscriber';
import { setWeb3ConnectionStatus, setInteractionState, setNetworkMessage, metamaskLocked } from '../actions/web3-actions';
class NetworkStatus extends Component {
componentDidMount(){
if (this.props.global.web3 !== undefined){
const interactionStateSubscriber = subscribe('web3Store.metamaskLocked', state => {
if (state.web3Store.metamaskLocked !== true) {
console.log('metamask is unlocked')
this.checkNetwork();
} else {
console.log('metamask is locked')
}
})
// if (this.props.web3Store.web3 !== undefined){
// this.checkNetwork();
// }
}
checkNetwork = () => {
this.props.global.web3.eth.net.getNetworkType((err, networkId) => {
this.props.web3Store.web3.eth.net.getNetworkType((err, networkId) => {
console.log("Connected to " + networkId)
let interactionState = networkId === 'rinkeby' ? 'connected' : 'disconnected';
let connectionStatus = networkId === 'rinkeby' ? true : false;
......@@ -64,6 +73,7 @@ const mapDispatchToProps = (dispatch) => {
setWeb3ConnectionStatus,
setInteractionState,
setNetworkMessage,
metamaskLocked
}, dispatch)
}
......
......@@ -6,7 +6,7 @@ import { setExchangeInputValue, setExchangeOutputValue } from '../actions/exchan
class Purchase extends Component {
purchaseTokens = async () => {
await this.props.setBlockTimestamp(this.props.global.web3);
await this.props.setBlockTimestamp(this.props.web3Store.web3);
if (this.props.web3Store.exchangeType === 'ETH to Token') {
this.ethToTokenPurchase();
} else if (this.props.web3Store.exchangeType === 'Token to ETH') {
......@@ -19,9 +19,9 @@ class Purchase extends Component {
ethToTokenPurchase = () => {
var exchange = this.props.symbolToExchangeContract(this.props.exchange.outputToken.value);
var minTokens = (this.props.exchange.outputValue/10**18).toString();
var minTokensInt = this.props.global.web3.utils.toWei(minTokens);
var minTokensInt = this.props.web3Store.web3.utils.toWei(minTokens);
var ethSold = this.props.exchange.inputValue;
var weiSold = this.props.global.web3.utils.toWei(ethSold);
var weiSold = this.props.web3Store.web3.utils.toWei(ethSold);
var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins
// console.log(minTokensInt, weiSold, timeout);
......@@ -53,9 +53,9 @@ class Purchase extends Component {
tokenToEthPurchase = () => {
var exchange = this.props.symbolToExchangeContract(this.props.exchange.inputToken.value);
var minEth = (this.props.exchange.outputValue/10**18).toString();
var minEthInt = this.props.global.web3.utils.toWei(minEth);
var minEthInt = this.props.web3Store.web3.utils.toWei(minEth);
var tokensSold = this.props.exchange.inputValue;
var tokensSoldInt = this.props.global.web3.utils.toWei(tokensSold);
var tokensSoldInt = this.props.web3Store.web3.utils.toWei(tokensSold);
var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins
exchange.methods.tokenToEthSwap(tokensSoldInt, minEthInt, timeout).send({from: this.props.web3Store.currentMaskAddress})
......@@ -78,9 +78,9 @@ class Purchase extends Component {
var exchange = this.props.symbolToExchangeContract(this.props.exchange.inputToken.value);
var tokenOutAddress = this.props.symbolToTokenAddress(this.props.exchange.outputToken.value);
var minTokens = (this.props.exchange.outputValue/10**18).toString();
var minTokensInt = this.props.global.web3.utils.toWei(minTokens);
var minTokensInt = this.props.web3Store.web3.utils.toWei(minTokens);
var tokensSold = this.props.exchange.inputValue;
var tokensSoldInt = this.props.global.web3.utils.toWei(tokensSold);
var tokensSoldInt = this.props.web3Store.web3.utils.toWei(tokensSold);
var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins
console.log('tokenOutAddress', tokenOutAddress);
console.log('minTokensInt', minTokensInt);
......
import { INITIALIZE_GLOBAL_WEB3 } from '../constants';
// 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
// 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
import { combineReducers } from 'redux';
import global from './global-reducer';
// import global from './global-reducer';
import web3Store from './web3-reducer';
import exchangeContracts from './exchangeContract-reducer';
import tokenContracts from './tokenContract-reducer';
import exchange from './exchange-reducer';
export default combineReducers({
global,
web3Store,
exchangeContracts,
tokenContracts,
......
......@@ -14,8 +14,10 @@ import {
} from '../constants';
export default (state = {}, action) => {
const { connected, currentMaskAddress, metamaskLocked, interaction, factoryContract, networkMessage, timestamp, exchangeType, globalWeb3, aboutToggle } = action
const { connected, currentMaskAddress, metamaskLocked, interaction, factoryContract, networkMessage, timestamp, exchangeType, web3, aboutToggle } = action
switch (action.type) {
case INITIALIZE_GLOBAL_WEB3:
return Object.assign({}, state, { web3: web3 });
case SET_WEB3_CONNECTION_STATUS:
return Object.assign({}, state, { connected: connected });
case SET_CURRENT_MASK_ADDRESS:
......@@ -34,8 +36,6 @@ export default (state = {}, action) => {
return Object.assign({}, state, { blockTimestamp: timestamp });
case SET_EXCHANGE_TYPE:
return Object.assign({}, state, { exchangeType: exchangeType });
case INITIALIZE_GLOBAL_WEB3:
return Object.assign({}, state, { globalWeb3: globalWeb3 });
case TOGGLE_ABOUT:
return Object.assign({}, state, { aboutToggle: aboutToggle })
default: return state;
......
export default {
global: {},
web3Store: {
web3: {},
connected: false,
aboutToggle: false,
globalWeb3: {},
......
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