Commit fbd78a5a authored by Hayden Adams's avatar Hayden Adams

rename web to web3Store, remove getBlock interval

parent 37d82f97
...@@ -27,7 +27,8 @@ import { ...@@ -27,7 +27,8 @@ import {
factoryContractReady, factoryContractReady,
setNetworkMessage, setNetworkMessage,
setBlockTimestamp, setBlockTimestamp,
setExchangeType setExchangeType,
putWeb3InStore
} from './actions/web3-actions'; } from './actions/web3-actions';
import { import {
...@@ -95,17 +96,15 @@ class App extends Component { ...@@ -95,17 +96,15 @@ class App extends Component {
}) })
this.getInfoFirstTime(); this.getInfoFirstTime();
this.checkNetwork(); this.checkNetwork();
this.getBlock();
} }
} }
componentDidMount(){ componentDidMount (){
if(localweb3 === 'undefined') { if(localweb3 === 'undefined') {
this.props.web3ConnectionUnsuccessful(); this.props.web3ConnectionUnsuccessful();
console.log('props here', this.props) this.props.putWeb3InStore(localweb3);
} else if(this.props.web3.connected === true) { } else if(this.props.web3Store.connected === true) {
console.log('successfully connected to metamask') console.log('successfully connected to metamask');
setInterval(this.getBlock, 10000);
setInterval(this.getMarketInfo, 15000); setInterval(this.getMarketInfo, 15000);
setInterval(this.getAccountInfo, 15000); setInterval(this.getAccountInfo, 15000);
setInterval(this.getUserAddress, 10000); setInterval(this.getUserAddress, 10000);
...@@ -120,7 +119,7 @@ class App extends Component { ...@@ -120,7 +119,7 @@ class App extends Component {
// getInfoFirstTime = async () => { // getInfoFirstTime = async () => {
// await this.getUserAddress(); // await this.getUserAddress();
// if(this.props.web3.currentMaskAddress !== '') { // if(this.props.web3Store.currentMaskAddress !== '') {
// await this.getContracts(); // await this.getContracts();
// this.getMarketInfo(); // this.getMarketInfo();
// this.getAccountInfo(); // this.getAccountInfo();
...@@ -165,23 +164,23 @@ class App extends Component { ...@@ -165,23 +164,23 @@ class App extends Component {
} }
getContracts = async () => { getContracts = async () => {
const uniExchangeAddress = this.props.web3.exchangeAddresses.UNI; const uniExchangeAddress = this.props.web3Store.exchangeAddresses.UNI;
const uniExchangeContract = new localweb3.eth.Contract(exchangeABI, uniExchangeAddress); const uniExchangeContract = new localweb3.eth.Contract(exchangeABI, uniExchangeAddress);
this.props.uniExchangeContractReady(uniExchangeContract); this.props.uniExchangeContractReady(uniExchangeContract);
const swapExchangeAddress = this.props.web3.exchangeAddresses.SWT; const swapExchangeAddress = this.props.web3Store.exchangeAddresses.SWT;
const swapExchangeContract = new localweb3.eth.Contract(exchangeABI, swapExchangeAddress); const swapExchangeContract = new localweb3.eth.Contract(exchangeABI, swapExchangeAddress);
this.props.swtExchangeContractReady(swapExchangeContract); this.props.swtExchangeContractReady(swapExchangeContract);
const uniTokenAddress = this.props.web3.tokenAddresses.UNI; const uniTokenAddress = this.props.web3Store.tokenAddresses.UNI;
const uniTokenContract = new localweb3.eth.Contract(tokenABI, uniTokenAddress); const uniTokenContract = new localweb3.eth.Contract(tokenABI, uniTokenAddress);
this.props.uniTokenContractReady(uniTokenContract); this.props.uniTokenContractReady(uniTokenContract);
const swapTokenAddress = this.props.web3.tokenAddresses.SWT; const swapTokenAddress = this.props.web3Store.tokenAddresses.SWT;
const swapTokenContract = new localweb3.eth.Contract(tokenABI, swapTokenAddress); const swapTokenContract = new localweb3.eth.Contract(tokenABI, swapTokenAddress);
this.props.swtTokenContractReady(swapTokenContract); this.props.swtTokenContractReady(swapTokenContract);
const factoryAddress = this.props.web3.factoryAddress; const factoryAddress = this.props.web3Store.factoryAddress;
const factoryContract = new localweb3.eth.Contract(factoryABI, factoryAddress); const factoryContract = new localweb3.eth.Contract(factoryABI, factoryAddress);
this.props.factoryContractReady(factoryContract); this.props.factoryContractReady(factoryContract);
...@@ -234,9 +233,9 @@ class App extends Component { ...@@ -234,9 +233,9 @@ class App extends Component {
symbolToTokenAddress = (symbol) => { symbolToTokenAddress = (symbol) => {
if(symbol === 'UNI') { if(symbol === 'UNI') {
return this.props.web3.exchangeAddresses.UNI; return this.props.web3Store.exchangeAddresses.UNI;
} else if (symbol === 'SWAP') { } else if (symbol === 'SWAP') {
return this.props.web3.exchangeAddresses.SWT; return this.props.web3Store.exchangeAddresses.SWT;
} }
} }
...@@ -250,9 +249,9 @@ class App extends Component { ...@@ -250,9 +249,9 @@ class App extends Component {
symbolToExchangeAddress = (symbol) => { symbolToExchangeAddress = (symbol) => {
if(symbol === 'UNI') { if(symbol === 'UNI') {
return this.props.web3.exchangeAddresses.UNI; return this.props.web3Store.exchangeAddresses.UNI;
} else if(symbol === 'SWAP') { } else if(symbol === 'SWAP') {
return this.props.web3.exchangeAddresses.SWT; return this.props.web3Store.exchangeAddresses.SWT;
} }
} }
...@@ -265,7 +264,7 @@ class App extends Component { ...@@ -265,7 +264,7 @@ class App extends Component {
} }
getMarketInfo = () => { getMarketInfo = () => {
switch (this.props.web3.exchangeType) { switch (this.props.web3Store.exchangeType) {
case 'ETH to Token': case 'ETH to Token':
this.getExchangeState('output'); this.getExchangeState('output');
break; break;
...@@ -281,7 +280,7 @@ class App extends Component { ...@@ -281,7 +280,7 @@ class App extends Component {
} }
getAccountInfo = () => { getAccountInfo = () => {
switch (this.props.web3.exchangeType) { switch (this.props.web3Store.exchangeType) {
case 'ETH to Token': case 'ETH to Token':
this.getEthBalance('input'); this.getEthBalance('input');
this.getTokenBalance('output'); this.getTokenBalance('output');
...@@ -341,12 +340,12 @@ class App extends Component { ...@@ -341,12 +340,12 @@ class App extends Component {
getEthBalance = (type) => { getEthBalance = (type) => {
if (type === 'input') { if (type === 'input') {
localweb3.eth.getBalance(this.props.web3.currentMaskAddress, (error, balance) => { localweb3.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.web3.currentMaskAddress, (error, balance) => { localweb3.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,13 +356,13 @@ class App extends Component { ...@@ -357,13 +356,13 @@ class App extends Component {
var token; var token;
if (type === 'input') { if (type === 'input') {
token = this.symbolToTokenContract(this.props.exchange.inputToken.value); token = this.symbolToTokenContract(this.props.exchange.inputToken.value);
token.methods.balanceOf(this.props.web3.currentMaskAddress).call((error, balance) => { token.methods.balanceOf(this.props.web3Store.currentMaskAddress).call((error, balance) => {
this.props.setInputBalance(balance); this.props.setInputBalance(balance);
// console.log(this.props.exchange.inputToken.value + ' Balance: ' + balance); // console.log(this.props.exchange.inputToken.value + ' Balance: ' + balance);
}); });
} else if (type === 'output') { } else if (type === 'output') {
token = this.symbolToTokenContract(this.props.exchange.outputToken.value); token = this.symbolToTokenContract(this.props.exchange.outputToken.value);
token.methods.balanceOf(this.props.web3.currentMaskAddress).call((error, balance) => { token.methods.balanceOf(this.props.web3Store.currentMaskAddress).call((error, balance) => {
this.props.setOutputBalance(balance); this.props.setOutputBalance(balance);
// console.log(this.props.exchange.outputToken.value + ' Balance: ' + balance); // console.log(this.props.exchange.outputToken.value + ' Balance: ' + balance);
}); });
...@@ -371,12 +370,12 @@ class App extends Component { ...@@ -371,12 +370,12 @@ class App extends Component {
} }
getAllowance = () => { getAllowance = () => {
var type = this.props.web3.exchangeType; var type = this.props.web3Store.exchangeType;
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);
token.methods.allowance(this.props.web3.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); console.log(this.props.exchange.inputToken.value + ' allowance: ' + result);
if(result === '0'){ if(result === '0'){
this.props.setAllowanceApprovalState(false) this.props.setAllowanceApprovalState(false)
...@@ -387,13 +386,13 @@ class App extends Component { ...@@ -387,13 +386,13 @@ class App extends Component {
} }
approveAllowance = () => { approveAllowance = () => {
var type = this.props.web3.exchangeType; var type = this.props.web3Store.exchangeType;
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 = localweb3.utils.toWei('100000');
token.methods.approve(exchangeAddress, amount).send({from: this.props.web3.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'))
.on('receipt', (receipt) => { .on('receipt', (receipt) => {
console.log(receipt) console.log(receipt)
...@@ -406,7 +405,7 @@ class App extends Component { ...@@ -406,7 +405,7 @@ class App extends Component {
// TODO: stuff // TODO: stuff
tokenToExchangeFactoryLookup = (tokenAddress) => { tokenToExchangeFactoryLookup = (tokenAddress) => {
this.props.web3.factoryContract.methods.tokenToExchangeLookup(tokenAddress).call((error, exchangeAddress) => { this.props.web3Store.factoryContract.methods.tokenToExchangeLookup(tokenAddress).call((error, exchangeAddress) => {
console.log(exchangeAddress) console.log(exchangeAddress)
}); });
} }
...@@ -457,7 +456,7 @@ class App extends Component { ...@@ -457,7 +456,7 @@ class App extends Component {
setExchangeOutput = () => { setExchangeOutput = () => {
var inputValue = this.props.exchange.inputValue; var inputValue = this.props.exchange.inputValue;
if (this.props.web3.exchangeType === 'Invalid'){ if (this.props.web3Store.exchangeType === 'Invalid'){
this.props.setExchangeOutputValue(0); this.props.setExchangeOutputValue(0);
this.props.setInteractionState('error1'); this.props.setInteractionState('error1');
} else if(inputValue && inputValue !== 0 && inputValue !== '0'){ } else if(inputValue && inputValue !== 0 && inputValue !== '0'){
...@@ -470,24 +469,24 @@ class App extends Component { ...@@ -470,24 +469,24 @@ class App extends Component {
} }
getExchangeRate = (input) => { getExchangeRate = (input) => {
if (this.props.web3.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.web3.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.web3.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);
} }
} }
purchaseTokens = () => { purchaseTokens = () => {
if (this.props.web3.exchangeType === 'ETH to Token') { if (this.props.web3Store.exchangeType === 'ETH to Token') {
this.ethToTokenPurchase(); this.ethToTokenPurchase();
} else if (this.props.web3.exchangeType === 'Token to ETH') { } else if (this.props.web3Store.exchangeType === 'Token to ETH') {
this.tokenToEthPurchase(); this.tokenToEthPurchase();
} else if (this.props.web3.exchangeType=== 'Token to Token') { } else if (this.props.web3Store.exchangeType=== 'Token to Token') {
this.tokenToTokenPurchase(); this.tokenToTokenPurchase();
} }
} }
...@@ -554,16 +553,17 @@ class App extends Component { ...@@ -554,16 +553,17 @@ class App extends Component {
} }
// YOU ARE HERE NOW // YOU ARE HERE NOW
ethToTokenPurchase = () => { ethToTokenPurchase = async () => {
await this.getBlock();
var exchange = this.symbolToExchangeContract(this.props.exchange.outputToken.value); var exchange = this.symbolToExchangeContract(this.props.exchange.outputToken.value);
var minTokens = (this.props.exchange.outputValue/10**18).toString(); var minTokens = (this.props.exchange.outputValue/10**18).toString();
var minTokensInt = localweb3.utils.toWei(minTokens); var minTokensInt = localweb3.utils.toWei(minTokens);
var ethSold = this.props.exchange.inputValue; var ethSold = this.props.exchange.inputValue;
var weiSold = localweb3.utils.toWei(ethSold); var weiSold = localweb3.utils.toWei(ethSold);
var timeout = this.props.web3.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, weiSold, timeout);
exchange.methods.ethToTokenSwap(minTokensInt, timeout).send({from: this.props.web3.currentMaskAddress, value: weiSold}) exchange.methods.ethToTokenSwap(minTokensInt, timeout).send({from: this.props.web3Store.currentMaskAddress, value: weiSold})
.on('transactionHash', (result) => { .on('transactionHash', (result) => {
console.log('Transaction Hash created') console.log('Transaction Hash created')
let transactions = this.state.transactions let transactions = this.state.transactions
...@@ -590,15 +590,16 @@ class App extends Component { ...@@ -590,15 +590,16 @@ class App extends Component {
// tokenToEth and EthToToken purchase functions are very similar structurally // tokenToEth and EthToToken purchase functions are very similar structurally
// maybe we can make this more DRY in refactor // maybe we can make this more DRY in refactor
tokenToEthPurchase = () => { tokenToEthPurchase = async () => {
await this.getBlock();
var exchange = this.symbolToExchangeContract(this.props.exchange.inputToken.value); var exchange = this.symbolToExchangeContract(this.props.exchange.inputToken.value);
var minEth = (this.props.exchange.outputValue/10**18).toString(); var minEth = (this.props.exchange.outputValue/10**18).toString();
var minEthInt = localweb3.utils.toWei(minEth); var minEthInt = localweb3.utils.toWei(minEth);
var tokensSold = this.props.exchange.inputValue; var tokensSold = this.props.exchange.inputValue;
var tokensSoldInt = localweb3.utils.toWei(tokensSold); var tokensSoldInt = localweb3.utils.toWei(tokensSold);
var timeout = this.props.web3.blockTimestamp + 300; //current block time + 5mins var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins
exchange.methods.tokenToEthSwap(tokensSoldInt, minEthInt, timeout).send({from: this.props.web3.currentMaskAddress}) exchange.methods.tokenToEthSwap(tokensSoldInt, minEthInt, timeout).send({from: this.props.web3Store.currentMaskAddress})
.on('transactionHash', (result) => { .on('transactionHash', (result) => {
console.log('Transaction Hash created') console.log('Transaction Hash created')
let transactions = this.state.transactions let transactions = this.state.transactions
...@@ -614,16 +615,17 @@ class App extends Component { ...@@ -614,16 +615,17 @@ class App extends Component {
.on('error', console.error); .on('error', console.error);
} }
tokenToTokenPurchase = () => { tokenToTokenPurchase = async () => {
await this.getBlock();
var exchange = this.symbolToExchangeContract(this.props.exchange.inputToken.value); var exchange = this.symbolToExchangeContract(this.props.exchange.inputToken.value);
var tokenOutAddress = this.symbolToTokenAddress(this.props.exchange.outputToken.value); var tokenOutAddress = this.symbolToTokenAddress(this.props.exchange.outputToken.value);
var minTokens = (this.props.exchange.outputValue/10**18).toString(); var minTokens = (this.props.exchange.outputValue/10**18).toString();
var minTokensInt = localweb3.utils.toWei(minTokens); var minTokensInt = localweb3.utils.toWei(minTokens);
var tokensSold = this.props.exchange.inputValue; var tokensSold = this.props.exchange.inputValue;
var tokensSoldInt = localweb3.utils.toWei(tokensSold); var tokensSoldInt = localweb3.utils.toWei(tokensSold);
var timeout = this.props.web3.blockTimestamp + 300; //current block time + 5mins var timeout = this.props.web3Store.blockTimestamp + 300; //current block time + 5mins
exchange.methods.tokenToTokenSwap(tokenOutAddress, tokensSoldInt, minTokensInt, timeout).send({from: this.props.web3.currentMaskAddress}) exchange.methods.tokenToTokenSwap(tokenOutAddress, tokensSoldInt, minTokensInt, timeout).send({from: this.props.web3Store.currentMaskAddress})
.on('transactionHash', (result) => { .on('transactionHash', (result) => {
console.log('Transaction Hash created') console.log('Transaction Hash created')
let transactions = this.state.transactions let transactions = this.state.transactions
...@@ -664,32 +666,32 @@ class App extends Component { ...@@ -664,32 +666,32 @@ class App extends Component {
render() { render() {
return ( return (
<div className={this.props.web3.connected && !this.props.web3.metamaskLocked && this.props.web3.interaction !== 'disconnected' ? "App" : "App dim"}> <div className={this.props.web3Store.connected && !this.props.web3Store.metamaskLocked && this.props.web3Store.interaction !== 'disconnected' ? "App" : "App dim"}>
<Head /> <Head />
<section className="title"> <section className="title">
<div className="logo border pa2"> <div className="logo border pa2">
<span role="img" aria-label="Unicorn">🦄</span> <span role="img" aria-label="Unicorn">🦄</span>
</div> </div>
<NetworkStatus <NetworkStatus
network={this.props.web3.networkMessage} network={this.props.web3Store.networkMessage}
connected={this.props.web3.connected} connected={this.props.web3Store.connected}
metamask={this.props.metamask} metamask={this.props.metamask}
interaction={this.props.web3.interaction} interaction={this.props.web3Store.interaction}
address={this.props.web3.currentMaskAddress} address={this.props.web3Store.currentMaskAddress}
locked={this.props.web3.metamaskLocked} locked={this.props.web3Store.metamaskLocked}
balance={this.props.exchange.inputBalance}/> balance={this.props.exchange.inputBalance}/>
</section> </section>
<ConnectionHelper <ConnectionHelper
network={this.props.web3.networkMessage} network={this.props.web3Store.networkMessage}
connected={this.props.web3.connected} connected={this.props.web3Store.connected}
metamask={this.props.metamask} metamask={this.props.metamask}
address={this.props.web3.currentMaskAddress} address={this.props.web3Store.currentMaskAddress}
locked={this.props.web3.metamaskLocked} locked={this.props.web3Store.metamaskLocked}
approved={this.props.exchange.allowanceApproved} approved={this.props.exchange.allowanceApproved}
tokenAdded={this.state.tokenAdded} tokenAdded={this.state.tokenAdded}
approveAllowance={this.approveAllowance} approveAllowance={this.approveAllowance}
interaction={this.props.web3.interaction} interaction={this.props.web3Store.interaction}
exchangeType={this.props.web3.exchangeType} exchangeType={this.props.web3Store.exchangeType}
firstRun={this.state.firstRun} firstRun={this.state.firstRun}
uniAdded={this.state.uniAdded} uniAdded={this.state.uniAdded}
swapAdded={this.state.swapAdded} swapAdded={this.state.swapAdded}
...@@ -727,7 +729,7 @@ class App extends Component { ...@@ -727,7 +729,7 @@ class App extends Component {
</span> </span>
</section> </section>
{this.props.web3.interaction === 'input' ? {this.props.web3Store.interaction === 'input' ?
<a className="swap border pa2" role="button" onClick={() => {this.purchaseTokens()}}> <a className="swap border pa2" 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 + " " + 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 + " " + this.props.exchange.outputToken.value}</b>
...@@ -763,7 +765,7 @@ class App extends Component { ...@@ -763,7 +765,7 @@ class App extends Component {
</a> </a>
</section> </section>
{this.state.transactions.length > 0 && this.props.web3.interaction !== 'disconnected' ? {this.state.transactions.length > 0 && this.props.web3Store.interaction !== 'disconnected' ?
<section className="transaction border pa2"> <section className="transaction border pa2">
<p className="underline">Past Transactions:</p> <p className="underline">Past Transactions:</p>
<Transactions transactions={this.state.transactions}/> <Transactions transactions={this.state.transactions}/>
...@@ -775,7 +777,7 @@ class App extends Component { ...@@ -775,7 +777,7 @@ class App extends Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
web3: state.web3, web3Store: state.web3Store,
exchangeContracts: state.exchangeContracts, exchangeContracts: state.exchangeContracts,
tokenContracts: state.tokenContracts, tokenContracts: state.tokenContracts,
exchange: state.exchange exchange: state.exchange
...@@ -811,7 +813,8 @@ const mapDispatchToProps = (dispatch) => { ...@@ -811,7 +813,8 @@ const mapDispatchToProps = (dispatch) => {
setExchangeInputValue, setExchangeInputValue,
setExchangeOutputValue, setExchangeOutputValue,
setExchangeRate, setExchangeRate,
setExchangeFee setExchangeFee,
putWeb3InStore
}, dispatch) }, dispatch)
} }
......
import { import {
WEB3_CONNECTION_SUCCESSFUL, WEB3_CONNECTION_SUCCESSFUL,
WEB3_CONNECTION_UNSUCCESSFUL, WEB3_CONNECTION_UNSUCCESSFUL,
SET_CURRENT_MASK_ADDRESS, SET_CURRENT_MASK_ADDRESS,
...@@ -7,12 +7,13 @@ import { ...@@ -7,12 +7,13 @@ import {
SET_INTERACTION_STATE, SET_INTERACTION_STATE,
FACTORY_CONTRACT_READY, FACTORY_CONTRACT_READY,
SET_NETWORK_MESSAGE, SET_NETWORK_MESSAGE,
SET_BLOCK_TIMESTAMP, SET_BLOCK_TIMESTAMP,
SET_EXCHANGE_TYPE SET_EXCHANGE_TYPE,
PUT_WEB3_IN_STORE
} from '../constants'; } from '../constants';
// this actions folder is actually full of action creators // this actions folder is actually full of action creators
// your asynchronous calls are going to be in redux-thunk style action creators // your asynchronous calls are going to be in redux-thunk style action creators
export const web3ConnectionSuccessful = () => ({ export const web3ConnectionSuccessful = () => ({
type: WEB3_CONNECTION_SUCCESSFUL, type: WEB3_CONNECTION_SUCCESSFUL,
...@@ -54,7 +55,7 @@ export const setNetworkMessage = (networkMessage) => ({ ...@@ -54,7 +55,7 @@ export const setNetworkMessage = (networkMessage) => ({
networkMessage networkMessage
}); });
export const setBlockTimestamp = (timestamp) => ({ export const setBlockTimestamp = (timestamp) => ({
type: SET_BLOCK_TIMESTAMP, type: SET_BLOCK_TIMESTAMP,
timestamp timestamp
}); });
...@@ -63,3 +64,8 @@ export const setExchangeType = (exchangeType) => ({ ...@@ -63,3 +64,8 @@ export const setExchangeType = (exchangeType) => ({
type: SET_EXCHANGE_TYPE, type: SET_EXCHANGE_TYPE,
exchangeType exchangeType
}); });
export const putWeb3InStore = (globalWeb3) => ({
type: PUT_WEB3_IN_STORE,
globalWeb3
})
// 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 // 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 CHECK_WEB3_CONNECTION = 'CHECK_WEB3_CONNECTION'; export const CHECK_WEB3_CONNECTION = 'CHECK_WEB3_CONNECTION';
export const WEB3_CONNECTION_SUCCESSFUL = 'WEB3_CONNECTION_SUCCESSFUL'; export const WEB3_CONNECTION_SUCCESSFUL = 'WEB3_CONNECTION_SUCCESSFUL';
export const WEB3_CONNECTION_UNSUCCESSFUL = 'WEB3_CONNECTION_UNSUCCESSFUL'; export const WEB3_CONNECTION_UNSUCCESSFUL = 'WEB3_CONNECTION_UNSUCCESSFUL';
...@@ -26,7 +26,7 @@ export const SWT_EXCHANGE_CONTRACT_READY = 'SWT_EXCHANGE_CONTRACT_READY'; ...@@ -26,7 +26,7 @@ export const SWT_EXCHANGE_CONTRACT_READY = 'SWT_EXCHANGE_CONTRACT_READY';
export const UNI_TOKEN_CONTRACT_READY = 'UNI_TOKEN_CONTRACT_READY'; export const UNI_TOKEN_CONTRACT_READY = 'UNI_TOKEN_CONTRACT_READY';
export const SWT_TOKEN_CONTRACT_READY = 'SWT_TOKEN_CONTRACT_READY'; export const SWT_TOKEN_CONTRACT_READY = 'SWT_TOKEN_CONTRACT_READY';
// actions for the exchange, all in one place // actions for the exchange, all in one place
export const SET_INPUT_BALANCE = 'SET_INPUT_BALANCE'; export const SET_INPUT_BALANCE = 'SET_INPUT_BALANCE';
export const SET_OUTPUT_BALANCE = 'SET_OUTPUT_BALANCE'; export const SET_OUTPUT_BALANCE = 'SET_OUTPUT_BALANCE';
export const SET_INPUT_TOKEN = 'SET_INPUT_TOKEN'; export const SET_INPUT_TOKEN = 'SET_INPUT_TOKEN';
...@@ -41,4 +41,7 @@ export const SET_ALLOWANCE_APPROVAL_STATE = 'SET_ALLOWANCE_APPROVAL_STATE'; ...@@ -41,4 +41,7 @@ export const SET_ALLOWANCE_APPROVAL_STATE = 'SET_ALLOWANCE_APPROVAL_STATE';
export const SET_EXCHANGE_INPUT_VALUE = 'SET_EXCHANGE_INPUT_VALUE'; export const SET_EXCHANGE_INPUT_VALUE = 'SET_EXCHANGE_INPUT_VALUE';
export const SET_EXCHANGE_OUTPUT_VALUE = 'SET_EXCHANGE_OUTPUT_VALUE'; export const SET_EXCHANGE_OUTPUT_VALUE = 'SET_EXCHANGE_OUTPUT_VALUE';
export const SET_EXCHANGE_RATE = 'SET_EXCHANGE_RATE'; export const SET_EXCHANGE_RATE = 'SET_EXCHANGE_RATE';
export const SET_EXCHANGE_FEE = 'SET_EXCHANGE_FEE'; export const SET_EXCHANGE_FEE = 'SET_EXCHANGE_FEE';
\ No newline at end of file
// test setInteractionState
export const PUT_WEB3_IN_STORE = 'PUT_WEB3_IN_STORE';
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import web3 from './web3-reducer'; import web3Store from './web3-reducer';
import exchangeContracts from './exchangeContract-reducer'; import exchangeContracts from './exchangeContract-reducer';
import tokenContracts from './tokenContract-reducer'; import tokenContracts from './tokenContract-reducer';
import exchange from './exchange-reducer'; import exchange from './exchange-reducer';
export default combineReducers({ export default combineReducers({
web3, web3Store,
exchangeContracts, exchangeContracts,
tokenContracts, tokenContracts,
exchange exchange
}); });
\ No newline at end of file
// these will take in an action, have a default state set in the arguments and return a new state // these will take in an action, have a default state set in the arguments and return a new state
import { import {
WEB3_CONNECTION_SUCCESSFUL, WEB3_CONNECTION_SUCCESSFUL,
WEB3_CONNECTION_UNSUCCESSFUL, WEB3_CONNECTION_UNSUCCESSFUL,
SET_CURRENT_MASK_ADDRESS, SET_CURRENT_MASK_ADDRESS,
METAMASK_LOCKED, METAMASK_LOCKED,
METAMASK_UNLOCKED, METAMASK_UNLOCKED,
SET_INTERACTION_STATE, SET_INTERACTION_STATE,
FACTORY_CONTRACT_READY, FACTORY_CONTRACT_READY,
SET_NETWORK_MESSAGE, SET_NETWORK_MESSAGE,
SET_BLOCK_TIMESTAMP, SET_BLOCK_TIMESTAMP,
SET_EXCHANGE_TYPE SET_EXCHANGE_TYPE,
PUT_WEB3_IN_STORE
} from '../constants'; } from '../constants';
export default (state = {}, action) => { export default (state = {}, action) => {
const { connected, currentMaskAddress, metamaskLocked, interaction, factoryContract, networkMessage, timestamp, exchangeType } = action const { connected, currentMaskAddress, metamaskLocked, interaction, factoryContract, networkMessage, timestamp, exchangeType, globalWeb3 } = action
switch (action.type) { switch (action.type) {
case WEB3_CONNECTION_SUCCESSFUL: case WEB3_CONNECTION_SUCCESSFUL:
return Object.assign({}, state, { connected: connected }); return Object.assign({}, state, { connected: connected });
...@@ -35,6 +36,8 @@ export default (state = {}, action) => { ...@@ -35,6 +36,8 @@ export default (state = {}, action) => {
return Object.assign({}, state, { blockTimestamp: timestamp }); return Object.assign({}, state, { blockTimestamp: timestamp });
case SET_EXCHANGE_TYPE: case SET_EXCHANGE_TYPE:
return Object.assign({}, state, { exchangeType: exchangeType }); return Object.assign({}, state, { exchangeType: exchangeType });
case PUT_WEB3_IN_STORE:
return Object.assign({}, state, { globalWeb3: globalWeb3 });
default: return state; default: return state;
} }
} }
// what states do you need upon initialization? // what states do you need upon initialization?
// connected: are you connnected? default state = false // connected: are you connnected? default state = false
// props.metamask --> maybe we should keep this in global state too? // props.metamask --> maybe we should keep this in global state too?
// both of these are set to false in the default state // both of these are set to false in the default state
// fire dispatch functions to check for installation and connection in the default store // fire dispatch functions to check for installation and connection in the default store
// you are probably going to be storing stuff like invariants and all that jazz here // you are probably going to be storing stuff like invariants and all that jazz here
export default { export default {
// lets check if metamask is installed // lets check if metamask is installed
// also, lets assume that we're disconnected initially // also, lets assume that we're disconnected initially
// we're going to need to include a seperate nest for exchange actions // we're going to need to include a seperate nest for exchange actions
web3: { web3Store: {
connected: false, connected: false,
currentMaskAddress: '', currentMaskAddress: '',
metamaskLocked: true, metamaskLocked: true,
...@@ -55,4 +55,4 @@ export default { ...@@ -55,4 +55,4 @@ export default {
rate: 0, rate: 0,
fee: 0, fee: 0,
} }
} }
\ No newline at end of file
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